gpt4 book ai didi

java - 正在发送短信 : uid 10137 does not have android. 权限.SEND_SMS

转载 作者:行者123 更新时间:2023-12-01 09:22:47 25 4
gpt4 key购买 nike

在我的第一部使用 Lollipop 的手机中,程序运行良好,我可以发送和接收短信。但在我使用棉花糖的第二部手机中,我的应用程序被强制关闭。我不知道出了什么问题

这是强制关闭后的日志...

java.lang.IllegalStateException: Could not execute method for android:onClick at android.view.View$DeclaredOnClickListener.onClick(View.java:4461) at android.view.View.performClick(View.java:5207) at android.widget.CompoundButton.performClick(CompoundButton.java:122) at android.view.View$PerformClick.run(View.java:21177) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5458) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.view.View$DeclaredOnClickListener.onClick(View.java:4456) ... 10 more Caused by: java.lang.SecurityException: Sending SMS message: uid 10137 does not have android.permission.SEND_SMS. at android.os.Parcel.readException(Parcel.java:1620) at android.os.Parcel.readException(Parcel.java:1573) at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:842) at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:311) at android.telephony.SmsManager.sendTextMessage(SmsManager.java:294) at com.example.tamvan.komunikasiberlapis.MainActivity.clicksaklar1GSMMode(MainActivity.java:379) ... 12 more

这是我在 list 中的许可

<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

最佳答案

For Marshmallow, You need to add permissionCode:    ...    private static final int PERMISSION_SEND_SMS = 1;    ...    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED)    {        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, PERMISSION_SEND_SMS);    }    else     {        //do send or read sms    }    ...    @Override    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)        {            switch(requestCode)            {                case PERMISSION_SEND_SMS:                    if(grantResults != null && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)                    {                        //do send or read sms                    }                    break;            }        }

关于java - 正在发送短信 : uid 10137 does not have android. 权限.SEND_SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40053588/

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