I tried to start a activity by dialing a certain number. But I can't receive NEW_OUTGOING_CALL
broadcast on the HTC g17. Here is my code.
<receiver android:name="com.example.security.receiver.CallPhoneReceiver">
<intent-filter >
<action
android:name="android.intent.action.NEW_OUTGOING_CALL"
android:priority="10000"/>
</intent-filter>
</receiver>
and I have added the permission like this
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
and my receiver function is
package com.example.security.receiver;
import com.example.security.ui.LostProtectedActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class CallPhoneReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("annoy",this.getResultData());
String outPhoneNumber = this.getResultData();
if(outPhoneNumber.equals("201314")){
Intent i = new Intent(context,LostProtectedActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
setResultData(null);
}
}
}
I have figured it out yet.There is a mistake in the "CallPhoneReciever".It should be
context.startActivity(i);
not
context.startActivity(intent);
And I find it's better to set the priority to 2147483647 (the max value of int), it is prior than 1000. But granted that priority is 2147483647, there are some applications made by some big company, they will register the BroadcastReceiver
dynamically when the telephone is starting up, and these application will receive the broadcast early than applications that are registered statically.