Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android AlarmManager不在Emulator上工作_Android_Emulation_Alarmmanager - Fatal编程技术网

Android AlarmManager不在Emulator上工作

Android AlarmManager不在Emulator上工作,android,emulation,alarmmanager,Android,Emulation,Alarmmanager,另一个抱怨是AlarmManager希望快速解决问题。 我正在使用Android模拟器进行开发。 我发现了一个据称有效的例子,所以我尝试使用它。 我做了以下工作: 向清单文件添加了接收方字符串 <receiver android:name=".SchHandler" android:process=":remote" /> 创建广播接收器以创建和侦听警报 public class SchHandler extends BroadcastReceiver { private

另一个抱怨是AlarmManager希望快速解决问题。 我正在使用Android模拟器进行开发。 我发现了一个据称有效的例子,所以我尝试使用它。 我做了以下工作:

向清单文件添加了接收方字符串

 <receiver android:name=".SchHandler" android:process=":remote" />
创建广播接收器以创建和侦听警报

public class SchHandler extends BroadcastReceiver {
    private final String REMINDER_BUNDLE = "ReminderBundle";

    public SchHandler (Context context, Bundle extras, int timeoutInSeconds) {    
        Toast.makeText(context, "Scheduling...", Toast.LENGTH_LONG).show();
        Log.d("Debug", "Sch");

        AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, SchHandler.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

        Toast.makeText(context, "Time:" + System.currentTimeMillis(), Toast.LENGTH_LONG).show();
        alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis() + 2000, 5000, pendingIntent);    
    }

    @Override
    public void onReceive(Context context, Intent arg1) {
       // TODO Auto-generated method stub
       Log.e(REMINDER_BUNDLE, "Receive");
       Toast.makeText(context, "Testing", Toast.LENGTH_LONG).show();
    }
}

我用set试过了,set重复,没用。我还应该尝试什么?

邪恶的根源可能是标签中的android:process=:remote。尝试删除它。

我将接收器的名称修改为完全限定的版本,结果是我使用了它的包名而不是类名。设置正确后,我使它工作。

这很奇怪。我看你的代码没有任何问题。是否执行了onReceive,但没有显示toast?如果执行,那么日志应该显示它Log.d。但是什么也没发生。那么你的广播接收器没有正确注册。尝试在AndroidManifest.xml中将某些操作添加到您的中,并将该操作设置为Intent;但是仍然没有运气。奇怪的是,有这么多关于AlarmManager的问题与这个特定问题有关,但却没有“简单”的解决方案。似乎组件本身有缺陷。
public class SchHandler extends BroadcastReceiver {
    private final String REMINDER_BUNDLE = "ReminderBundle";

    public SchHandler (Context context, Bundle extras, int timeoutInSeconds) {    
        Toast.makeText(context, "Scheduling...", Toast.LENGTH_LONG).show();
        Log.d("Debug", "Sch");

        AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, SchHandler.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

        Toast.makeText(context, "Time:" + System.currentTimeMillis(), Toast.LENGTH_LONG).show();
        alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP,
        System.currentTimeMillis() + 2000, 5000, pendingIntent);    
    }

    @Override
    public void onReceive(Context context, Intent arg1) {
       // TODO Auto-generated method stub
       Log.e(REMINDER_BUNDLE, "Receive");
       Toast.makeText(context, "Testing", Toast.LENGTH_LONG).show();
    }
}