广播接收器在图书馆不工作

编程入门 行业动态 更新时间:2024-10-12 03:19:54
本文介绍了广播接收器在图书馆不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好我在图书馆项目中创建一个广播接收器。

Hi Guys I created a broadcast receiver in a Library Project.

下面是code

import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // When our Alaram time is triggered , this method will be excuted (onReceive) // We're invoking a service in this method which shows Notification to the User Intent myIntent = new Intent(context, AlarmNotificationService.class); context.startService(myIntent); } }

我使用警报管理使用低于code触发广播接收机。

I trigger the broadcast receiver using alarm manager using the below code.

Intent myIntent = new Intent("Alarm"); myIntent.setClass(activity, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, myIntent, 0); AlarmManager alarmManager = (AlarmManager)activity.getSystemService(activity.ALARM_SERVICE); long time = System.currentTimeMillis() + 10 * 1000; alarmManager.set(AlarmManager.RTC, time , pendingIntent);

我定义在主项目的清单接收器如下图所示。

I defined the receiver in the main project's manifest as shown below

<receiver android:name="com.library.packagename.AlarmReciever"> <intent-filter> <action android:name="Alarm" /> </intent-filter> </receiver>

但广播接收机是没有得到触发。

but the broadcast receiver is not getting triggered.

推荐答案

如果你这样做,而不设置操作,您的广播将闪光。

If you do this without setting the action, your broadcast will fire.

Intent intent = new Intent(activity, AlarmReceiver.class); alarmIntent = PendingIntent.getBroadcast(activity, 0, intent, 0);

同时删除&lt;作用机器人:名字=报警/&GT;从清单。

更多推荐

广播接收器在图书馆不工作

本文发布于:2023-11-27 12:57:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638175.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接收器   图书馆   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!