MinnuKaAnae
MinnuKaAnae

Reputation: 1646

Incoming call manage from android app

Is it possible to develop one application that if incoming call is coming I need to open my android app, in that I have to answer/reject the call and another option that is divert call. If i click on divert button call needs to transfer to another person. I dont have idea on this concept. Can we do it like this?

Upvotes: 1

Views: 216

Answers (1)

Vaibhav Kadam
Vaibhav Kadam

Reputation: 699

Manifest.xml

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

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name" >

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

    <activity android:name="StartActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

MyPhoneReceiver.JAVA

public class MyPhoneReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        String state = extras.getString(TelephonyManager.EXTRA_STATE);

        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
            String phoneNumber = extras
                    .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Log.e("DEBUG", phoneNumber);
        }
    }
}

}

StartActivity.JAVA

public class StartActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Intent intent = new Intent("tuet");
    sendBroadcast(intent);
}

}

Thank you!

Upvotes: 2

Related Questions