英文:
Android 10: java.lang.SecurityException: getDeviceId: The user 10222 does not meet the requirements to access device identifiers
问题
我在Android 10上遇到了问题。当用户尝试授予“读取电话状态”权限时,我遇到了这个错误。我知道,谷歌现在限制了使用设备ID。另外,我已经阅读了所有关于这些更改的文档,我的问题是其他的。
首先,让我描述一下我如何使用设备ID以及为什么使用它。
在清单文件中:
```xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
在Java代码中:
public String getDeviceId(boolean encrypt) {
@SuppressLint("HardwareIds") String deviceId = android.provider.Settings.Secure.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
String encryptedDeviceId = "";
if (encrypt) {
try {
encryptedDeviceId = MCrypt.bytesToHex(MCrypt.$().encrypt(deviceId));
} catch (Exception e) {
e.printStackTrace();
}
}
return encryptedDeviceId;
}
现在,我知道我无法获取设备ID。以下是我的问题。
- 即使我从清单中删除了
uses_permission
行并删除了Java代码,我的应用程序仍然要求“电话状态”权限。为什么?
以下是我的整个清单。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="myoackagenamehere"
android:installLocation="preferExternal"
android:versionCode="151"
android:versionName="1.5.1">
<!-- 其他权限 -->
<!-- 这里有一些权限声明 -->
<!-- 这是问题所在的权限声明 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application>
<!-- 应用程序组件 -->
</application>
</manifest>
- 以前,我曾使用设备ID来恢复游戏进度,这意味着我在我的数据库中有设备ID,并且在用户重新安装游戏后使用它们。现在,如果前面的问题得到解决,我该如何避免丢失用户的进度?我的意思是,如果我为用户获取另一个ID,那么它将不再与数据库中的ID相同。
谢谢大家。
=====编辑=====
这是我合并的清单文件的一部分的屏幕截图,我无法导航或删除它。
======编辑 2======
我找到了问题所在,我的一些库的minSDKversion
小于4,这个权限会自动添加。
<details>
<summary>英文:</summary>
I have a problem with Android 10. I have I'm getting this error when the user tries to give the Read Phone state permission. I know , that now Google restrict using the device id. Also , I have read all documentation regarding these changes, and my questions are other.
Firstly, let me describe how and for what I used the device id.
In the manifest.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
And in the Java code.
public String getDeviceId(boolean encrypt) {
@SuppressLint("HardwareIds") String deviceId = android.provider.Settings.Secure.getString(activity.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
String encryptedDeviceId = "";
if (encrypt) {
try {
encryptedDeviceId = MCrypt.bytesToHex(MCrypt.$().encrypt(deviceId));
} catch (Exception e) {
e.printStackTrace();
}
}
return encryptedDeviceId;
}
Now , I know that I can't get the device id.
Here are my questions.
1.Event If I remove the uses_permission row in manifest and remove the java code, my app continues to want the Phone State permission. Why?
Here is my whole manifest.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="myoackagenamehere"
android:installLocation="preferExternal"
android:versionCode="151"
android:versionName="1.5.1">
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="org.onepf.openiab.permission.BILLING" />
<uses-permission android:name="com.sec.android.iap.permission.BILLING" />
<uses-permission android:name="com.nokia.payment.BILLING" />
<uses-permission android:name="com.slideme.sam.manager.inapp.permission.BILLING" />
<permission
android:name="mypackagename.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="mypackagename.permission.C2D_MESSAGE" />
<application
android:name="androidx.multidex.MultiDexApplication"
android:icon="@drawable/ic_launcher"
android:roundIcon="@drawable/ic_launcher_round"
android:label="@string/app_name"
android:allowBackup="true"
android:fullBackupContent="true"
tools:replace="android:name,android:fullBackupContent"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity
android:name="mypackagename.MainActivity"
android:configChanges="orientation|keyboardHidden|locale|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/apps_flyer_deep_link" />
</intent-filter>
</activity>
<activity
android:name="com.ironsource.sdk.controller.ControllerActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true" />
<activity
android:name="com.ironsource.sdk.controller.InterstitialActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent" />
<activity
android:name="com.ironsource.sdk.controller.OpenUrlActivity"
android:configChanges="orientation|screenSize"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent" />
<activity
android:name="com.vungle.warren.ui.VungleActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<activity
android:name="com.vungle.warren.ui.VungleFlexViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!-- Amazon Payment Stuff -->
<receiver
android:name="com.amazon.device.iap.ResponseReceiver"
tools:ignore="ExportedReceiver,InvalidPermission">
<intent-filter>
<action
android:name="com.amazon.inapp.purchasing.NOTIFY"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
</intent-filter>
</receiver>
<!--Google Push Notifications Stuff-->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<service
android:name="mypackagename.notification.service.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!--End of Google Push Notifications Stuff-->
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="@string/google_game_app_id" />
<meta-data
android:name="com.google.android.gms.appstate.APP_ID"
android:value="@string/google_game_app_id" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/ad_mob_app_id" />
<meta-data
android:name="applovin.sdk.key"
android:value="DpAUIPAz0TKP6geC6ifl0HJdoW6brFg23rXLFhJFAdeGJHTP_78_OScAzknpzSs0HNMW4fnEHQVahz_h48gTaI" />
<!-- Facebook Stuff-->
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
tools:replace="android:theme" />
<activity
android:name="com.facebook.ads.AudienceNetworkActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<!-- End of Facebook Stuff-->
<!-- Tapjoy Stuff-->
<activity
android:name="com.tapjoy.TJAdUnitActivity"
android:configChanges="orientation|keyboardHidden"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity
android:name="com.tapjoy.mraid.view.ActionHandler"
android:configChanges="orientation|keyboardHidden" />
<activity
android:name="com.tapjoy.mraid.view.Browser"
android:configChanges="orientation|keyboardHidden" />
<!-- For SDK 11.3+ -->
<activity
android:name="com.tapjoy.TJContentActivity"
android:configChanges="orientation|keyboardHidden"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!--End of Tapjoy Stuff-->
<!--Bugsnag Stuff-->
<meta-data
android:name="com.bugsnag.android.API_KEY"
android:value="8117a06b5900bdf6c3d33f8150131fbb" />
<!--End of Bugsnag Stuff-->
<!--Ad Stuff-->
<activity
android:name="com.adcolony.sdk.AdColonyInterstitialActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:hardwareAccelerated="true" />
<activity
android:name="com.applovin.adview.AppLovinInterstitialActivity"
android:configChanges="orientation|screenSize"/>
<service android:name=".expansion.ExpansionFilesDownloaderService" />
<receiver android:name=".expansion.DownloaderServiceBroadcastReceiver" />
<receiver android:name=".notification.service.NotificationPublisher" />
<!--End of Ad Stuff-->
<receiver
android:name="com.appsflyer.SingleInstallBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
2. I used the device Id for the restoring the game progress before, so that means , that I have device id's in my DB and use them , if user reinstall the game. Now , if the previous problem will be resolved, how can I avoid loosing my users progress? I mean if I will get another id for user , then it will no longer the same as in DB.
Thanks guys.
=====EDIT=====
Here is screenshot from my Merged Manifest file, and I can't either navigate or remove it.
[![Part of merged manifest, where the READ_PHONE_STATE is present][1]][1]
[1]: https://i.stack.imgur.com/c1nGd.png
======EDIT 2======
I found it, some of my libs have minSDKversion < 4, and this permission added automatically.
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论