I tried and saw that the notice should come to me at the specified time and it did not come to me .setContentTitle(title.get("Title of notification")) .setContentText(subText.get("Sub text of notification")) title subtext error
Notice should come only to me at the specified time I should be notified only at the time I place it
public class MainActivity extends AppCompatActivity {
@RequiresApi(Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationCheckPoint();
}
@RequiresApi(Build.VERSION_CODES.N)
private void NotificationCheckPoint() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 19);
calendar.set(Calendar.MINUTE, 53);
calendar.set(Calendar.SECOND, 0);
Intent MyIntent = new Intent(getApplicationContext(), BroadastNotification.class);
PendingIntent MyPendIntent = PendingIntent.getBroadcast(getApplicationContext(), 100,
MyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager MyAlarm = (AlarmManager) getSystemService(ALARM_SERVICE);
MyAlarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, MyPendIntent);
}
This BroadcastNotication
public class BroadcastNotification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
sendNotification(context);
}
private void sendNotification(Context context) {
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "101";
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
@SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Notification", NotificationManager.IMPORTANCE_MAX);
//Configure Notification Channel
notificationChannel.setDescription("Game Notifications");
notificationChannel.enableLights(true);
notificationChannel.setVibrationPattern(new long[]{200});
notificationChannel.enableVibration(false);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle(title.get("Title of notification"))
.setContentText(String.substring("Sub text of notification"))
.setAutoCancel(true)
.setSound(defaultSound)
.setContentIntent(pendingIntent)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_MAX);
notificationManager.notify(1, notificationBuilder.build());
}
from I tried and saw that the notification should come to me at the specified time?

No comments:
Post a Comment