Multiple Google api keys in manifest file (Android) - java

I am trying to add two api keys i.e Google places api key and google maps api key.
But I am not able to add both at same time to manifest file.How can I achieve the same.Any help would be appreciated.
Thanks in advance.
The error I am getting is
Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.geo.API_KEY in the element of AndroidManifest.xml
I am including api keys like this
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxx" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxx"/>

Use following meta-data in your manifest. there is no need to create another api key for places api if you already have api key for google map.
If you are using both Maps & Places Api in your application then you only need to specify geo api key.and just enable Places Api.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="api_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />

Rather than adding two different API keys, for the same project enable both keys and copy down the same key as follows for single project which you want currently
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaS******************WDaKCEHP" />
<!-- Google Places API Key -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaS******************WDaKCEHP" />

Whats your Error log saying
Caused by: java.lang.RuntimeException: The API key can only be
specified once. It is recommended that you use the meta-data tag with
the name: com.google.android.geo.API_KEY in the element of
AndroidManifest.xml
Just remove
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="xxxx"/>
Make sure you have below permissions . Enough for Map Showing .
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/common_google_api_key" />
<uses-library
android:name="com.google.android.maps"
android:required="false" />
Read
Getting error "java.lang.RuntimeException: Unable to start activity" in my app

Related

How to set file provider for images stored in app data folder

I have been working on CameraX API and storing captured image on Internal storage App data folder with path say storage/emulated/0/Android/data/packageName/Files/IMG_25052021_171806.jpg
Now i want to get content URI for this saved image. For this i have been using provider in Manifest.
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.abc.xyz.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepath" />
</provider>
with File path as
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="/" />
When i am calling FileProvider.getUriForFile(ImageCrop.this,"com.abc.xyz.fileprovider", pictureFile); it returning me Illegal Argument Exception
Please suggest !!!
You seem to be using getExternalFilesDir() for the filesystem location. If so, use <external-files-path>, not <files-path>, in your metadata XML resource. See the documentation for more.

Strange behavior related to FusedLocationApi.requestLocationUpdates()

I'm writing a Android app and there's a strange behavior related to FusedLocationApi.requestLocationUpdates() that I've searched on SO and none of the other related questions solved my problem.
Apparently the requestLocationUpdates do not trigger the onLocationChanged() method all the times; I'm saying this because I'm cleaning my app's data on emulator for each run and sometimes the onLocationChanged() is triggered, sometimes not (most of under some conditions like run the app for the second time w/o cleaning the app's data or after making a user data's wipe i.e)
Below you can find my code (links from pastebin, I don't want to create any visual overload here)
Main Activity: http://pastebin.com/XiRrcR11
MapHandler: http://pastebin.com/HELnhaxy
Another problem is, oddly enough, if I use a anonymous inner class in the MapHandler in the method displayLocation(), the app works, but if I use a external class who extends LocationListener the app do not behave correctly
I know the expected question levels in SO are high but I'm starting my studies about Android development and this issue is taking my sleep away
Btw here is my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trackit.app.track_it_v002">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Can you guys give me a hand here?
EDIT: after some debugging I've seen the requestLocationUpdates is not returning a non null object and not triggering onLocationChanged(), anyone have a idea why? =S
I encountered this issue. The mGoogleApiClient object, which needs to be connected at the time of requestLocationUpdates. This was resolved by requestingLocationUpdates from onConnected callback.
/*
* Called first time google client is connected
*/
#Override
public void onConnected(#Nullable Bundle bundle) {
Log.v(LOG_TAG,"DetectDrivingService - onConnected");
// Create
try {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
}
catch(SecurityException se){
}
}

AndroidManifest.xml not working properly

we are sooooo close to finishing our game, it is ready to be published through google play but we are having problems making any of the game services work.
we have a simple achievement button that should call the achievement UI, same goes for logging in. but we do not get any prompts when we are running it on our android device.
we have
PlayGamesPlatform.Activate();
in our start function
Social.localUser.Authenticate((bool success) => {
// handle success or failure
});
connected to a log in button
and
Social.ShowAchievementsUI();
on our show achievement button.
our email is connected as a tester on google play and the game service API's are all enabled
my real question is about the AndroidManifest that the game play service for unity created.
this is it:
<?xml version="1.0" encoding="utf-8"?>
<!-- This file was automatically generated by the Google Play Games plugin for Unity
Do not edit. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.example.games.mainlibproj"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<application>
<!-- Required for Nearby Connections API -->
<meta-data android:name="com.google.android.gms.nearby.connection.SERVICE_ID"
android:value="" />
<!-- the space in these forces it to be interpreted as a string vs. int -->
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="\ 606268116612" />
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="\ 606268116612" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.games.bridge.NativeBridgeActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
</application>
</manifest>
i have read online that the package name should be our package name but shouldnt this be created when we run android set up using our ID number for our game? should i physically change this in code in the manifest even though it says i shouldnt edit it?
also OUR.ID i have replaced just for this question and in the real manifest has our actual ID No
Many Thanks In Advance
I always have the same package name (at application level) than my hierarchy in the project. In my opinion is a good practice to set the root at the folder where you have all your activities.
On the other hand, you can sign your app for market with the ID you want setting it in your gradle file.
You can see a good reference here.
I hope this would help you.

Adding advertising in the application?

I am using this code:
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
But is in error :
Description Resource Path Location Type error: No resource identifier
found for attribute 'loadAdOnCreate' in package 'com.teste.teste1'
activity_teste.xml /Teste/res/layout line 120 Android AAPT Problem
You need to add your unique ad unit id. To get this you need to create a new banner ad in your AdMob profile after you set up a new application for monetization.
EDIT:
Remove "loadAdOnCreate" attribute on the 120th line since it can not be used as XML attribute.
EDIT 2:
Possible new solutions:
Add xmlns:ads="http://schemas.android.com/apk/res-auto to your parentl ayout in XML.
Add Google Play services to your dependencies:
compile 'com.google.android.gms:play-services:6.+'
Add a meta tag in your application's manifest:
<!--This meta-data tag is required to use Google Play Services.-->
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Add config changes and theme for adactivity in your application's manifest:
<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />

how to solve IllegalStateException

I am developping an app and i wanna display a google map v2 on activity but it doesn't show
this is a snippet form logcat
11-30 19:14:56.681: E/AndroidRuntime(6062):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.cultural/com.example.cultural.MainActivity}:
android.view.InflateException: Binary XML file line #20: Error
inflating class fragment
11-30 19:14:56.681: E/AndroidRuntime(6062): Caused by:
java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 6171000
but found 0. You must have the following declaration within the
element:
Make sure you add this to your manifest application tag :
<application
... >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR KEY HERE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
and see comment below or check this :
Android Google Maps API "Error inflating class fragment"
Make sure you have the following inside the <application> element in your AndroidManifest.xml.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>

Categories