diff --git a/Notemaster/app/src/main/AndroidManifest.xml b/Notemaster/app/src/main/AndroidManifest.xml index a9b267c..6c7a375 100644 --- a/Notemaster/app/src/main/AndroidManifest.xml +++ b/Notemaster/app/src/main/AndroidManifest.xml @@ -11,6 +11,8 @@ + + { // pendingIntent); // mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); // } -private void showNotification(int tickerId, String content) { - PendingIntent pendingIntent; - if (tickerId != R.string.ticker_success) { - pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, - NotesPreferenceActivity.class), PendingIntent.FLAG_IMMUTABLE); - } else { - pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, - NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE); - } - Notification.Builder builder = new Notification.Builder(mContext) - .setAutoCancel(true) - .setContentTitle(mContext.getString(R.string.app_name)) - .setContentText(content) - .setContentIntent(pendingIntent) - .setWhen(System.currentTimeMillis()) - .setOngoing(true); - Notification notification=builder.getNotification(); - mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); -} + private void showNotification(int tickerId, String content) { + PendingIntent pendingIntent; + if (tickerId != R.string.ticker_success) { + pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, + NotesPreferenceActivity.class), PendingIntent.FLAG_IMMUTABLE); + } else { + pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, + NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE); + } + Notification.Builder builder = new Notification.Builder(mContext) + .setAutoCancel(true) + .setContentTitle(mContext.getString(R.string.app_name)) + .setContentText(content) + .setContentIntent(pendingIntent) + .setWhen(System.currentTimeMillis()) + .setOngoing(true); + Notification notification=builder.getNotification(); + mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); + } @Override protected Integer doInBackground(Void... unused) { publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity diff --git a/Notemaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/Notemaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java index f221202..ab9851f 100644 --- a/Notemaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java +++ b/Notemaster/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java @@ -53,10 +53,14 @@ public class AlarmInitReceiver extends BroadcastReceiver { long alertDate = c.getLong(COLUMN_ALERTED_DATE); Intent sender = new Intent(context, AlarmReceiver.class); sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID))); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, PendingIntent.FLAG_IMMUTABLE); AlarmManager alermManager = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); - alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { + alermManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); + } else { + alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent); + } } while (c.moveToNext()); } c.close(); diff --git a/Notemaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/Notemaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 96a9ff8..bf1521c 100644 --- a/Notemaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/Notemaster/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -159,6 +159,14 @@ public class NoteEditActivity extends Activity implements OnClickListener, return; } initResources(); + + // 检查并请求闹钟和通知权限 + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) { + requestPermissions(new String[]{android.Manifest.permission.POST_NOTIFICATIONS}, 1); + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { + requestPermissions(new String[]{android.Manifest.permission.SCHEDULE_EXACT_ALARM}, 2); + } } /** @@ -623,13 +631,17 @@ public class NoteEditActivity extends Activity implements OnClickListener, if (mWorkingNote.getNoteId() > 0) { Intent intent = new Intent(this, AlarmReceiver.class); intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId())); - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_IMMUTABLE); AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE)); showAlertHeader(); if(!set) { alarmManager.cancel(pendingIntent); } else { - alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { + alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, date, pendingIntent); + } else { + alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent); + } } } else { /** diff --git a/Notemaster/app/src/main/res/drawable-hdpi/list_background.png b/Notemaster/app/src/main/res/drawable-hdpi/list_background.png index c141458..aee5751 100644 Binary files a/Notemaster/app/src/main/res/drawable-hdpi/list_background.png and b/Notemaster/app/src/main/res/drawable-hdpi/list_background.png differ diff --git a/Notemaster/app/src/main/res/values/styles.xml b/Notemaster/app/src/main/res/values/styles.xml index c1eddb2..2276951 100644 --- a/Notemaster/app/src/main/res/values/styles.xml +++ b/Notemaster/app/src/main/res/values/styles.xml @@ -62,6 +62,10 @@ @style/NoteActionBarStyle + + + +