拜仁已伤
拜仁已伤
  • 发布:2018-10-09 10:01
  • 更新:2019-07-30 09:18
  • 阅读:1912

安卓通过广播来定时启动个推service或activity报错

分类:HBuilder

function addAlarm() {
// --- 注册监听 start ---
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var filter = new IntentFilter(ALARM_RECEIVER);
main.registerReceiver(receiver, filter);
// --- 注册监听 end ---
// --- 设置闹铃时间 start ---
var Calendar = plus.android.importClass('java.util.Calendar');
var calendar = Calendar.getInstance();
// 11点4分执行
// calendar.set(Calendar.HOUR_OF_DAY, 13);
// calendar.set(Calendar.MINUTE, 41);
// calendar.set(Calendar.SECOND, 0);
// 过5s 执行
calendar.setTimeInMillis(Date.parse(new Date()));
calendar.add(Calendar.SECOND, 5);
// --- 设置闹铃时间 end ---
// --- 设置闹铃 ---
var Intent = plus.android.importClass('android.content.Intent');
var intent = new Intent(ALARM_RECEIVER);
//
// var PendingIntent = plus.android.importClass('android.app.PendingIntent');
//var sender = PendingIntent.getBroadcast(main, 0, intent, 0);

            var PendingIntent = plus.android.importClass('android.app.PendingIntent');  
          var sender=PendingIntent.getService(main, 0, intent, 0);  
            var AlarmManager = plus.android.importClass("android.app.AlarmManager");  
            var Context = plus.android.importClass("android.content.Context");  
            var alarm = main.getSystemService(Context.ALARM_SERVICE);  
            // 一次    
            alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);  
            // 重复多次  
            //alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5 * 1000, sender);  
            mui.toast("设置闹铃5秒后提醒: "+getCurTime());  
        };
2018-10-09 10:01 负责人:无 分享
已邀请:
8***@qq.com

8***@qq.com

原生代码应该为:
PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

你试试
var sender=PendingIntent.getBroadcast(main, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

getui_johny

getui_johny - 个推技术支持

var sender=PendingIntent.getService(main, 0, intent, 0);
这个方法没有反射到

如问题未能得到解决,可以从HB群或个推官网(https://www.getui.com/cn/)里面联系技术咨询

该问题目前已经被锁定, 无法添加新回复