Android:为请求码值选择什么?
2022-09-01 00:54:24
像这样的方法要求我向它们传递一个请求码,我以后可以在回调中测试(在本例中)。是否有一些最佳实践值我应该在请求代码中传递?我注意到,如果我只是输入一个随机,我有时会收到这样的错误:ActivityCompat.requestPermissions
onRequestPermissionsResult
int
java.lang.IllegalArgumentException: Can only use lower 8 bits for requestCode
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: FATAL EXCEPTION: main
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: Process: my package, PID: 8315
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage.myactivity}: java.lang.IllegalArgumentException: Can only use lower 8 bits for requestCode
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: Caused by: java.lang.IllegalArgumentException: Can only use lower 8 bits for requestCode
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.support.v4.app.FragmentActivity.validateRequestPermissionsRequestCode(FragmentActivity.java:799)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.support.v4.app.ActivityCompatApi23.requestPermissions(ActivityCompat23.java:29)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.support.v4.app.ActivityCompat.requestPermissions(ActivityCompat.java:316)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at mypackage.myactivity.checkReadPhoneState(PermissionsGatewayActivity.java:48)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at mypackage.myactivity.onCreate(PermissionsGatewayActivity.java:36)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-25 16:47:43.652 8315-8315/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)