2015-09-05 66 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或以上版本上運行代碼。