I have a BroadcastReceiver
.
AndroidManifest.xml
:
<!-- When starting calculator-->
<receiver android:name=".APP_CALCULATOR_class" >
<intent-filter>
<action android:name="android.intent.category.APP_CALCULATOR" >
</action>
</intent-filter>
</receiver>
APP_CALCULATOR_class.class
:
package com.startcalcevent.startcalcevent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class APP_CALCULATOR_class extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Calculator is on" , Toast.LENGTH_LONG).show();
}
}
Why is this code not working when I open the calculator application?
I will only start when you send an Intent that is broadcasted. A App_CALCULATOR category Intent with action (ACTION_MAIN) is not broadcasted (using sendBroadcast(Intent)
) but started as an Activity using startActivity(Intent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.