简体   繁体   English

如何为普通应用授予INTERACT_ACROSS_USERS权限并处理这种情况? 为什么需要此权限?

[英]How to give permission INTERACT_ACROSS_USERS to normal apps and handle this situation ? why this permission required?

App works well in all version of android device at installation time (First time) but when I open next time on Android P ,it throws following exception 应用在安装时(第一次)在所有版本的android设备上都运行良好,但是当我下次在Android P上打开时,它会引发以下异常

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)

and i searched over internet ,I found this question Android permission.INTERACT_ACROSS_USERS_FULL . 我通过互联网搜索,发现这个问题是Android权限。INTERACT_ACROSS_USERS_FULL I put permission in manifest as 我在清单中放入许可

 <permission
    android:name="android.permission.INTERACT_ACROSS_USERS_FULL"
    android:protectionLevel="signature" />

But this solution doesn't work in my case . 但是这种解决方案对我来说不起作用。 The crash is happening again and again. 崩溃一次又一次地发生。 I think it's because of multiUser problem . 我认为是因为multiUser问题。 I also searched about that and found this link https://android.stackexchange.com/questions/67038/can-somebody-explain-how-multi-user-is-implemented-in-android-4-4/67040#67040 我也对此进行了搜索,并找到了此链接https://android.stackexchange.com/questions/67038/can-somebody-explain-how-multi-user-is-implemented-in-android-4-4/67040#67040

Is there any idea how to handle this problem ? 有什么办法解决这个问题吗?

here is my manifest file 这是我的清单文件

<?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>

and app level build.gradle file is here 和应用程序级别的build.gradle文件在这里

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'

android {

compileSdkVersion 28
defaultConfig {
    applicationId "************"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 22
    versionName "2.9.1"

testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        //  buildConfigField 'String', "APP_KEY", APP_KEY
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        resValue("bool", "FIREBASE_CRASH_ENABLED", "true")
    }

    debug {
        resValue("bool", "FIREBASE_CRASH_ENABLED", "false")
    }

}
externalNativeBuild {
    cmake {
        path 'src/CMakeLists.txt'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
/*
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
    transitive = true;
}
*/
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// compile 'com.android.support:exifinterface:27.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.orhanobut:hawk:2.0.1'
implementation 'com.jakewharton:butterknife:8.5.1'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.github.xiprox:ErrorView:v2.2.0.1'
implementation 'com.github.ragunathjawahar:android-saripaar:android-saripaar-2.0.3'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'com.jakewharton.timber:timber:4.5.1'
implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
implementation 'com.facebook.android:facebook-android-sdk:4.29.0'

implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

//  implementation 'com.twitter.sdk.android:twitter:3.0.0'
implementation 'com.splitwise:tokenautocomplete:2.0.8@aar'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
implementation 'com.android.support:multidex:1.0.3'

implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.google.firebase:firebase-config:16.1.0'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
///implementation 'org.jsoup:jsoup:1.10.1'
}

repositories {
mavenCentral()
}

configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
        if (!requested.name.startsWith("multidex")) {
            details.useVersion '26.0.1'
        }
    }
}
}
apply plugin: 'com.google.gms.google-services'

Finally I got answer ! 终于我得到了答案!

As android 28 has some restrictions , All developers should review these changes and modify their apps to support them properly, where applicable to the app. 由于android 28有一些限制,所有开发人员都应查看这些更改并修改其应用程序以在适用于该应用程序的情况下适当地支持它们。

https://developer.android.com/about/versions/pie/android-9.0-changes-all https://developer.android.com/about/versions/pie/android-9.0-changes-all

Here are my some changes in code 这是我的一些代码更改

  1. Android 9 has new features like rotation.It might crash when you set it to portrait mode constantly in manifest.It is better to request rotation from code. Android 9具有旋转等新功能。当您在清单中不断将其设置为纵向模式时,它可能会崩溃。最好从代码中请求旋转。 so I remove android:screenOrientation="portrait" from manifest.xml 所以我从manifest.xml中删除了android:screenOrientation =“ portrait”

  2. Another problem in my code is static registration of broadcast 我的代码中的另一个问题是广播的静态注册

     <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> 

    Action android.net.conn.CONNECTIVITY_CHANGE is deprecated in android P. so I register it dynamically in BaseActivity.java as 动作android.net.conn.CONNECTIVITY_CHANGE在android P中已弃用,因此我在BaseActivity.java中将其动态注册为

     @Override protected void onResume() { super.onResume(); registerReceiver(connectReceiver, newIntentFilter("android.net.conn.CONNECTIVITY_CHANGE")); } 
  3. I update all library in build.gradle and remove unnecessary implementations 我更新了build.gradle中的所有库,并删除了不必要的实现

As conclusion , 作为结论,

  • please , first read full documentation of android behaviour changes 请先阅读android行为更改的完整文档
  • make necessary changes (Orientation, Broadcast,Backgroud service etc) , as they are restricted 进行必要的更改(方向,广播,背景服务等),因为它们受到限制

Thank you ! 谢谢 !

UPDATE UPDATE

Hey Guys , Quickly search for method getUserId() , if you have this method in your application level class or Activity , just rename this method name . 大家好,快速搜索方法getUserId() ,如果您的应用程序级别的类或“活动”中包含此方法,则只需重命名此方法名称即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从用户 0 作为用户 -1 未经许可调用 INTERACT_ACROSS_USERS 或 INTERACT_ACROSS_USERS_FULL 不允许 - Call from user 0 as user -1 without permission INTERACT_ACROSS_USERS or INTERACT_ACROSS_USERS_FULL not allowed Android 权限。INTERACT_ACROSS_USERS 拒绝 - Android permission.INTERACT_ACROSS_USERS denial 安全例外:android.permission.INTERACT_ACROSS_USERS - Security Exception: android.permission.INTERACT_ACROSS_USERS 权限拒绝错误-SpeechRecognizer是连续服务吗? (android.permission.INTERACT_ACROSS_USERS_FULL) - Permission Denial Error - SpeechRecognizer as a continuous service? (android.permission.INTERACT_ACROSS_USERS_FULL) 有关将与其他应用程序交互的应用程序的权限 - Permission about a app that will interact with other apps 如何使该用户(“普通用户”)具有使用该过程的权限 - how can I make this user (Normal Users) permission to use the procedure 这些传感器权限是正常的或需要用户权限才能在应用程序中使用 - These Sensor permissions are normal or required user permission to use in app 在AndroidManifest中授予活动权限 - Give activity permission in AndroidManifest 为什么在缺少Java权限的情况下会有NPE? 以及如何找出哪个权限? - Why is there a NPE on a missing Java Permission? And how to find out which Permission? 以编程方式在AEM中授予组权限? - Programatically Give Group Permission in AEM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM