2015-09-05 67 views
4

我想创建一个应用程序,当我打出电话时输入日志消息。权限拒绝与广播接收器

但是,当我运行代码时,我得到了权限拒绝,尽管我输入了权限。

拒绝登录:

“2月9日至4日:35:50.535 1294年至1666年/ W/BroadcastQueue:权限拒绝:接收意图{ACT = android.intent.action.NEW_OUTGOING_CALL FLG = 0x10000010(具有额外)}到samples.varma.packagecom.testreceive2/.CallReceiver需要因寄件人的Android(UID 1000)android.permission.PROCESS_OUTGOING_CALLS”

清单代码:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="samples.varma.packagecom.testreceive2" > 
    android:versionCode="1" 
    android:versionName="1.0"> 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="23" /> 


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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 


     <activity 
      android:name=".MainActivity" 
      android:enabled="true" 
      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=".CallReceiver"> 


      <intent-filter> 
       <action android:name="android.intent.action.PHONE_STATE"/> 
       <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> 
      </intent-filter> 
     </receiver> 
    </application> 


</manifest> 

这里是我的接收器的代码:

package samples.varma.packagecom.testreceive2; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.telephony.TelephonyManager; 
import android.util.Log; 

public class CallReceiver extends BroadcastReceiver { 
    public CallReceiver() { 
    } 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); 
     if (state == null) { 
      String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
      Log.i("TAG", "Outgoing Number: " + number); 
     } else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { 
      String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
      Log.i("TAG", "Incoming Number: " + number); 
     } 
    } 
     } 

我对此很新,所以很有可能有几个错误或者我完全不在基地。无论如何,我会非常感谢任何指导。有人会知道我为什么会得到这种否认吗?

感谢

编辑:

它也给了我这些权限否认,即使我已经添加了手机状态的权限。

特权电话状态权限是系统权限,所以我不能添加。

09-04 04:36:03.249 1294-1440/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000) 
09-04 04:36:03.271 1294-1308/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000) 

1294-1308/? W/BroadcastQueue﹕ Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to samples.varma.packagecom.testreceive2/.CallReceiver requires android.permission.READ_PHONE_STATE due to sender android (uid 1000) 
+0

请看看http://stackoverflow.com/questions/6254551/intercepting-outgoing-call-what-am--missing –

+0

你可以检查这个链接http://www.codeproject.com/Articles/548416/Detecting-incoming-and-outgoing-phone-calls-on-And –

+0

添加清单

回答

2

我得到它通过以下链接紧密合作Intercepting outgoing call - what am I missing?(感谢ajit)

我结束了ta king取消PHONE_STATE权限,在清单中向我的接收者添加android:enabled =“true” 和android:exported =“true”,将NEW_OUTGOING_CALL权限重定位到下面的应用程序(不确定是否有必要) sdk版本,并基本上从接口复制接收器。从接收器标签

更新的清单代码来体现标签:

<receiver 
      android:name=".testreceive3" 
      android:enabled="true" 
      android:exported="true" > 
      <intent-filter> 

       <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>--> 
      </intent-filter> 
     </receiver> 
    </application> 

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

</manifest> 

让我知道是否有其他人需要更多的信息。

0

您应该添加以下的事情在你的清单接收

<service android:name=".CallReceiver" 
      android:enabled="true" 
      android:exported="false" > 
     </service> 
0

使用许可CALL_PHONE而不是OUTGOING

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

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

我已经启动了Android模拟器并没有什么相同的应用程序帮助,甚至

android:enabled="true" 
android:exported="true" 

解决的办法是去设置 - >应用程序 - >所有MyApplication - >权限 - >切换电话的权限。

Android Phone Permission for Application

0

ü需要申请运行许可INT您的代码时,在Android 6.0或以上版本上运行代码。