使用AlarmManager的Unity android插件

时间:2014-04-30 13:08:12

标签: android unity3d alarmmanager

有没有在Unity项目中使用Android闹钟的方法?

我尝试创建自己的.jar并创建自己的活动,扩展UnityPlayerActivity。在OnCreate方法中,我编写了这段代码:

        Log.i("ALARM", "create alarm");
    AlarmManager am=(AlarmManager)getBaseContext().getSystemService(Context.ALARM_SERVICE);
    Intent AlarmIntent = new Intent(getBaseContext(), AlarmCheckStats.class);
    PendingIntent sender = PendingIntent.getBroadcast(getBaseContext(), 0, AlarmIntent, 0);
    long repeat=2*1000;
    am.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),repeat, sender);

日志消息显示在LogCat上,但后来永远不会进入Alarm.onReceive。我在Manifest.xml中正确声明接收器,所以我不知道为什么不工作。是否有人在Unity上做出类似的东西?

0 个答案:

没有答案