应用在安装时(第一次)在所有版本的android设备上都能正常运行,但是当我下次在 Android P 上打开时,它会引发以下异常
num = subparsers.add_parser("num", usage="test num [-h] [-n N] (-x X | (-y Y -z Z))")
,我在互联网上进行搜索,发现了这个问题Android permission.INTERACT_ACROSS_USERS_FULL。 我在清单中将权限设置为
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.merojob.merojobapp/com.merojob.merojobapp.SplashScreenActivity}: java.lang.SecurityException: Call from user 0 as user 361911 without permission INTERACT_ACROSS_USERS or INTERACT_ACROSS_USERS_FULL not allowed.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
但是对于我来说,这种解决方案不起作用。崩溃一次又一次地发生。我认为是因为multiUser问题。我也对此进行了搜索,并找到了此链接 https://android.stackexchange.com/questions/67038/can-somebody-explain-how-multi-user-is-implemented-in-android-4-4/67040#67040
有什么办法解决这个问题吗?
这是我的清单文件
<permission
android:name="android.permission.INTERACT_ACROSS_USERS_FULL"
android:protectionLevel="signature" />
和应用程序级别的build.gradle文件在此处
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="***************">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<permission
android:name="android.permission.INTERACT_ACROSS_USERS_FULL"
android:protectionLevel="signature" />
<application
android:name=".MeroJobApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppThemeJobSeeker">
<meta-data
android:name="io.fabric.ApiKey"
android:value="*****************************" />
<activity
android:name=".SplashScreenActivity"
android:allowTaskReparenting="true"
android:alwaysRetainTaskState="true"
android:configChanges="orientation"
android:launchMode="singleTask"
android:showForAllUsers="true"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
<activity
android:launchMode="singleTask"
android:showForAllUsers="true"
android:name=".activity.MainActivity"
android:screenOrientation="portrait" />
<activity
android:launchMode="singleTask"
android:showForAllUsers="true"
android:name=".activity.LoginActivity"
android:screenOrientation="portrait" />
<activity
android:launchMode="singleTask"
android:showForAllUsers="true"
android:name=".activity.TutorialActivity"
android:screenOrientation="portrait" />
<receiver
android:name=".utils.ConnectivityReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<service android:name=".Services.CustomFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".Services.CustomFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />
</application>
答案 0 :(得分:0)
最后我得到了答案!
由于android 28有一些限制,所有开发人员都应查看这些更改并修改其应用程序以在适用于该应用程序的情况下适当地支持它们。
https://developer.android.com/about/versions/pie/android-9.0-changes-all
这是我的一些代码更改
Android 9具有旋转等新功能。当您在清单中不断将其设置为纵向模式时,它可能会崩溃。最好从代码中请求旋转。所以我删除了 android:screenOrientation =“ portrait” 来自 manifest.xml
我的代码中的另一个问题是广播的静态注册
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
动作 android.net.conn.CONNECTIVITY_CHANGE 在android P中已弃用,因此我在BaseActivity.java中将其动态注册为
@Override
protected void onResume() {
super.onResume();
registerReceiver(connectReceiver, newIntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
}
我更新了 build.gradle 中的所有库,并删除了不必要的实现
结论,
谢谢!
更新
伙计们,快速搜索方法 getUserId(),如果您的应用程序级别的类或“活动”中有此方法,则只需重命名此方法名称即可。