I've been working on an Android App that uses Google Drive API. It was originally build from the quickstart example here. The simplified sequence of API calls (with proper error handling not shown here) is:
GoogleAccountCredential cred = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);
cred.setSelectedAccountName("...");
Drive drvSvc = new Drive.Builder (AndroidHttp.newCompatibleTransport(), new GsonFactory(), cred).build();
FileList gooLst = drvSvc.files().list().setMaxResults(MAX_DOWN).setQ(_rqst).execute();
It has been working fine and I am just about to release my App. But suddenly, after Drive API update, I'm getting a warning
The method usingOAuth2(Context, String, String...) from the type
GoogleAccountCredential is deprecated
What's happening? Is there another way to obtain credentials? Is there an edited version of quickstart example available anywhere?
Thanks in advance for any clarification. sean
So, the simple answer to my own question is
replace:
GoogleAccountCredential crd =
GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE);
with
GoogleAccountCredential crd =
GoogleAccountCredential.usingOAuth2(this,
Arrays.asList(DriveScopes.DRIVE_FILE));
For completeness
I'm guessing you got to this exception by following the code example from Google Drive QuickStart. If so you'll might find the following things I had to modify interesting.
Google Play Services Lib (NB. See comment below!)
The documentation uses the old way of adding libraries to an Android project. This will fail when executed with the latest ADT. You will be able to compile and upload to the device/emulator but on execution you'll get a NoClassDefFoundError.
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/AccountPicker;
To fix this you should copy paste the google-play-services.jar file to the libs folder instead.
Missing meta-tag
Up to the next error. I then received an IllegalStateException with the instructions to add a meta-tag in the manifest holding the google-play-services version.
So within the application tag of the manifest add:
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version"/>
And in one of the resource files (res/values/a-file-here.xml) add the following:
<integer name="google_play_services_version">4030500</integer>
In my case the lib matched this version. If you enter the wrong version here you'll get an error showing the proper version to specify. So make sure to check output.
Permission Denied
Finally I got a prompt for oauth in the app just to find out the example app is still missing a permission. The error for reference:
java.io.FileNotFoundException: /storage/emulated/0/Pictures/IMG_20131211_110629.jpg: open failed: EACCES (Permission denied)
Next to the permissions listed within the example:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
Also add the WRITE_EXTERNAL_STORAGE permission in your manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
More resources
If you get an com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException exception with in the root cause somewhere a description Unknown you should check the settings in the Google API console. I received this error on a package mismatch.
Another links of interest are the oauth2 documentation and the google api playground.
Related
In my Flutter project, I have 2 flavors: free and full, and I use Codemagic for my CI/CD.
Only the free version comes with a Google ad banner. So I added the com.google.android.gms.permission.AD_ID permission in the manifest, then run my build on Codemagic, for the full version only.
Then I went to my Google Play console, and I got the error : This version includes the com.google.android.gms.permission.AD_ID permission, but your statement in the Play Console indicates that your app does not use the advertising ID., which is true (again, for the full version only).
So I add 2 new AndroidManifest.xml files in my project, one in free, one in full, and removed the permission from the main AndroidManifest.xml file.
Here is the content of the manifest in the android/app/src/free directory:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mistikee.mistikee.mistikee">
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
</manifest>
And here is the content of the manifest in the android/app/src/full directory:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mistikee.mistikee.mistikee">
</manifest>
Then I launched a new build on Codemagic, everything went fine, until I went to the Google Play console, and I still got the same error. I really don't understand why. It looks like there is a cache issue somewhere.
How can I fix that, without going to the console telling that I use the advertising ID (because, again, I don't use it in the full version)?
Thanks.
I am trying to release a Flutter based Android app to the Play Store.
When I review my release in Play Store console, I have the following warning:
You must complete the advertising ID declaration before you can release an app that targets Android 13 (API 33). We'll use this declaration to provide safeguards in Play Console to accommodate changes to advertising ID in Android 13.
Apps targeting Android 13 or above and using advertising ID must include the com.google.android.gms.permission.AD_ID permission in the manifest.
I have followed the advice and added the following to my android/app/src/main/AndroidManifest.xml:
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
</manifest>
When I 'flutter clean', create and upload a new bundle, I'm still getting the same warning. Does anyone know how to resolve this warning?
Note: I have incorporated Google Ads in my app using the google_mobile_ads plugin.
Luke
There are 2 steps that you have to follow to solve this problem.
add com.google.android.gms.permission.AD_ID permission in the manifest file.
Go to your Google Play Console select the app which you are trying to upload then on the left side go to Policy and programs -> App content in there fill the Advertising ID form.
So you have already done step 1. Now complete step 2 and upload your app again.
Go to your Google Play Console select the app which you are trying to upload then on the left side go to Policy -> App content in there fill the Advertising ID form.
Only if you answered with Yes in the form shown above, add the line shown below to your AndroidManifest.xml:
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
I have research a lot on here and google but could not find the solution. I have uploaded an app on play store and it was working fine then i developed an other application by making changes in previous app project and changed project id in build.gradle script and version code. Now if any of two application is installed in phone 2nd one always gives error code -505. Please help me, my both apps are live on playstore.
I have found my mistake and i am sharing it here as a answer if anyone else face this problem. I am using google maps in both applications and I use static package name in manifest for MAPS.RECIEVE permission and I complete forgot to change that package name. I was using following code
<permission
android:name="com.myapp.packagename.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
Correct one is
<permission
android:name="${applicationId}.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
I've followed Amazon's Getting Started guide, and (after Exporting the Amazon library, increasing the heap size available to Eclipse and adding the necessary permissions to the application manifest), I now have the sample S3_UploaderActivity Android app running.
However, when I try to upload an image I get this error message on my device's screen:
Unable to execute HTTP request: Unable to resolve host
"my-unique-namexxxxxxxxxxxxxxxpicture-bucket.s3-us-west-2.amazonaws.com": No address associated with hostname
Although this wasn't mentioned in the Getting Started guide, I presumably need to change the "my-unique-name" and "picture-bucket" strings (the latter which is stored in a constant called PICTURE_BUCKET).
But what do I change these values to??
Did you add the internet permission to your manifest file ?
<uses-permission android:name="android.permission.INTERNET" />
I tried to upgrade my implementation of AdMob. Using the GoogleAdMobSDK, I would like to turn into the google-play-services-lib.
The ad appears. So it seems ok, but I still got this error at the method call loadAd() in log
Requesting resource 0x7f0c000d failed because it is complex
GooglePlayServicesUtil: The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Here's my checklist:
I import the library project in my workspace, copying the source.
I reference the library into my project
I add the meta-data in the Manifest
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
My code
this.request = new AdRequest.Builder().addTestDevice(id).build();
this.adView = new AdView(context);
this.adView.setAdUnitId(MY_AD_UNIT_ID);
this.adView.setAdSize(AdSize.SMART_BANNER);
...
this.adView.loadAd(request);
The target version for my app in 9 (2.3). I test on Nexus 5 with KitKat version.
I also tried to put the google-play-services-lib jar in the properties, but no result.
I want to be sure that this error could be handle before submit my app.
This is a benign error with the current version of Google Play Services.
Don't worry about it. Submit your app. Get some sleep.