Reputation: 243
I am trying to launch an activity from a broadcast receiver that listens to outgoing call which is 5556. The problem is, the activity is not being launched but the dial inbuilt activity is being called, I have changed the priority of the intent to 100 but to no avail. How do I get the activity to launch at dial instead of the inbuilt calling activity? Here is the code:
package com.messageHider;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class launchReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
String compare_num="5556";
if(number.equals(compare_num))
{
Intent myintent=new Intent(context,messageHider.class);
myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myintent);
abortBroadcast();
}
}
}
Manifest file:
<receiver android:name=".launchReceiver">
<intent-filter android:priority="0">
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
Upvotes: 7
Views: 4271
Reputation: 51
Instead of aborting broadcast with abortBroadcast(); use setResultData(null) to end the call after launching your activity.
Upvotes: 3
Reputation: 14974
In your manifest you require one permission (according to the docs):
You must hold the PROCESS_OUTGOING_CALLS permission to receive this Intent.
And that is
"android.permission.PROCESS_OUTGOING_CALLS"
Also straight from the docs:
Any BroadcastReceiver receiving this Intent must not abort the broadcast.
And here is the link to the page where I got the info:
http://developer.android.com/reference/android/content/Intent.html
Upvotes: 3