android.provider.Telephony.SMS_RECEIVED无效

时间:2016-05-05 05:33:11

标签: android

我的应用程序无法捕获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();
}`

1 个答案:

答案 0 :(得分:1)

您想使用危险权限之一。

如果您的APP为23岁以上,您应该拥有<uses-permission>并通过调用ContextCompat.checkSelfPermission()检查您的代码,如果您的代码中未通过调用{{1}授予权限请求}

阅读documentation有关在Android 6.0 +中运行时请求权限的信息。

相关问题