开发者

AlarmManagerIntent doesn't get called

开发者 https://www.devze.com 2023-02-16 11:27 出处:网络
I want to use the AlarmManager to call a BroadcastReciever: Context ctx=getApplicationContext(); Intent StartIntent = new Intent(ctx, tartReceiver.class);

I want to use the AlarmManager to call a BroadcastReciever:

Context ctx=getApplicationContext();
Intent StartIntent = new Intent(ctx, tartReceiver.class);

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC, StartTime.toMillis(false), PendingIntent.getActivity(ctx, 6,
                        StartIntent, PendingIntent.FLAG_CANCEL_CURRENT ));

The receiver is declared in the manifest like this:

<receiver android:process=":remote" android:name=".StartReceiver" android:exported="true"/>

But nothing ever happens. If I use ctx.sendBroadcast(StartIntent), the intend gets called, so it should be all right, or not? I also checked the StartTime, it should be ok and I tried also 0 (which should c开发者_JAVA技巧ause the Intent to be called immediately according to the documentation).

What must I change to get it working?


JonathanK,

You want PendingIntent.getBroadcast() not PendingIntent.getActivity().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号