1

在我的应用程序中,我在这个片段中有一个片段和一个 imageButton。当我在我的设备 (Android 8 - API 26) 中运行该应用程序并单击 imageButton 时,该应用程序崩溃并引发我以前没有看到的运行时错误。

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.mustafa.diyetisyenadmin, PID: 26366
              java.lang.SecurityException: Permission Denial: null asks to run as user 1 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS
                  at android.os.Parcel.readException(Parcel.java:1945)
                  at android.os.Parcel.readException(Parcel.java:1891)
                  at android.view.autofill.IAutoFillManager$Stub$Proxy.addClient(IAutoFillManager.java:326)
                  at android.view.autofill.AutofillManager.ensureServiceClientAddedIfNeededLocked(AutofillManager.java:903)
                  at android.view.autofill.AutofillManager.notifyViewExited(AutofillManager.java:487)
                  at android.view.View.notifyEnterOrExitForAutoFillIfNeeded(View.java:6983)
                  at android.view.View.dispatchAttachedToWindow(View.java:17594)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3332)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3339)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3339)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3339)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3339)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3339)
                  at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3339)
                  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1792)
                  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1515)
                  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7266)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:981)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:790)
                  at android.view.Choreographer.doFrame(Choreographer.java:721)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
                  at android.os.Handler.handleCallback(Handler.java:808)
                  at android.os.Handler.dispatchMessage(Handler.java:101)
                  at android.os.Looper.loop(Looper.java:166)
                  at android.app.ActivityThread.main(ActivityThread.java:7425)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

所以我在 Manifest.xml 中添加了所需的权限,并尝试了主题Android permission.INTERACT_ACROSS_USERS_FULL中的每个代码,但我得到了同样的错误。我已经解决了这个主题的自动填充问题,但是只有我点击了 ImageButton 才会发生片段错误。我应该怎么做才能解决这个问题?

4

2 回答 2

3

最后我找到了解决方案。出现问题是因为我的活动中有一个名为getUserId()的方法,它返回字符串 user_id 并将数据发送到片段。我更改了它的名称,现在一切正常。

于 2018-09-13T13:45:56.490 回答
0

您必须添加运行时权限。为此,请遵循

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!checkIfAlreadyhavePermission()) {
                    requestForSpecificPermission();
                }
}

模块 checkIfAlreadyhavePermission() 实现为:

private boolean checkIfAlreadyhavePermission() {
    int result = ContextCompat.checkSelfPermission(this, Manifest.permission.INTERACT_ACROSS_USERS_FULL);
    return result == PackageManager.PERMISSION_GRANTED;
}

模块 requestForSpecificPermission() 实现为:

private void requestForSpecificPermission() {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.INTERACT_ACROSS_USERS_FULL}, 101);
}

并覆盖 Activity :

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case 101:
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //DO WHATEVER YOU WANTED TO DO
            } else {
                //not granted
            }
            break;
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
于 2018-09-13T11:52:32.263 回答