gpt4 book ai didi

android - Paypal 安全异常 : Requires READ_PHONE_STATE

转载 作者:搜寻专家 更新时间:2023-11-01 07:48:20 24 4
gpt4 key购买 nike

我在 Paypal-sandbox 中尝试结帐时遇到一些错误,错误仅发生在 Marshmallow 版本的设备中,低于该版本的其他版本工作正常。

错误信息

Fatal Exception: java.lang.SecurityException: getDeviceId: Neither user 10179 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4207)
at com.paypal.android.c.k.a(Unknown Source)
at com.paypal.android.c.f.B(Unknown Source)
at com.paypal.android.c.f.d(Unknown Source)
at com.paypal.android.c.f$3.run(Unknown Source)
Background sticky concurrent mark sweep GC freed 25935(1829KB) AllocSpace objects, 47(6MB) LOS objects, 8% free, 87MB/95MB, paused 7.704ms total 70.036ms
NeighborEvent{elapsedMs=2177754483, 192.168.0.1, [AC220B8E9BEB], RTM_NEWNEIGH, NUD_REACHABLE}
START u0 {cmp=com.luulla.mobile.android/com.paypal.android.MEP.PayPalActivity (has extras)} from uid 10179 on display 0
Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@724f030 attribute=null, token = android.os.BinderProxy@760242f

我可以知道有人遇到过这个问题吗?是Paypal-SDK引起的吗?非常感谢给定的建议和回答:)

最佳答案

如果您在 Android 版本的 Marshmallow 中运行应用程序,它需要用户的许可,有两种方法可以解决这个问题。要么在 list 文件中将 android:targetSdkVersion="22" 更改为低于 23(Marshmallow)。

或者写一个函数获取权限:

// ID to identify phone permissions request 
private static final int REQUEST_READ_PHONE_PERMISSIONS = 1;

// called this when "Checkout" button clicked
// function to get permission from user
public void getUserPermission()
{
// check whether "READ_PHONE_STATE" permission is granted or not
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)
{
// we do not have the permissions, we need to request permission from user
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_READ_PHONE_PERMISSIONS);
return;
}
}

当您的应用程序请求权限时,系统会向用户显示一个对话框,您可能需要处理权限请求响应。

// Write a callback method
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
{
switch (requestCode)
{
case REQUEST_READ_PHONE_PERMISSIONS:
// if request is cancelled, the result arrays are empty
if (grantResults.length == 0 || grantResults[0] == PackageManager.PERMISSION_DENIED)
{
// permissions denied. Show message to user with explanations
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("This app is designed for android version Marshmallow and above. Denying permission will cause unable to Checkout.");
alert.setPositiveButton("Ok", null);
alert.show();
}

// if we get permissions from user, proceed to checkout in Paypal
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
// continue with proceed to checkout
}
return;
}
}

关于android - Paypal 安全异常 : Requires READ_PHONE_STATE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39223124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com