java.lang.SecurityException:正在发送短信:uid 10282没有android.permission.SEND

编程入门 行业动态 更新时间:2024-10-18 01:27:09
本文介绍了java.lang.SecurityException:正在发送短信:uid 10282没有android.permission.SEND_SMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用程序不断崩溃,并显示以下错误代码:

My app keeps crashing with this error code:

java.lang.SecurityException: Sending SMS message: uid 10282 does not have android.permission.SEND_SMS.

这是我的代码

Button button2 = (Button) findViewById(R.id.text); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String messageToSend = "this is a text"; String number = "XXXXXX"; SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null,null); } });

}

推荐答案

尝试在您的第一个活动的onCreate方法中添加此代码,如果仍然存在任何错误,请随时与我联系.这将检查SMS权限,并在未授予SMS权限的情况下进行请求.

Try adding this code in onCreate method of your 1st activity and feel free to contact me again if any error persists. This will check for SMS permission and will ask for it in case it hasn't been granted.

Here, 'this' is the current activity if ((ContextCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) + ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS)) != PackageManager.PERMISSION_GRANTED) { // Permission is not granted // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this,"Manifest.permission.READ_SMS") || ActivityCompat.shouldShowRequestPermissionRationale(this,"Manifest.permission.READ_SMS")) { // Show an explanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed; request the permission ActivityCompat.requestPermissions(this, new String[]{"Manifest.permission.READ_SMS, Manifest.permission.SEND_SMS"}, REQUEST_CODE); // REQUEST_CODE is an // app-defined int constant. The callback method gets the // result of the request. } } else { // Permission has already been granted }

更多推荐

java.lang.SecurityException:正在发送短信:uid 10282没有android.permission.SEND

本文发布于:2023-11-27 04:02:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636504.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送短信   SecurityException   java   lang   uid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!