|
@@ -8,6 +8,7 @@ import android.app.PendingIntent;
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
|
|
+import android.os.Build;
|
|
|
import android.os.SystemClock;
|
|
import android.os.SystemClock;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
@@ -31,8 +32,12 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|
|
Log.i("set alarm status:","收到推送设置");
|
|
Log.i("set alarm status:","收到推送设置");
|
|
|
|
|
|
|
|
Intent intent2 = new Intent(context, MainActivity.class);
|
|
Intent intent2 = new Intent(context, MainActivity.class);
|
|
|
|
|
+ int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
|
|
|
+ if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
|
|
|
|
|
+ flags = PendingIntent.FLAG_IMMUTABLE;
|
|
|
|
|
+ }
|
|
|
count++;
|
|
count++;
|
|
|
- PendingIntent pendingIntent = PendingIntent.getActivity(context, count, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, count, intent2, flags);
|
|
|
// 创建通知构建器
|
|
// 创建通知构建器
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelID)
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelID)
|
|
|
.setSmallIcon(R.drawable.ic_stat_onesignal_default)
|
|
.setSmallIcon(R.drawable.ic_stat_onesignal_default)
|
|
@@ -52,14 +57,14 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|
|
openAppIntent.setAction("START_TIMER_NOW");
|
|
openAppIntent.setAction("START_TIMER_NOW");
|
|
|
openAppIntent.putExtra("id",strId);
|
|
openAppIntent.putExtra("id",strId);
|
|
|
openAppIntent.putExtra("category_id",categoryId);
|
|
openAppIntent.putExtra("category_id",categoryId);
|
|
|
- PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, flags);
|
|
|
builder.addAction(0, "Start timer now with 1-tap", openAppPendingIntent);
|
|
builder.addAction(0, "Start timer now with 1-tap", openAppPendingIntent);
|
|
|
|
|
|
|
|
Intent openAppIntent2 = new Intent(context, MainActivity.class);
|
|
Intent openAppIntent2 = new Intent(context, MainActivity.class);
|
|
|
openAppIntent2.setAction("PICK_EARLIER_START");
|
|
openAppIntent2.setAction("PICK_EARLIER_START");
|
|
|
openAppIntent2.putExtra("id",strId);
|
|
openAppIntent2.putExtra("id",strId);
|
|
|
openAppIntent2.putExtra("category_id",categoryId);
|
|
openAppIntent2.putExtra("category_id",categoryId);
|
|
|
- PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent2, flags);
|
|
|
builder.addAction(0, "Pick an earlier start", openAppPendingIntent2);
|
|
builder.addAction(0, "Pick an earlier start", openAppPendingIntent2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -71,14 +76,14 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|
|
openAppIntent.setAction("END_TIMER_NOW");
|
|
openAppIntent.setAction("END_TIMER_NOW");
|
|
|
openAppIntent.putExtra("id",strId);
|
|
openAppIntent.putExtra("id",strId);
|
|
|
openAppIntent.putExtra("category_id",categoryId);
|
|
openAppIntent.putExtra("category_id",categoryId);
|
|
|
- PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, flags);
|
|
|
builder.addAction(0, "End timer now with 1-tap", openAppPendingIntent);
|
|
builder.addAction(0, "End timer now with 1-tap", openAppPendingIntent);
|
|
|
|
|
|
|
|
Intent openAppIntent2 = new Intent(context, MainActivity.class);
|
|
Intent openAppIntent2 = new Intent(context, MainActivity.class);
|
|
|
openAppIntent2.setAction("PICK_EARLIER_END");
|
|
openAppIntent2.setAction("PICK_EARLIER_END");
|
|
|
openAppIntent2.putExtra("id",strId);
|
|
openAppIntent2.putExtra("id",strId);
|
|
|
openAppIntent2.putExtra("category_id",categoryId);
|
|
openAppIntent2.putExtra("category_id",categoryId);
|
|
|
- PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent2, flags);
|
|
|
builder.addAction(0, "Pick an earlier end", openAppPendingIntent2);
|
|
builder.addAction(0, "Pick an earlier end", openAppPendingIntent2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -105,8 +110,12 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|
|
intent.putExtra("id",strId);
|
|
intent.putExtra("id",strId);
|
|
|
intent.putExtra("mode",mode);
|
|
intent.putExtra("mode",mode);
|
|
|
|
|
|
|
|
|
|
+ int flags = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
|
|
|
+ if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
|
|
|
|
|
+ flags = PendingIntent.FLAG_IMMUTABLE;
|
|
|
|
|
+ }
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(
|
|
|
- context, 0, intent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
+ context, 0, intent, flags);
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+24*3600*1000,pendingIntent);
|
|
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+24*3600*1000,pendingIntent);
|