AndroidAndroidP 上的 AdvertisingId 异常
AndroidAdvertisingId exception on Android P
在不更改 Android Oreo 和 Android P 之间的任何代码的情况下,当我尝试以下列方式获取广告 ID 时:
Thread backgroundWorker = new Thread(new Runnable(
{
@Override
public void run()
{
try
{
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(appContext);
if (adInfo != null){
Log.d(“some tag”,adInfo.getId());
}
}
catch (IllegalStateException e){}
catch (GooglePlayServicesRepairableException e){}
catch (IOException e){}
catch (GooglePlayServicesNotAvailableException e){}
catch (SecurityException e){}
});
我在 Android P 上收到以下 SecurityException,我的清单或其他地方没有声明任何 SharedPrefs:
05-22 15:01:14.590 18536-22301/com.someapp.mobilesdktest
W/AdvertisingIdClient: Error while reading from SharedPreferences
java.lang.SecurityException: MODE_WORLD_READABLE no longer supported
at android.app.ContextImpl.checkMode(ContextImpl.java:2453)
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:389)
at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:376)
at
com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown
Source:12)
at com.someapp.SomeFile.run(SomeFile.java:3607)
at java.lang.Thread.run(Thread.java:764)
当我尝试通过 SharedPreferences prefs.getAll() 打印任何 SharedPrefs 时,它是空的...我如何将其更改为 MODE_PRIVATE,因为 getAdvertisingIdInfo() 是游戏中的一种方法-services-basement 包并尝试调用 getSharedPreferences("google_ads_flags", 1);
所以我升级到 com.google.android.gms:play-services-ads:12.0.1 并且异常消失了。
在不更改 Android Oreo 和 Android P 之间的任何代码的情况下,当我尝试以下列方式获取广告 ID 时:
Thread backgroundWorker = new Thread(new Runnable(
{
@Override
public void run()
{
try
{
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(appContext);
if (adInfo != null){
Log.d(“some tag”,adInfo.getId());
}
}
catch (IllegalStateException e){}
catch (GooglePlayServicesRepairableException e){}
catch (IOException e){}
catch (GooglePlayServicesNotAvailableException e){}
catch (SecurityException e){}
});
我在 Android P 上收到以下 SecurityException,我的清单或其他地方没有声明任何 SharedPrefs:
05-22 15:01:14.590 18536-22301/com.someapp.mobilesdktest W/AdvertisingIdClient: Error while reading from SharedPreferences java.lang.SecurityException: MODE_WORLD_READABLE no longer supported at android.app.ContextImpl.checkMode(ContextImpl.java:2453) at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:389) at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:376) at com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown Source:12) at com.someapp.SomeFile.run(SomeFile.java:3607) at java.lang.Thread.run(Thread.java:764)
当我尝试通过 SharedPreferences prefs.getAll() 打印任何 SharedPrefs 时,它是空的...我如何将其更改为 MODE_PRIVATE,因为 getAdvertisingIdInfo() 是游戏中的一种方法-services-basement 包并尝试调用 getSharedPreferences("google_ads_flags", 1);
所以我升级到 com.google.android.gms:play-services-ads:12.0.1 并且异常消失了。