|
@@ -16,6 +16,7 @@ import androidx.core.app.NotificationManagerCompat;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
public class AlarmReceiver extends BroadcastReceiver {
|
|
public class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
+ int count = 0;
|
|
|
@Override
|
|
@Override
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
String title = intent.getStringExtra("title");
|
|
String title = intent.getStringExtra("title");
|
|
@@ -23,15 +24,17 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|
|
String channel = intent.getStringExtra("channel");
|
|
String channel = intent.getStringExtra("channel");
|
|
|
String categoryId = intent.getStringExtra("categoryId");
|
|
String categoryId = intent.getStringExtra("categoryId");
|
|
|
String strId = intent.getStringExtra("id");
|
|
String strId = intent.getStringExtra("id");
|
|
|
|
|
+ int msg_id = intent.getIntExtra("msg_id",0);
|
|
|
|
|
|
|
|
Intent intent2 = new Intent(context, MainActivity.class);
|
|
Intent intent2 = new Intent(context, MainActivity.class);
|
|
|
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_IMMUTABLE);
|
|
|
|
|
|
|
+ count++;
|
|
|
|
|
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, count, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
// 创建通知构建器
|
|
// 创建通知构建器
|
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, strId)
|
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, strId)
|
|
|
.setSmallIcon(R.drawable.ic_stat_onesignal_default)
|
|
.setSmallIcon(R.drawable.ic_stat_onesignal_default)
|
|
|
.setContentTitle(title)
|
|
.setContentTitle(title)
|
|
|
.setContentText(message)
|
|
.setContentText(message)
|
|
|
- .setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
|
|
|
|
|
+ .setPriority(NotificationCompat.PRIORITY_HIGH)
|
|
|
.setContentIntent(pendingIntent);
|
|
.setContentIntent(pendingIntent);
|
|
|
|
|
|
|
|
assert categoryId != null;
|
|
assert categoryId != null;
|
|
@@ -42,14 +45,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_IMMUTABLE);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
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_IMMUTABLE);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
builder.addAction(0, "Pick an earlier start", openAppPendingIntent2);
|
|
builder.addAction(0, "Pick an earlier start", openAppPendingIntent2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -60,31 +63,22 @@ 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_IMMUTABLE);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
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_IMMUTABLE);
|
|
|
|
|
|
|
+ PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
builder.addAction(0, "Pick an earlier end", openAppPendingIntent2);
|
|
builder.addAction(0, "Pick an earlier end", openAppPendingIntent2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// // 添加自定义按钮
|
|
|
|
|
-// Intent openAppIntent = new Intent(context, MainActivity.class);
|
|
|
|
|
-// openAppIntent.setAction("OPEN_APP");
|
|
|
|
|
-// PendingIntent openAppPendingIntent = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_IMMUTABLE);
|
|
|
|
|
-// builder.addAction(0, "Start timer now with 1-tap", openAppPendingIntent);
|
|
|
|
|
-//
|
|
|
|
|
-// Intent openAppIntent2 = new Intent(context, MainActivity.class);
|
|
|
|
|
-// openAppIntent2.setAction("OPEN_APP");
|
|
|
|
|
-// PendingIntent openAppPendingIntent2 = PendingIntent.getActivity(context, 0, openAppIntent, PendingIntent.FLAG_IMMUTABLE);
|
|
|
|
|
-// builder.addAction(0, "Pick an earlier start", openAppPendingIntent2);
|
|
|
|
|
|
|
|
|
|
// 显示通知
|
|
// 显示通知
|
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
|
|
- notificationManager.notify(0, builder.build());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ notificationManager.notify(msg_id, builder.build());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
|
// @Override
|