znl_12 2013-06-06 07:40 采纳率: 0%
浏览 1740
已采纳

Broadcast service 没有被调用

我使用下面的代码调用 Broadcast service

Intent i = new Intent(this, BootUpReceiverRecall.class);
        sendBroadcast(i);
 <receiver  android:process=":remote" android:name="BootUpReceiverRecall"></receiver>
public class BootUpReceiverRecall extends BroadcastReceiver 
{
      // Restart service every 30 seconds
      private static final long REPEAT_TIME = 1000 * 30;
      @Override
      public void onReceive(Context context, Intent intent) 
      {
        AlarmManager service = (AlarmManager) context
            .getSystemService(Context.ALARM_SERVICE);
        Intent i = new Intent(context, BootUpReceiver.class);
        PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
            PendingIntent.FLAG_CANCEL_CURRENT);
        Calendar cal = Calendar.getInstance();
        // Start 30 seconds after boot completed
        cal.add(Calendar.SECOND, 30);
        //
        // Fetch every 30 seconds
        // InexactRepeating allows Android to optimize the energy consumption
        service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
            cal.getTimeInMillis(), REPEAT_TIME, pending);
        // service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
        // REPEAT_TIME, pending);
      }

但是我的BootUpReceiver 从来没有被调用,哪里出错了呢?

  • 写回答

2条回答

  • 码密码密哄 2013-06-06 08:00
    关注
    Intent i = new Intent(this, BootUpReceiverRecall.class);
            sendBroadcast(i);
    

    为什么要这样写呢? 我是没这样写过
    广播分2中注册方式:
    1中是代码注册,局部广播 可以写在Activity中

    YourReceiver reveiver = new YourReceiver ();
    IntentFilter filter = new IntentFilter();
            filter.addAction("yourAction");
            registerReceiver(reveiver , filter);
    

    Activity生命周期中可以管理register 和 unregister
    2.manifest配置 节点下
    创建 YourReceiver在xx.xx.xx.receiver(随便写)包下 extends BrocastReceiver
    根据action过滤

    你这个可改成

    Intent i = new Intent(“action”);
            sendBroadcast(i);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?