Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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"
- android:exported="true">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <receiver android:name=".BlockCallReceiver" android:exported="true">
- <intent-filter>
- <action android:name="android.intent.action.PHONE_STATE" />
- <action android:name="android.intent.action.USER_PRESENT" />
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </receiver>
- </application>
- public class PhoneStateReceiver extends BroadcastReceiver {
- public void onReceive(Context context, Intent intent) {
- // TODO Auto-generated method stub
- String str = intent.getAction();
- if ("android.intent.action.PHONE_STATE".equals(str))
- inComing(context, intent);
- if ("android.intent.action.NEW_OUTGOING_CALL".equals(str))
- outGoing(context, intent);
- }
- private void inComing(Context context, Intent intent){
- String callState = intent.getStringExtra("state");
- if ("RINGING".equals(callState)){
- Log.i(TAG, "RINGING SENDS BUSY");
- }else if ("OFFHOOK".equals(callState)){
- Log.i(TAG, "OFFHOOK SENDS BUSY");
- }else if("IDLE".equals(callState)){
- Log.i(TAG, "IDLE SENDS AVAILABLE");
- }
- }
- private void trueCallerOutgoing(Context context, Intent intent)
- {
- String callState = intent.getStringExtra("state");
- if ("RINGING".equals(callState)){
- Log.i(TAG, "RINGING SENDS BUSY");
- }else if ("OFFHOOK".equals(callState)){
- Log.i(TAG, "OFFHOOK SENDS BUSY");
- }else if("IDLE".equals(callState)){
- Log.i(TAG, "IDLE SENDS AVAILABLE");
- }
- }
- }
- <receiver android:name="PhoneStateReceiver" >
- <intent-filter>
- <action android:name="android.intent.action.PHONE_STATE" />
- <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
- </intent-filter>
- </receiver>
- <uses-permission android:name="android.permission.READ_PHONE_STATE" />
Add Comment
Please, Sign In to add comment