本文介绍了广播接收器在图书馆不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我在图书馆项目中创建一个广播接收器。
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;从清单。
更多推荐
广播接收器在图书馆不工作
发布评论