Hello, everyone
I need to set alarm icon in status bar, without a notification. It works
when application is running, but after finishing an application, the
receiver does not respond on "ALARM_CHANGED", only on "BOOT_COMPLETED".
Need to set alarm icon after user turns off alarms in build-in Alarm Clock.
Thanks.
manifest:
<receiver android:name=".Alarm.AlarmInitReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ALARM_CHANGED" />
</intent-filter></receiver>
AlarmInitReceiver.java:
public class AlarmInitReceiver extends BroadcastReceiver {@Overridepublic void
onReceive(Context context, Intent intent) {
if (intent.getAction() != null) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
Toast.makeText(context, "BOOT-completed", Toast.LENGTH_LONG).show();
}
if (intent.getAction().equals("android.intent.action.ALARM_CHANGED")) {
Toast.makeText(context, "Alarm on", Toast.LENGTH_SHORT).show();
setStatusBarIcon(true);
}
}}
MainActivity:
public class MainActivity extends Activity {
@Overridepublic void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setStatusBarIcon(true);
enableReceiver(true);
}
protected void enableReceiver(boolean enable) {
ComponentName receiver = new ComponentName(mContext,
AlarmInitReceiver.class);
PackageManager pm = mContext.getPackageManager();
pm.setComponentEnabledSetting(receiver,
(enable) ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);}
public static void setStatusBarIcon(boolean enabled){
Intent alarmChanged = new Intent("android.intent.action.ALARM_CHANGED");
alarmChanged.putExtra("alarmSet", enabled);
mContext.sendBroadcast(alarmChanged);}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/fe243471-8a4b-4dac-a400-fd692264209a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.