Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.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 重新启动手机后,闹钟未运行_Android_Alarmmanager - Fatal编程技术网

Android 重新启动手机后,闹钟未运行

Android 重新启动手机后,闹钟未运行,android,alarmmanager,Android,Alarmmanager,我正在开发一个可以设置警报的应用程序,但当我重新启动系统时,应用程序崩溃,并且在bootAlarm不再活动后警报无法重置。请帮我解决这个问题。我正在为此使用广播接收器 public void setAlarm(Calendar targetCal) { db(); Intent intent = new Intent(getBaseContext(), AlarmReceiver.class); intent.putExtra("text", two);

我正在开发一个可以设置警报的应用程序,但当我重新启动系统时,应用程序崩溃,并且在bootAlarm不再活动后警报无法重置。请帮我解决这个问题。我正在为此使用广播接收器

    public  void setAlarm(Calendar targetCal) {
    db();
    Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
      intent.putExtra("text", two);
       intent.putExtra("id", "" );
       PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1,  intent, 0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),pendingIntent);
    System.out.println("running setAlarm  ...");
   //       numBoth=numBoth+1;
  //        numCyn=numCyn+1;
 //     numEss=numEss+1;
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), 86400000, pendingIntent);

}    



public class AlarmReceiver extends BroadcastReceiver {

Intent intent;
String msg;
RingtoneManager ringtoneM;
//  private int[] SeqSwipeSound = new int[] { R.raw.swipe_1,
//          R.raw.right_color1, R.raw.wrong_color };
private int next=0;
SharedPreferences prefs;
String ringtone;
private SQLiteDatabase database;

private static final String DB_NAME = "essential";

private static final String TABLE_NAME = "tone";



private static final String TEXT = "name";

 @SuppressWarnings("static-access")
 @Override
 public void onReceive(final Context arg0, final Intent arg1) {
/* if(arg1.getAction().equals(arg1.ACTION_BOOT_COMPLETED)){


 }
 else {*/

// android.os.Debug.waitForDebugger();

 try {


      Toast.makeText(arg0, "Alarm received!", Toast.LENGTH_LONG).show();
      ExternalDbOpenHelper dbOpenHelperT = new ExternalDbOpenHelper(arg0, DB_NAME);
        database = dbOpenHelperT.openDataBase();
        database = dbOpenHelperT.getWritableDatabase();

     /* Intent i = new Intent(arg0,AlarmSettingsActivity.class);
      i.putExtra("alarm", true);

        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        arg0.startActivity(i);*/

      Bundle b = arg1.getExtras();

      long id = /*intent.getIntExtra("id",0);*/ 10;
      msg =  b.getString("text");;

      Intent notificationIntent = null;

      notificationIntent = new Intent(arg0, KarmicQuote.class);
      notificationIntent.putExtra("text", msg);
      notificationIntent.putExtra("id", "");
      notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);


      Notification noti = new Notification(R.drawable.app_icon_1, msg, System.currentTimeMillis());
      PendingIntent pi = PendingIntent.getActivity(arg0, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

      noti.setLatestEventInfo(arg0, "Essential Insights", msg, pi);
      // TODO check user preferences
      noti.defaults |= Notification.DEFAULT_VIBRATE;
      //noti.sound = Uri.parse(AlarmSettingsActivity.());
      //noti.defaults |= Notification.DEFAULT_SOUND;\

      noti.defaults |= Notification.DEFAULT_LIGHTS;
      noti.flags |= Notification.FLAG_AUTO_CANCEL;     


  //          AlarmSettingsActivity act= new AlarmSettingsActivity();
   //          act.db();
    //  AudioManager audioManager = (AudioManager)         arg0.getSystemService(Context.AUDIO_SERVICE);



      String name = null;
        try
        {
            Cursor c = null;
            c = database.rawQuery("select name from tone", null);
            c.moveToFirst();
            name = c.getString(c.getColumnIndex("name"));
            System.out.println("Get:"+name);

            c.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }



            Uri tone = Uri.parse(name);
            noti.sound = tone;
      NotificationManager nm = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
      nm.notify((int)id, noti);

} catch (Exception e) {
    // TODO: handle exception
}
 }
}

在清单文件中:

   <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
   <receiver
        android:name="com.essentialsguide.AlarmReciever"
        android:process=":remote" >
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />

            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.TIME_SET" />
        </intent-filter>
    </receiver> 

你的密码在哪里?如果我们看不到它,我们怎么能修复它?你在舱单上做了什么吗?