我的应用程序无法捕获android.provider.Telephony.SMS_RECEIVED,我尝试更改优先级,但仍然不起作用。
AndroidManifest.xml `
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
>
<receiver android:enabled="true" android:exported="true" android:name="com.example.dexter.texter.MyReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>`
MyReceiver.java`
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcasted", Toast.LENGTH_LONG).show();
}`发布于 2016-05-05 14:42:18
您想要使用一个危险的权限。
如果您的应用程序是23+,则应具有<uses-permission>,并通过调用ContextCompat.checkSelfPermission()签入代码,如果未授予权限,则通过调用ActivityCompat.requestPermissions()在代码中请求它
有关在Android 6.0+中运行时请求权限的信息,请阅读documentation。
https://stackoverflow.com/questions/37043116
复制相似问题