0

我正在尝试在设备的闹钟应用程序中设置新的闹钟Intent(AlarmClock.ACTION_SET_ALARM)。它适用于我尝试的所有手机。但在 Galaxy S2 中它不起作用。该意图打开一个空的黑屏时钟应用程序,而不是闹钟应用程序。

编码:

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
    i.putExtra(AlarmClock.EXTRA_HOUR, hour);
    i.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
    i.putExtra(AlarmClock.EXTRA_MESSAGE,personalMessage);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
    }
    startActivity(i);

如果我直接打开应用程序(com.sec.android.app.clockpackage.ClockPackage, setClassName,所有这些东西),我可以打开正确的应用程序但不设置警报。

编码:

String packageName = "com.sec.android.app.clockpackage";  
    String className = "com.sec.android.app.clockpackage.ClockPackage";  
    Intent internetIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
    internetIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    internetIntent.setClassName(packageName, className);
    internetIntent.putExtra(AlarmClock.EXTRA_HOUR, hour);
    internetIntent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
    internetIntent.putExtra(AlarmClock.EXTRA_MESSAGE,personalMessage);
    startActivity(internetIntent);

有谁知道?!

谢谢!

4

1 回答 1

0

我遇到了同样的问题。

尝试这个:

private void setAlarmNow() {
    GregorianCalendar cal = new GregorianCalendar();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE)+1;//to make sure it won't be set at the next day
    intent = new Intent(AlarmClock.ACTION_SET_ALARM);
    intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
    intent.putExtra(AlarmClock.EXTRA_MINUTES, minute);
    intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);    

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.add(Calendar.SECOND, 10);
    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);   
    Log.d(TAG, "Backup alarm geset.");
}
于 2013-07-09T14:00:51.623 回答