Skip to main content

Introduction to Google Advertising ID and fast integration to Apk and use


 
Advertising ID (Ad ID)
The ad id is a user-specific, unique, re-settable ad id, provided by the Google Play Service, which gives users better control for developers to provide a simple, standard system to continue using your application for The anonymous identifier for the purpose of the ad and either reset the tag or exit the benefit-based Google Play medical program.
The ad ID can be implemented in your application through a simple API.


Focus on development functions
Standard and Simple - Advertising logo is a standard part for analysis of advertising and simple systems .
Let the user control - the user can set their ID at any time or exit those interest-based ads from Google's app, and their preferences apply to the advertising agency's advertising ID.


Start
Get the Google Play Service SDK - download the google-play-service.jar from the downloaded Android SDK's Extras directory
Read the documentation and examples - document examples


Annotations
As a reminder , please note that from 2014-08-01 , the new application and application updates via Google activity must be used in any ad identifier for any advertising purposes instead of using ads on the ad ID device
How to check your application's compliance through the development console, or in the details of the relevant development policy changes, see the Google Game Developer Help Center Advertising ID Reference

Use the ad ID
The ad ID is a unique but user-reset string identifier that allows online advertising and other applications to anonymously identify a user. The user's advertising ID is provided through the API for the service provided to the application in the Google Play Service.
Users can set their advertising ID at any time from Google to set the application's right on the device's advertising section. From the same application, the user can also select targeted ad IDs based on the ad to set the appropriate ad tracking preferences. When a user selects a targeted ad , this ad tracking preference is provided to the application via the Google Play Service API .
App use ads must respect and respect user habits and preferences tracking, and note that any application that uses ad ids must respect Google's development content policy terms.

ID format
The Google Play Service API exposes and the user ID is the UUID string format.

Need
The Ads ID API supports Google Play Service 4.0+ devices
Support for specific devices is based on the version of Google Paly Service that the device installs

The user's ad ID and ad tracking are given priority
If your app wants to use an ad ID, your device must have Google Play Service installed
The API for the ad ID is available in the com.google.android.gms.ads.identifier package in the Google Play Service library. Get the user's ad ID and tracking preferences , call the method getadvertisingidinfo () , which returns an advertisingidclient information package . User current ad ID and tracking preferences .
Getadvertisingidinfo () method of blocking calls, so you can not say it in the main thread (UI thread). If the main thread , the method throws an exceptionstateexception exception .
Once you retrieve the advertisingidclient object , you can use its getid () and islimitadtrackingenabled () methods to access the ad ID and ad tracking preferences .

Method Description
public String getId() Retrieves the advertising ID.
public boolean isLimitAdTrackingEnabled() Retrieve whether the user has limit ad tracking enabled or not.
The ad ID API does not include a "reset" method. Only users can start resetting their own ad ID in the Google Play Service settings .

Example 1:
Get ID to be placed in the sub-thread, this approach is to put google-play-service.jar on the project under the lib, the whole jar about more than 3M, there is no need to integrate jar way to see example two.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    import com.google.android.gms.ads.identifier.AdvertisingIdClient;  
    import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;  
    import com.google.android.gms.common.GooglePlayServicesAvailabilityException;  
    import com.google.android.gms.common.GooglePlayServicesNotAvailableException;  
    import java.io.IOException;  
    ...  
      
    // Do not call this function from the main thread. Otherwise,   
    // an IllegalStateException will be thrown.  
    public void getIdThread() {  
      
      Info adInfo = null;  
      try {  
        adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);  
      
      } catch (IOException e) {  
        // Unrecoverable error connecting to Google Play services (e.g.,  
        // the old version of the service doesn't support getting AdvertisingId).  
       
      } catch (GooglePlayServicesAvailabilityException e) {  
        // Encountered a recoverable error connecting to Google Play services.   
      
      } catch (GooglePlayServicesNotAvailableException e) {  
        // Google Play services is not available entirely.  
      }  
      final String id = adInfo.getId();  
      final boolean isLAT = adInfo.isLimitAdTrackingEnabled();  
    }  

