2017-01-26 4 views
0

전화를 받았을 때 축배를 보여주고 싶지만 디버깅 모드에서는 아무 것도 일어나지 않고 OnReceive에서 멈추지 않습니다. onReceive에서 멈추지 않는 이유를 알 수 없습니다. 그것은 의도를받지 못하는 것과 같습니다.Android에서 걸려 오는 전화를 감지하려고합니다.

의 AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.rajatgupta.broadcastrecieverexample"> 



<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <receiver android:name="MyReciever"> 
     <intent-filter> 
      <action android:name="rajat_action"> 
      </action> 
     </intent-filter> 
    </receiver> 

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


</application> 

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

IncomingCall.java 내가 잘못 뭐하는 거지

public class IncomingCall extends BroadcastReceiver { 

Context mContext; 
@Override 
public void onReceive(Context context, Intent intent) { 

     try { 
    Log.d("Intent", "Intent Detected"); 
    Toast.makeText(context," Receiver start  ",Toast.LENGTH_SHORT).show(); 
} 
catch (Exception e){ 
    e.printStackTrace(); 
} 


} 
} 

?

답변

0

READ_PHONE_STATE 권한을 Manifest에 두는 것만으로는 이제 더 이상 런타임에 권한을 요청해야합니다.

권한 체크 : int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_PHONE_STATE);

요청 : ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_PHONE_STATE}, MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);

https://developer.android.com/training/permissions/requesting.html