首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android.provider.Telephony.SMS_RECEIVED不工作

android.provider.Telephony.SMS_RECEIVED不工作
EN

Stack Overflow用户
提问于 2016-05-05 13:33:11
回答 1查看 1.6K关注 0票数 0

我的应用程序无法捕获android.provider.Telephony.SMS_RECEIVED,我尝试更改优先级,但仍然不起作用。

AndroidManifest.xml `

代码语言:javascript
运行
复制
<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`

代码语言:javascript
运行
复制
@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Broadcasted", Toast.LENGTH_LONG).show();
}`
EN

回答 1

Stack Overflow用户

发布于 2016-05-05 14:42:18

您想要使用一个危险的权限。

如果您的应用程序是23+,则应具有<uses-permission>,并通过调用ContextCompat.checkSelfPermission()签入代码,如果未授予权限,则通过调用ActivityCompat.requestPermissions()在代码中请求它

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37043116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档