Android棉花糖-SMS_RECEIVED权限
我最近更新了我的应用程序以支持android 6棉花糖. 我按照 https://developer.android.com/training/permissions/requesting上的说明进行操作.html
i recently updated my app to support android 6 marshmallow. i followed the instruction on https://developer.android.com/training/permissions/requesting.html
并为Manifest.permission.RECEIVE_SMS添加了requestPermissions. 当我运行以下代码时:
and added requestPermissions for Manifest.permission.RECEIVE_SMS. when im runing the following code :
Log.i(TAG, "sending SMS...");
Intent intent = new Intent("android.provider.Telephony.SMS_RECEIVED");
intent.putExtra("pdus", data);
getContext().sendOrderedBroadcast(intent, null);
我明白了
java.lang.SecurityException:权限拒绝:不允许从pid = 1999,uid = 10056发送广播android.provider.Telephony.SMS_RECEIVED
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.provider.Telephony.SMS_RECEIVED from pid=1999, uid=10056
即使我授予SMS_RECEIVED权限,我也无法在设备上发送短信广播.
i cant send sms broadcast on the device even if i grant SMS_RECEIVED permission.
任何想法,为什么我会在android 6上收到此安全异常.
any idea why i get this security exception on android 6.
我的目标是在设备链接中生成伪造的短信[我可以发送"SMS已收到意图"? .我没有在Google上找到任何不再被提及的内容.
my goal is to generate a fake sms in my device link[can I send "SMS received intent"? . i didnt find any mentions on google that its not permitted anymore .
您需要将权限添加到清单xml:
You need to add the permission into manifest xml:
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
AND ,您需要在运行时请求权限.在android 6之前,安装时会自动授予权限.在android 6及更高版本中,您可以安装应用程序而不授予权限.您可以在活动类中使用此功能:
AND, you need to ask for the permission at runtime. Until android 6, the permissions were granted automatically on installation. In android 6 and above, you can install application and not grant the permission. You can use this function in your activity class:
private void requestSmsPermission() {
String permission = Manifest.permission.RECEIVE_SMS;
int grant = ContextCompat.checkSelfPermission(this, permission);
if ( grant != PackageManager.PERMISSION_GRANTED) {
String[] permission_list = new String[1];
permission_list[0] = permission;
ActivityCompat.requestPermissions(this, permission_list, 1);
}
}
此-您的活动.