AdvertisingID acquisition is not successful

Asked 1 years ago, Updated 1 years ago, 126 views

I wrote the source code according to the official document (http://www.androiddocs.com/google/play-services/id.html) to get the AdvertisingID, but it didn't work.
I added the following code.
app.gradle

 dependencies {
    compile'com.google.android.gms:play-services:8.3.0'
}

[Among AndroidManifest.xml tags]

<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>

MainActivity.java onCreate()

newAdIDTask(this).execute();

MainActivity.java Inner Class

private class AdIDTask extensions AsyncTask<Void,Void,String>{
    Context context_;
    public AdIDTask(Contextc){
        context_=c;
    }
    @ Override
    Protected String doInBackground (Void...params) {
        // Asynchronous processing
        try{
            AdvertisingIdClient.Info info=AdvertisingIdClient.getAdvertisingIdInfo(context_);
            return info.getId();
        } catch(Exceptione){
            return null;
        }catch(NoClassDefFoundError) {
            return null;
        }
    }

    @ Override
    protected void onPostExecute(String advertisingID) {
        if(advertisingID!=null){
            // If AdId is obtained
        }
        else{
            // If AdId could not be retrieved
        }
    }
}

When you run the method getAdvertisingIdInfo in the first line of the try statement, no returns were returned from the function and no exceptions were handled.
By the way, I am using GooglemapAPI in the same app, but it worked fine.
I would appreciate it if you could let me know if anyone knows the cause.

android google-play-service

2022-09-30 21:13

1 Answers

Please try to write the catch exactly as described in the example implementation to which the official documentation is located.
If you enter GooglePlayServicesNotAvailableException, you are running on a terminal (checked by AVD) where the service is unavailable.GooglePlayServicesRepairableException is unknown (Google PlayService is out of date?), you may have a problem with the terminal you are running.

By the way, I was able to confirm the acquisition of AdvertisingId on the actual machine (Nexus6) with the contents written by user14439.


2022-09-30 21:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.