Sakkeer Hussain Sakkeer Hussain - 3 months ago 18
Android Question

How to set intent filter for dial action in android?

I am trying to create a simple dial pad. I created all that and now I like to receive action dial intent from other applications.

<intent-filter>

<action android:name="android.intent.action.DIAL" />

<category android:name="android.intent.category.DEFAULT" />

<data android:xxxxxx="XXXXXX" />

</intent-filter>


and now I don't know what should be filled with the data in action filter.
Can anyone help me ?
Thanks in advance.

Answer

This is the intent filter should be used.

<intent-filter>
<action android:name="android.intent.action.CALL_DIAL" />                
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>

And we can read the phone number from onCreate methord like this.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //start reading here
        Intent intent = getIntent();
        if(intent.getData()!=null){
            Log.d("intent received",intent.getData().toString());
            String phoneNumber = intent.getData().toString(); //contains tel:phone_no
            phoneNumber = phoneNumber.substring(4);
            Log.d("intent received","Received phone number : "+phoneNumber);
                  /// do what you like here
        }else{
            Log.d("intent received","null intent received");
        }
}
Comments