13

I am trying to register my Activity so that it can be used by the Activity chooser/picker allowing a user to choose whether or not to select my application/Activity to complete what they are trying to do.

I want to provide the option for the user to be able to select my application when they want to send an SMS message and when they want to place an outgoing call, to try to achieve this I added the following pieces of code within my Activity tags in my manifest:

<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

However the Activity chooser never appears and the native apps are used without providing a choice to the user. Can anyone see where I am going wrong?

EDIT:

I have figured out I need to add

<data android:scheme="sms" />
<data android:scheme="smsto" />

for the SMS message but what do I use for the outgoing call?

EDIT 2:

I have tried the following for the outgoing call:

 <intent-filter>
 <action android:name="android.intent.action.VIEW" />
 <action android:name="android.intent.action.DIAL" />
 <category android:name="android.intent.category.DEFAULT" />
 <category android:name="android.intent.category.BROWSABLE" />
 <data android:scheme="tel" />
 </intent-filter>

But again with no luck, has this been blocked from 1.6 on?

Edit 3:

This is what happens when I click Text Mobile:

alt text

So i want the same thing when I click Call mobile

Donal Rafferty
  • 19,707
  • 39
  • 114
  • 191

4 Answers4

9

I think it should help you

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

Tested on Android 2.1

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
Konrad
  • 106
  • 1
  • 1
    Has anyone noticed that this does not work on HTC phones? I've added the same intent-filter to my activity, and it works on some phones, but on the HTC Incredible my activity is never presented as a choice to complete the intent. – E-Riz Sep 20 '11 at 18:15
3

This is because activities and services can not pickup outside intents on their own. You need to use a BroadcastReceiver. To implement this, do the following:

Extend Android's BroadcastReceiver class like so:

public class MyReceiver extends BroadcastReceiver {

 @Override
 public void onReceive(Context context, Intent intent) {
        Context context = getApplicationContext();
  Intent sendIntent = new Intent();
  if ( intent.getAction().equals(Intent.NEW_OUTGOING_CALL) ) {
   sendIntent.setClass(context, MyActivity.class);
   context.startActivity(sendIntent);
  }
        else if ( intent.getAction().equals(Intent.SOME_OTHER_INTENT) {
            sendIntent.setClass(context, MyService.class);
   context.startService(sendIntent);
        }
        // More else ifs for more intents you want to catch.
 }

}

Then you need to declare the receiver in your manifest like this:

<receiver android:name="MyReceiver">
  <intent-filter>
    <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        // more intents you want to catch here
  </intent-filter>
</receiver>

Only intents declared in the manifest will be caught by your Receiver, so if you want to catch several intents thrown by the system or other programs and want to do the exact same thing when their intents are caught then specify those intents here in the manifest and skip the if/else blocks in the onReceive method.

AndrewKS
  • 3,603
  • 2
  • 24
  • 33
  • 1
    I dont think that is the correct way for me to achieve what I want, I want to register for the SEND and DIAL intents sent from the system, I have the SEND one working as above when I click on send text the "Complete action using" dialog appears which is exactly what I want, I just need to be able to do the same for when I click on call contact. – Donal Rafferty Nov 01 '10 at 15:22
  • 2
    Ah then maybe you need to specify certain permissions for which intents you want your program to be allowed to use. Look at http://developer.android.com/reference/android/Manifest.permission.html. I believe you need to use the CALL_PHONE permission. – AndrewKS Nov 01 '10 at 15:31
  • Yep, I have that in there too - Cant understand why its not working at all. – Donal Rafferty Nov 01 '10 at 15:53
2

this worked for me

   <activity
        android:label="@string/app_name"
        android:name=".TestIntentActivity" >            
      <intent-filter> 
         <action android:name="android.intent.action.CALL" />
         <category android:name="android.intent.category.DEFAULT" />
         <action android:name="android.intent.action.CALL_PRIVILEGED" />
         <data android:scheme="tel" />
      </intent-filter>
    </activity>
Sanda
  • 21
  • 2
1

You need to add a priority to the intent filter so that Android takes it into account. For example:

 <activity android:name="YourActivity">
   <intent-filter android:priority="100">
      <action android:name="android.intent.action.CALL_PRIVILEGED" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:mimeType="text/plain" />
   </intent-filter>
 </activity>
Rabi
  • 2,593
  • 1
  • 23
  • 26