我知道这已经被问了十几次了,但是我仍然得到了这个xml配置的权限错误。我已经仔细研究了关于这个问题的其他答复。我正在使用API级别23。谁能指出这个错误吗?错误是显而易见的:
09-12 09:13:40.016 1295-1309/?W/BroadcastQueue:权限拒绝:对com.example.richard.simplesmstoast/.SmsReceiver的接收意图{ act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (有额外的)}需要android.permission.RECEIVE_SMS,因为发送方com.android.phone (uid 1001)
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
发布于 2015-09-14 11:20:40
新权限模型 for Android (api 23)中存在问题:
Quickview
关于SMS案例文档,请举一个例子:
例如,假设一个应用程序在其清单中列出了它需要SEND_SMS和RECEIVE_SMS权限,这两个权限都属于android.许可权-groupp.sms,当应用程序需要发送消息时,它请求SEND_SMS权限。系统向用户显示一个对话框,询问应用程序是否可以访问SMS。如果用户同意,系统将授予应用程序它请求的SEND_SMS权限。稍后,应用程序请求RECEIVE_SMS。系统会自动授予此权限,因为用户已经在同一权限组中批准了权限。
解决办法:
发布于 2016-02-17 16:54:42
首先,必须在RECEIVE_SMS中声明AndroidManifest.xml权限。
...
<uses-permission android:name="android.permission.RECEIVE_SMS" />
...
<receiver
android:name=".receiver.IncomingSmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>然后,从API级别23,我们需要在运行时请求RECEIVE_SMS权限。注意到这一点很重要。https://developer.android.com/training/permissions/requesting.html
public class MainActivity extends AppCompatActivity {
private static final int PERMISSIONS_REQUEST_RECEIVE_SMS = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Request the permission immediately here for the first time run
requestPermissions(Manifest.permission.RECEIVE_SMS, PERMISSIONS_REQUEST_RECEIVE_SMS);
}
private void requestPermissions(String permission, int requestCode) {
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this, permission)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
// 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.
Toast.makeText(this, "Granting permission is necessary!", Toast.LENGTH_LONG).show();
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{permission},
requestCode);
// requestCode is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case PERMISSIONS_REQUEST_RECEIVE_SMS: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the
// contacts-related task you need to do.
NotificationUtil.getInstance().show(this, NotificationUtil.CONTENT_TYPE.INFO,
getResources().getString(R.string.app_name),
"Permission granted!");
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
NotificationUtil.getInstance().show(this, NotificationUtil.CONTENT_TYPE.ERROR,
getResources().getString(R.string.app_name),
"Permission denied! App will not function correctly");
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
}希望这能帮到你。
发布于 2015-09-18 05:32:08
@Richard Green:您的逻辑猫抛出
权限拒绝:接收到com.example.richard.simplesmstoast/.SmsReceiver的意图{ act=android.provider.Telephony.SMS_RECEIVED flg=0x8000010 (有额外的)}需要android.permission.RECEIVE_SMS,因为发送方com.android.phone
权限是限制对代码的一部分或对设备上的数据的访问的限制。施加这一限制是为了保护可能被误用以扭曲或破坏用户体验的关键数据和代码。
我认为它的权限有问题。
请将下面的舱单-Permissions添加到应用程序标签上。
<uses-permission android:name="INTERNET"/>
<uses-permission android:name="ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />我希望它能帮到你。
https://stackoverflow.com/questions/32537156
复制相似问题