when my application runs, I can get the receiver in OutcallReceiver , but when my application didn't run, I can't get the receiver, I want to know why I can not get the receiver when Application isn't in background.
However, when I use android.intent.action.BOOT_COMPLETED ,I can got the receiver,even though the application is not in background, so my question is : What 's the difference between android.intent.action.BOOT_COMPLETED And android.intent.action.NEW_OUTGOING_CALL ? they are both sent by android system. BOOT_COMPLETED can get the receiver even though my application is not in background.
1. AndroidManifest.xml
<receiver android:name=".ui.guide.OutcallReceiver" android:exported="true" >
<intent-filter android:priority="2147483647" >
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
OutcallReceiver .java
public class OutcallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String currentNumber = getResultData();
if (currentNumber == null) {
currentNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context);
String number = preference.getString(Constants.PRIVACY_DIAL_PHONE_NUMBER, "");
if (currentNumber.equals(number)) {
lockscreenApp(context);
setResultData(null);
abortBroadcast();
}
}}
0 comments:
Post a Comment