0

私は、私の Java サブジェクトのリマインダー アプリケーションを開発しています。

このコードを使用して保留中のアラームを作成しています。コードは次のとおりです。

Intent intent2 = new Intent(ReminderActivity.this, AlarmReceiver.class);
                intent2.putExtra("idint", iid);
                intent2.putExtra("title", myRem.getText().toString());
                intent2.putExtra("title_desc", myRemDesc.getText().toString());
                intent2.putExtra("date", date.toString());
                PendingIntent pendingIntent = 
                        PendingIntent.getActivity(ReminderActivity.this,iid, intent2,
                                PendingIntent.FLAG_CANCEL_CURRENT);
                AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
                am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);

そして、起動時に受信機を追加するように AndroidManifest.xml を設定しました

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name="PollReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
</receiver>

そして最後に、これは私の PollReceiver.class です

public class PollReceiver extends BroadcastReceiver {
  static DBAdapter db;

  @Override
  public void onReceive(Context ctxt, Intent i) {
    scheduleAlarms(ctxt);
  }

  static void scheduleAlarms(Context ctxt) {
    db.open();
     Cursor c = db.getAllRecords();
     if(c.moveToFirst())
        {
            do{
                int iid = (int) c.getLong(0);
                String title = c.getString(1);
                String title_desc = c.getString(2);
                String date = c.getString(3);

                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    Date myDate = null;
                    try {
                        myDate = sdf.parse(date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                Calendar cal = Calendar.getInstance();
                cal.setTime(myDate);

                Calendar CurCal = Calendar.getInstance();

                if (cal.compareTo(CurCal) <= 0 )
                {
                    Intent intent2 = new Intent(ctxt, AlarmReceiver.class);
                    intent2.putExtra("idint", iid);
                    intent2.putExtra("title", title);
                    intent2.putExtra("title_desc", title_desc);
                    intent2.putExtra("date", date);

                    PendingIntent pendingIntent = 
                            PendingIntent.getActivity(ctxt,iid, intent2,
                                    PendingIntent.FLAG_CANCEL_CURRENT);
                    AlarmManager am = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
                    am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);

            }

            } while(c.moveToNext());

        }

        db.close();

  }
}

しかし、まだ保留中のアラームがリロードされないようです。

ワイルドな推測の人はいますか?

4

1 に答える 1

0

アラームが適切に設定されていて、「android.intent.action.BOOT_COMPLETE」アクションを受信して​​いないことが問題であると確信している場合は、これをカウントします。

Google によるマルウェア対策として。Google は、アプリケーションが多くのことを実行できるようになる前に、ユーザーが最初にランチャーからアクティビティを起動し、アクティビティが少なくとも 1 回明示的に起動されるまで BOOT_COMPLETED が配信されないようにすることを提唱しています。

最近のAndroidバージョンでよくある間違いです。

よろしく!

于 2014-05-01T19:17:45.623 に答える