-
How to Use Class For Sending Notification In Android?
over 5 years ago
-
over 4 years ago
You can use and NotificationCompact builder to create notification for your android application. If you want to show Firebase push notification you can follow this post: https://trinitytuts.com/firebase-push-notification-android/NotificationCompat.Builder builder = null; final int NOTIFY_ID = 0; // ID of notification String id = "mychannel"; // default_channel_id PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (notifManager == null) { notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel mChannel = notifManager.getNotificationChannel(id); if (mChannel == null) { mChannel = new NotificationChannel(id, title, importance); mChannel.enableVibration(true); mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); notifManager.createNotificationChannel(mChannel); } builder = new NotificationCompat.Builder(context, id) .setContentTitle(title) .setContentText(desciption) .setContentIntent(pendingIntent) .setSound(defaultSoundUri) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.mipmap.ic_launcher) .setPriority(NotificationCompat.PRIORITY_DEFAULT); } else { builder = new NotificationCompat.Builder(context, id); intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); builder.setContentTitle(title) .setContentText(desciption) // required .setSmallIcon(android.R.drawable.ic_popup_reminder) // required .setDefaults(Notification.DEFAULT_ALL) .setAutoCancel(true) .setContentIntent(pendingIntent) .setTicker("Accept your request") .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}) .setPriority(Notification.PRIORITY_HIGH); } Notification notification = builder.build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFY_ID, notification);
-
-
over 5 years ago
public class MainActivity extends ActionBarActivity { EditText ed1,ed2,ed3; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ed1=(EditText)findViewById(R.id.editText); ed2=(EditText)findViewById(R.id.editText2); ed3=(EditText)findViewById(R.id.editText3); Button b1=(Button)findViewById(R.id.button); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String tittle=ed1.getText().toString().trim(); String subject=ed2.getText().toString().trim(); String body=ed3.getText().toString().trim(); NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); Notification notify=new Notification.Builder (getApplicationContext()).setContentTitle(tittle).setContentText(body). setContentTitle(subject).setSmallIcon(R.drawable.abc).build(); notify.flags |= Notification.FLAG_AUTO_CANCEL; notif.notify(0, notify); } }); } }
Learn more at: https://www.tutorialspoint.com/android/android_push_notification.htm -
2 Answer(s)