
我想以编程方式获取用户广告ID.我使用了以下开发者网站的代码.但它不起作用
Info adInfo = null; try { adInfo = AdvertisingIDClIEnt.getAdvertisingIDInfo(getApplicationContext()); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingID). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } catch (IllegalStateException e) { // Todo auto-generated catch block e.printstacktrace(); } catch (GooglePlayServicesRepairableException e) { // Todo auto-generated catch block e.printstacktrace(); } final String ID = adInfo.getID(); final boolean isLAT = adInfo.islimitAdTrackingEnabled();如何以编程方式获取用户的广告ID?请帮我
解决方法:
我可能会迟到但这可能会帮助别人!
AsyncTask<VoID, VoID, String> task = new AsyncTask<VoID, VoID, String>() { @OverrIDe protected String doInBackground(VoID... params) { AdvertisingIDClIEnt.Info IDInfo = null; try { IDInfo = AdvertisingIDClIEnt.getAdvertisingIDInfo(getApplicationContext()); } catch (GooglePlayServicesNotAvailableException e) { e.printstacktrace(); } catch (GooglePlayServicesRepairableException e) { e.printstacktrace(); } catch (IOException e) { e.printstacktrace(); } String advertID = null; try{ advertID = IDInfo.getID(); }catch (NullPointerException e){ e.printstacktrace(); } return advertID; } @OverrIDe protected voID onPostExecute(String advertID) { Toast.makeText(getApplicationContext(), advertID, Toast.LENGTH_SHORT).show(); } }; task.execute(); 总结 以上是内存溢出为你收集整理的如何以编程方式在Android中获取广告ID全部内容,希望文章能够帮你解决如何以编程方式在Android中获取广告ID所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)