我的Android应用抛出此错误:
D/tag: https://www.example.net/stagingarea/Toronto/products/json_confirm/7731/1/3/
W/Adreno-EGL: <qeglDrvAPI_eglGetConfigAttrib:612>: EGL_BAD_ATTRIBUTE
W/System.err: java.lang.SecurityException: getDeviceId: Neither user 10120 nor current process has android.permission.READ_PHONE_STATE.
W/System.err: at android.os.Parcel.readException(Parcel.java:2005)
W/System.err: at android.os.Parcel.readException(Parcel.java:1951)
W/System.err: at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:5506)
W/System.err: at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:1100)
W/System.err: at com.paypal.android.c.k.a(Unknown Source:97)
W/System.err: at com.paypal.android.c.f.B(Unknown Source:4)
W/System.err: at com.paypal.android.c.f.d(Unknown Source:0)
W/System.err: at com.paypal.android.c.f$3.run(Unknown Source:675)
I/zygote: Do full code cache collection, code=502KB, data=399KB
I/zygote: After code cache collection, code=496KB, data=334KB
I/zygote: Do partial code cache collection, code=503KB, data=335KB
I/zygote: After code cache collection, code=503KB, data=335KB
I/zygote: Increasing code cache capacity to 2MB
I/Choreographer: Skipped 79 frames! The application may be doing too much work on its main thread.
E/ViewRootImpl: sendUserActionEvent() returned.
W/System.err: java.lang.SecurityException: getDeviceId: Neither user 10120 nor current process has android.permission.READ_PHONE_STATE.
W/System.err: at android.os.Parcel.readException(Parcel.java:2005)
W/System.err: at android.os.Parcel.readException(Parcel.java:1951)
W/System.err: at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:5506)
W/System.err: at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:1100)
W/System.err: at com.paypal.android.c.k.a(Unknown Source:97)
W/System.err: at com.paypal.android.c.f.B(Unknown Source:4)
W/System.err: at com.paypal.android.c.f.d(Unknown Source:0)
W/System.err: at com.paypal.android.c.f$3.run(Unknown Source:675)
我试图通过使用以下代码来解决它:
int permissionCheckREAD_PHONE_STATE = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);
if(permissionCheckREAD_PHONE_STATE != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_READ_PHONE_STATE);
}
但是,使用此新代码,我会收到此错误:
Cannot resolve symbol 'REQUEST_READ_PHONE_STATE'
我已经在使用import android.Manifest;
,我认为它已经包括android.permission.READ_PHONE_STATE
所需的内容。在我的AndroidManifest.xml
中,我包括了以下内容:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
关于我为什么遇到此Cannot resolve symbol 'REQUEST_READ_PHONE_STATE'
错误的任何想法?
更新1:我得到的确切错误是:
Error:(164, 96) error: cannot find symbol variable REQUEST_READ_PHONE_STATE
答案 0 :(得分:1)
REQUEST_READ_PHONE_STATE
是我需要定义的常量。我通过定义它并使用该常量添加所需的相应代码来对其进行修复:
public static final int REQUEST_READ_PHONE_STATE = 8;