0

私のコードでは、AndroidマニフェストファイルでBoot Completedのすべての権限を追加しました。ブロードキャストレシーバーをログに記録しました。再起動後、コントロールはブロードキャストレシーバーに入りますが、アラームは発生しません。アラームをトリガーします。通常の場合(シャットダウンする前)、アラームが発生し、アクティビティが起動します。再起動後、アラームは発生しません。

これは私のBoadcastレシーバーです

public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Log.d("hai", "inside onreceive");
    try {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {


                    Calendar cal = new GregorianCalendar();
                    cal.setTimeInMillis(System.currentTimeMillis());

                    cal.set(Calendar.HOUR_OF_DAY,9);
                    cal.set(Calendar.MINUTE,49);
                    cal.set(Calendar.SECOND, 0);
                    cal.set(Calendar.MILLISECOND, 0);

                    Intent intent1 = new Intent(context,
                            AlarmLauncher.class);
                    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent1.putExtra("alarm_message", "feathersoft Rules!");
                    // In reality, you would want to have a static variable
                    // for the request code instead of 192837
                    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent1,PendingIntent.FLAG_CANCEL_CURRENT);
                    Log.d("hai",
                            "alarm set");

                    // Get the AlarmManager service
                    AlarmManager am = (AlarmManager) context
                            .getSystemService(context.ALARM_SERVICE);
                    // am.set(AlarmManager.RTC_WAKEUP,
                    // cal.getTimeInMillis(), sender);
                    am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
                            sender);
                    Log.d("hai",
                            "Alarm Alert:Inside the boot completed broadcast receiver......");



                Log.d("hai",
                        "Alarm Alert:Inside the boot completed broadcast receiver......");
            }
        } 

    }catch (Exception e) {
            Toast.makeText(
                    context,
                    "There was an error somewhere, but we still received an alarm",
                    Toast.LENGTH_SHORT).show();
            e.printStackTrace();


        }
    try {

    if(intent.getAction().equals(null))
        {

                SharedPreferences sp = context
                        .getSharedPreferences(
                                BigBirdConstants.nameOfPreference,
                                context.MODE_PRIVATE);
                String alrm = sp.getString(
                        BigBirdConstants.pref_myflight_alarm_time, "hello");
                Log.d("hai", alrm);
                Intent newIntent = new Intent(context, AlarmLauncher.class);
                newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                System.out.println("boot completed");
                // newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(newIntent);
            } 
        }catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

これは再起動後の私のアラームdumpsysです

$ dumpsys alarm
 dumpsys alarm
  Current Alarm Manager state:

  Realtime wakeup (now=1334031884759):
 RTC_WAKEUP #2: Alarm{460a6c88 type 0 com.android.providers.calendar}
  type=0 when=1334110692157 repeatInterval=0 count=0
  operation=PendingIntent{45dea300: PendingIntentRecord{460a6c10 com.android.p
roviders.calendar broadcastIntent}}
RTC_WAKEUP #1: Alarm{460eb1d0 type 0 com.google.android.gsf}
  type=0 when=1334073656706 repeatInterval=566387000 count=0
operation=PendingIntent{45d0d9c8: PendingIntentRecord{4606f3c0 com.google.an
droid.gsf broadcastIntent}}
  RTC_WAKEUP #0: Alarm{4610cd88 type 0 com.google.android.gsf}
    type=0 when=1334032080140 repeatInterval=1800000 count=0
    operation=PendingIntent{46057dc0: PendingIntentRecord{4610cd10 com.google.an
droid.gsf broadcastIntent}}
  RTC #1: Alarm{45ed7b10 type 1 android}
    type=1 when=1334082600000 repeatInterval=0 count=0
    operation=PendingIntent{45dd2c10: PendingIntentRecord{45e81c08 android broad
castIntent}}
  RTC #0: Alarm{461bf460 type 1 android}
    type=1 when=1334031900000 repeatInterval=0 count=0
    operation=PendingIntent{45cceb98: PendingIntentRecord{45f2b3e0 android broad
castIntent}}

  Elapsed realtime wakeup (now=527752):
  ELAPSED_WAKEUP #2: Alarm{46169c28 type 2 android}
    type=2 when=25881048 repeatInterval=0 count=0
    operation=PendingIntent{45d0c358: PendingIntentRecord{45cc99b0 android broad
castIntent}}
  ELAPSED_WAKEUP #1: Alarm{4610dc40 type 2 com.google.android.gsf}
    type=2 when=995077 repeatInterval=0 count=0
    operation=PendingIntent{460dd5c8: PendingIntentRecord{4610dbc8 com.google.an
droid.gsf broadcastIntent}}
  ELAPSED_WAKEUP #0: Alarm{46011b68 type 2 com.google.android.apps.maps}
    type=2 when=970384 repeatInterval=900000 count=0
    operation=PendingIntent{45f9f478: PendingIntentRecord{45fea1d0 com.google.an
droid.apps.maps startService}}
  ELAPSED #1: Alarm{460da648 type 3 android}
    type=3 when=2557073343 repeatInterval=0 count=0
    operation=PendingIntent{45f84d38: PendingIntentRecord{45e34428 android broad
castIntent}}
  ELAPSED #0: Alarm{4609a418 type 3 android}
    type=3 when=727667 repeatInterval=0 count=0
    operation=PendingIntent{45f7da98: PendingIntentRecord{45e39420 android broad
castIntent}}

  Broadcast ref count: 0

  Alarm Stats:
  com.bigbird.Activity
    20ms running, 1 wakeups
    1 alarms: flg=0x10000004 cmp=com.bigbird.Activity/.AlarmLauncher
  com.google.android.gsf
    47ms running, 1 wakeups
    1 alarms: act=com.google.android.intent.action.GTALK_RECONNECT flg=0x4
  android
    22819ms running, 3 wakeups
    1 alarms: act=com.android.internal.policy.impl.PhoneWindowManager.DELAYED_KE
YGUARD flg=0x4
    8 alarms: act=android.intent.action.TIME_TICK flg=0x40000004
    2 alarms: act=android.content.syncmanager.SYNC_ALARM flg=0x4
$
4

1 に答える 1

1

問題が発生しました

保留中のインテントでは、起動するアクティビティが使用されます。それは障害です。保留中のインテントでは、ブロードキャストレシーバーをインテントとして使用する必要があります。

if (sp.getBoolean(BigBirdConstants.pref_alarm_set, false)) {
                String alrm = sp.getString(
                        BigBirdConstants.pref_myflight_alarm_time, "hello");
                String alrmtime[] = new String[2];


                    alrmtime = alrm.split(":");

                    Calendar cal = new GregorianCalendar();
                    cal.setTimeInMillis(System.currentTimeMillis());
                    /*
                     * Integer.parseInt(alrmtime[
                     * 0])
                     */
                    /* Integer.parseInt(alrmtime[1]) */
                    cal.set(Calendar.HOUR_OF_DAY,11);
                    cal.set(Calendar.MINUTE,13);
                    cal.set(Calendar.SECOND, 0);
                    cal.set(Calendar.MILLISECOND, 0);

                    Intent intent1 = new Intent(context,
                            AlarmReceiver.class);
                    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent1.putExtra("alarm_message", "feathersoft Rules!");
                    // In reality, you would want to have a static variable
                    // for the request code instead of 192837
                    PendingIntent sender = PendingIntent.getBroadcast(context, 192837, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
                    Log.d("hai",
                            "alarm set");
于 2012-04-10T06:12:45.290 に答える