本文介绍了短信不发送棉花糖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在单击按钮时打开系统默认消息传递"活动.这是我的代码:
I am trying to open System default Messaging activity when clicking on a button. Here is my code:
smsUri = Uri.parse("tel:" + teacherPhone2);
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("address", teacherPhone);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
它在MarshMallow下可以正常工作.但是在MarshMallow中,单击该按钮时应用程序崩溃.我已经设置了用户权限,还请求发送短信许可.谁能告诉我为什么会这样吗?
It works fine below MarshMallow. But in MarshMallow the app crashes when clicking that button. I have set the user-permission and also requested send sms permission.Can anyone tell me why this happens?
推荐答案
String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_SMS, Manifest.permission.CAMERA};
if(!hasPermissions(this, PERMISSIONS)){
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
public static boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
尝试此代码
这篇关于短信不发送棉花糖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!