代码之家  ›  专栏  ›  技术社区  ›  Ramesh Pokharel

如何为普通应用程序授予跨用户交互权限并处理这种情况?为什么需要这个许可?

  •  0
  • Ramesh Pokharel  · 技术社区  · 7 年前

    安卓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)
    

    Android permission.INTERACT_ACROSS_USERS_FULL 我把 许可 在舱单上作为

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

    但这个解决方案在我的情况下不起作用。坠机事件一次又一次地发生。我想这是因为多用户问题。我也搜索了一下,找到了这个链接 https://android.stackexchange.com/questions/67038/can-somebody-explain-how-multi-user-is-implemented-in-android-4-4/67040#67040

    这是我的清单文件

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

    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'
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Ramesh Pokharel    7 年前

    我终于得到了答案!

    由于安卓28有一些限制,所有开发人员都应该审查这些更改,并在适用于应用程序的情况下修改其应用程序以正确支持这些更改。

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

    下面是我对代码的一些修改

    1. Android 9有一些新功能,比如旋转。当你在清单中将它设置为纵向模式时,它可能会崩溃。最好从代码中请求旋转。所以我删除 清单文件

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

      行动 android.net.conn.CONNECTIVITY\u更改

      @Override
      protected void onResume() {
      super.onResume();
      registerReceiver(connectReceiver, newIntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
         }
      
    3. 并删除不必要的实现

    最后,,

    • 请先阅读android行为变化的完整文档
    • 进行必要的更改(定向、广播、背景服务等),因为它们受到限制

    非常感谢。

    更新