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>
registerReceiver() method. The implementing class for a receiver extends the BroadcastReceiver class. If the event for which the broadcast receiver has registered happens, the onReceive() method of the receiver is called by the Android system.
Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.
Broadcast Receivers are used to listen for Broadcast Intents. To enable a Broadcast Receiver, it needs to be registered, either in code or within the application manifest.
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
Instead of aborting broadcast with abortBroadcast(); use setResultData(null) to end the call after launching your activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With