How to set api key for Google maps v2 - java

I am trying to create a map application. I am setting up the AndroidManifest.xml file for the permissions and API Key.
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dibya.map"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.dibya.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<!-- Permissions needed -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.dibya.map.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="KEY" />
</application>
</manifest>
I am getting an error message:
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0.
You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
I have entered the correct API key. Please tell me where am I making mistake.

add the below tag inside your application tag and it works.
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />

Add this in your manifest
<meta-data android:name="com.google.android.gms.version" android:value="4030500"/>

you will need add library Google Play Service . After that there is missing one uses-permission, i.e., <uses-permission android:name="com.dibya.map.permission.MAPS_RECEIVE" />
Please rewrite the code in this manner:
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<permission
android:name="com.dibya.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.dibya.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
.........
I think your problem will be solved.
Thanks!!!

Add the following metadata in application tag. You have to use updated googlePlayService library(13th Rev).
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />

Write Android Manifest like this way. I am sure your map will works fine if you don't make any other mistakes.
<permission
android:name="com.example.mmmm.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission>
<uses-permission android:name="com.example.mmmm.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your API Key"/>

Related

Eclipse says that I don't have <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />

Recently I updated my google_play_service_lib, but I have the next error in eclipse very nonsense, because I have such line in my manifest...
java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 6587000 but found 7895000. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
This only happen when the version of my google_play services_lib is bigger than google_play_services_r26. I need to update to this version, but when I import it to my project I have that error. This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..."
android:versionCode="9"
android:versionName="2.3" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="99" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:icon="#drawable/ic2"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light.DarkActionBar" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
.......
</application>
</manifest>
Anyone can tell me what I am doing wrong?

ant build error: package r does not exist

I got this error message when running from command line:
[javac]E:\...\MainActivity.java:19: Error: Package R does not exist
[javac] setContentView(R.layout.activity_main);
I have added import com.***.R; to file MainActivity.java.
Here is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.***">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:persistent="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".JmfService"
android:enabled="true"/>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DELETE_PACKAGES"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.intent.action.MEDIA_SCANNER_SCAN_DIR" />
</manifest>
I've tried ant clean, rebuild project and so on.
When clicking on the menu button to build the project, i got BUILD SUCCESSFUL.

Launch an application from another application, resumes always to root activity

I created a application to launch other with this code:
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage("com.example");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (i == null)
throw new PackageManager.NameNotFoundException();
startActivity(i);
} catch (PackageManager.NameNotFoundException e)
{
This code works correctly (can start application) for Facebook, Google Maps, another application created by me (com.example).
My test aplication (com.example) can resume, but always to root activity.
This application has two activities. First activity (Main Launcher), and a second activity. When I navigate to second activity (Main -> second), and execute application Launcher (above code), my application test run to foreground, but always show the first activity and destroy the second activity.
The test application (com.example) manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Main"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Screen2"
android:label="#string/screen2Title"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout"
android:windowSoftInputMode="adjustResize">
</activity>
</application>
</manifest>
Facebook and Google Maps resume the last visible activity (not launcher activity).
Properties are well defined in above manifest?
The behavior of Facebook and Google Maps, is standard, or results of the code of activities, etc?
Thanks in advance for your help.
Problem solved, with the solution below.
Now I can start my application, if it is closed or resume (resume in any activity).
The code that starts the application is (Launcher):
Intent i;
PackageManager manager = getPackageManager();
try
{
i.addFlags(0);
i.setPackage(null);
if (i == null)
throw new PackageManager.NameNotFoundException();
startActivity(i);
}
catch (PackageManager.NameNotFoundException e)
{
}
My application that starts, has the following manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".Main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Screen2"
android:label="#string/screen2Title"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask" >
</activity>
<activity android:name=".Screen3"
android:label="#string/screen3Title"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask" >
</activity>
</application>
</manifest>
Now the application is resumed to any activity, without ever navigate to the root activity.

Google play services rev. 16 error

I am new to android. I want add a map to my application. I have the latest revision 16 of play services installed. When I run my application, I get an error a missing meta tag which i have added as below. I testing on android 2.3.6. See Manifets file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mylocation"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.mylocation.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="A***************************IE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>

Unable to load maps into an android(samsung) phone

Unable to load maps into an android(samsung) phone. It just displays grid cells without loading the maps. This is my first time developing an android application. Could you please help in what else needs to be done apart from the below steps.
Downloaded the android version(eclipse).
Installed all the required API's for google maps.
Set the manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.csc714.app"
android:versionCode="1"
android:versionName="1.0.0" >
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
If you are using google map v2 then first create(check) api key.
You have to add google-play-services library.
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="17" />
<permission
android:name="com.example.package.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.package.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<uses-library
android:name="com.google.android.maps"/>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
References:
link link2
Please refer link and change xml,java and manifext.xml
If you find any trouble then let me know.
In AndroidManifest.xml, add the following element as a child of the element, by inserting it just before the closing tag :
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key"/>
You are missing
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
Few permissions are repeated remove them
Go through the steps in the link. I doubt you have followed the steps from the below link.
https://developers.google.com/maps/documentation/android/start.
You can also follow the tutorial in the link below
http://www.youtube.com/watch?v=awX5T-EwLPc
Edit :
You also require
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You can also get rid of
<permission
android:name="com.example.package.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
For more information read
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2

Categories

Resources