Example 2:
Do not need to integrate google-play-service.jar how to get it?
This means that the phone itself installed Google Play Service, where the use of binding services and boast process communication to obtain advertising ID.
Create a class of AdvertisingIdClient.java

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    public class AdvertisingIdClient {  
        public static final class AdInfo {  
            private final String advertisingId;  
            private final boolean limitAdTrackingEnabled;     
      
            AdInfo(String advertisingId, boolean limitAdTrackingEnabled) {  
                this.advertisingId = advertisingId;  
                this.limitAdTrackingEnabled = limitAdTrackingEnabled;  
            }  
      
            public String getId() {  
                return this.advertisingId;  
            }  
      
            public boolean isLimitAdTrackingEnabled() {  
                return this.limitAdTrackingEnabled;  
            }  
        }  
      
        public static AdInfo getAdvertisingIdInfo(Context context) throws Exception {  
            if (Looper.myLooper() == Looper.getMainLooper())  
                throw new IllegalStateException(  
                        "Cannot be called from the main thread");  
      
            try {  
                PackageManager pm = context.getPackageManager();  
                pm.getPackageInfo("com.android.vending", 0);  
            } catch (Exception e) {  
                throw e;  
            }  
      
            AdvertisingConnection connection = new AdvertisingConnection();  
            Intent intent = new Intent(  
                    "com.google.android.gms.ads.identifier.service.START");  
            intent.setPackage("com.google.android.gms");  
            if (context.bindService(intent, connection, Context.BIND_AUTO_CREATE)) {  
                try {  
                    AdvertisingInterface adInterface = new AdvertisingInterface(  
                            connection.getBinder());  
                    AdInfo adInfo = new AdInfo(adInterface.getId(),  
                            adInterface.isLimitAdTrackingEnabled(true));  
                    return adInfo;  
                } catch (Exception exception) {  
                    throw exception;  
                } finally {  
                    context.unbindService(connection);  
                }  
            }  
            throw new IOException("Google Play connection failed");  
        }  
      
        private static final class AdvertisingConnection implements  
                ServiceConnection {  
            boolean retrieved = false;  
            private final LinkedBlockingQueue<IBinder> queue = new LinkedBlockingQueue<IBinder>(  
                    1);  
      
            public void onServiceConnected(ComponentName name, IBinder service) {  
                try {  
                    this.queue.put(service);  
                } catch (InterruptedException localInterruptedException) {  
                }  
            }  
      
            public void onServiceDisconnected(ComponentName name) {  
            }  
      
            public IBinder getBinder() throws InterruptedException {  
                if (this.retrieved)  
                    throw new IllegalStateException();  
                this.retrieved = true;  
                return (IBinder) this.queue.take();  
            }  
        }  
      
        private static final class AdvertisingInterface implements IInterface {  
            private IBinder binder;  
      
            public AdvertisingInterface(IBinder pBinder) {  
                binder = pBinder;  
            }  
      
            public IBinder asBinder() {  
                return binder;  
            }  
      
            public String getId() throws RemoteException {  
                Parcel data = Parcel.obtain();  
                Parcel reply = Parcel.obtain();  
                String id;  
                try {  
                    data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");  
                    binder.transact(1, data, reply, 0);  
                    reply.readException();  
                    id = reply.readString();  
                } finally {  
                    reply.recycle();  
                    data.recycle();  
                }  
                return id;  
            }  
      
            public boolean isLimitAdTrackingEnabled(boolean paramBoolean)  
                    throws RemoteException {  
                Parcel data = Parcel.obtain();  
                Parcel reply = Parcel.obtain();  
                boolean limitAdTracking;  
                try {  
                    data.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");  
                    data.writeInt(paramBoolean ? 1 : 0);  
                    binder.transact(2, data, reply, 0);  
                    reply.readException();  
                    limitAdTracking = 0 != reply.readInt();  
                } finally {  
                    reply.recycle();  
                    data.recycle();  
                }  
                return limitAdTracking;  
            }  
        }  
    }  

USE:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    new Thread(new Runnable() {  
                public void run() {  
                    try {  
                        AdInfo adInfo = AdvertisingIdClient  
                                .getAdvertisingIdInfo(MainActivity.this);  
                        advertisingId = adInfo.getId();  
                        optOutEnabled = adInfo.isLimitAdTrackingEnabled();  
                        // Log.i("ABC", "advertisingId" + advertisingId);  
                        // Log.i("ABC", "optOutEnabled" + optOutEnabled);  
                    } catch (Exception e) {  
                        e.printStackTrace();  
                    }  
                    mHandler.sendEmptyMessage(HANDEL_ADID);  
                }  
            }).start();  

Comments

Popular posts from this blog

C++ Programming Tutorial - How to Install Code::Blocks in Ubuntu Linux - Learn Online

Installing Code::Blocks How do I Install Code::Blocks HOWTO: Installing Code::Blocks 10.05 How do you install Irrlicht on Code::Blocks? How do you install CodeBlock on ubuntu? codeblocks /bin/sh: g++: not found Installing codeblocks on ubuntu Installing Code::Blocks on Ubuntu 10.04?

Eyeglasses and Lenses Prescription WooCommerce Wordpress Best Plugin

WooCommerce EYE Glasses and Lenses Prescription Wordpress Plugin builds your Eye Glasses and Lenses Website quickly and easily. It is powered by WooCommerce and it is fully automated so you don’t need to do anything. It features popular Presciption, Select Lenses and their Addons. You can also easily increase your sale by adding your this plugin. prescription glasses is the best plugin for your wordpress website. its Tested in All major Themeforest Wordpress & WooCommerce theme, Features Suits on every type of Eyeglasses and Lenses prescription Have multiple lens options  Compatible with Wordpress & WooCommerce  Anti Reflective Option  Sphere Select Option  Cylinder Select Option  Axis Select Option  Add Select Option  Pupils Distance Select Option Download

Google Fight Against Low Quality and Spammy Content

  Google's ongoing battle against spammy and low-quality content in search results is an essential aspect of maintaining the platform's credibility and usefulness. Here are some of the new strategies and policies Google is implementing to combat these issues: Improved Quality Ranking : Google is enhancing its core ranking algorithms to prioritize high-quality and original content while reducing the visibility of unoriginal or spammy content in search results. New Spam Policies : Google is updating its spam policies to address emerging tactics used by spammers. This includes targeting practices such as expired websites repurposed as spam repositories, obituary spam, and other manipulative behaviors. Reducing Unoriginal Results : Google is refining its ranking systems to identify and minimize unhelpful, unoriginal content. This includes pages created specifically to match certain search queries and content that prioritizes search engine optimization over user experience. Scaled C