权限拒绝,即使添加正确的许可清单 [英] Permission Denial , even after adding the correct permission in the manifest

查看:822
本文介绍了权限拒绝,即使添加正确的许可清单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,它会监听传入的短信。我已经添加了权限:

I am developing an app which listens to incoming sms. I have added the permission:

<uses-permission android:name="android.permission.RECEIVE_SMS" ></uses-permission> 

我的应用程序清单。是的,它是不接收标签内。

to my app manifest. And yes, it is not inside the receiver tag.

我想从一个仿真程序发送一个短信到另外一个测试应用程序。我的logcat得到如下条目:

I am trying to test the app by sending a sms from one emulator to another. My logcat gets the following entry :

WARN/ActivityManager(66): Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } to com.android.LUC requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

怪异的是,当我测试应用程序的模拟器运行的是Android 3.2,它工作正常!

The weird part is that when I am testing the app on emulator running android 3.2 it works fine!

应用程序清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.sms"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
 <uses-permission android:name="android.permission.RECEIVE_SMS" ></uses-permission>
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:permission="android.permission.RECEIVE_SMS">
        <activity android:name=".TestSMSReceiveActivity"
                  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=".mysmstestcall" android:enabled="true">
            <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
            </receiver>
    </application>



</manifest>

mysmstestcall是的BroadcastReceiver类TestSMSReceiveActivity是主要的活动。该应用程序无法接收消息模拟器运行Android 2.2。请帮助!

mysmstestcall is the broadcastreceiver class and TestSMSReceiveActivity is the main activity. The app fails to receive message in emulator running android 2.2. Please help!!

推荐答案

确定问题出在你的清单。我的工作短信广播接收器具有以下明显的条目:

OK the problem is in your manifest. My working SMS broadcast receiver has the following manifest entry:

<receiver
    android:name=".IncomingSmsBroadcastReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

您不需要一个机器人:接收器上的权限属性。你只需要以下权限接收广播,并能看到邮件的内容:

You do not need an android:permission attribute on the receiver. You just need the following permission to receive the broadcast and be able to look at the contents of the message:

<uses-permission android:name="android.permission.RECEIVE_SMS" />

最经常被错过的事情是安卓出口=真正的宣布这是需要为正在接收广播源自自己的应用程序外的接收器时。不用说,默认该属性为假。快乐的短信接收。

The thing most often missed is android:exported="true" when declaring the receiver which is required as you are receiving a broadcast that originates from outside your own application. Needless to say, the default for this property is 'false'. Happy SMS Receiving.

这篇关于权限拒绝,即使添加正确的许可清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