在我的应用程序中,我有一个片段和一个在片段内部的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时才发生。我该怎么办才能解决这个问题?
答案 0 :(得分:1)
最后我找到了解决方案。发生问题是因为我在活动中有一个名为 getUserId()的方法,该方法返回String user_id并将数据发送到片段。我更改了它的名称,现在一切正常。
答案 1 :(得分: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;
}
module requestForSpecificPermission()实现为:
private void requestForSpecificPermission() {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.INTERACT_ACROSS_USERS_FULL}, 101);
}
和覆盖活动:
@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);
}
}