ACTION_SET_ALARM在Galaxy SII中不起作用

时间:2012-09-26 18:10:41

标签: android android-intent alarm galaxy

我正在尝试使用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.ClockPackagesetClassName,所有这些东西),我可以打开正确的应用程序,但不会设置闹钟。

代码:

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);

有谁知道?!

谢谢!

1 个答案:

答案 0 :(得分: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.");
}