android foreground push notification
Java
// When app is in foreground, notifications are not generated themselves. You need to write some additional code. When message is received onMessageReceived() method is called where you can generate the notification. Here is the code:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = "Default";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody()).setAutoCancel(true).setContentIntent(pendingIntent);;
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
manager.notify(0, builder.build());
}
}
Also in Java:
- Title
- java read file text
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- print out value java
- Category
- Java
- Title
- filesaver javafx
- Category
- Java
- Title
- creating file in specific location in java application
- Category
- Java
- Title
- java file class
- Category
- Java
- Title
- declare bufferedreader java
- Category
- Java
- Title
- how to add multiple filter condition in Java stream filter chain
- Category
- Java
- Title
- arraylist to int array java
- Category
- Java
- Title
- scan a string using scanner class in java
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- java getter
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- print values of bst java
- Category
- Java
- Title
- convert char to string java
- Category
- Java
- Title
- convert string to mayus java
- Category
- Java
- Title
- how to separate no and text in java
- Category
- Java
- Title
- java == vs equals
- Category
- Java
- Title
- reverse array in java
- Category
- Java
- Title
- java question mark operator
- Category
- Java
- Title
- spigot despawn entity
- Category
- Java
- Title
- string length in java
- Category
- Java
- Title
- how to declare a linked list in java
- Category
- Java
- Title
- java script how to not allow soace
- Category
- Java
- Title
- java list as parameter
- Category
- Java
- Title
- java queue
- Category
- Java
- Title
- count number of matches in two strings java
- Category
- Java
- Title
- how to send http post create request using curl command
- Category
- Java
- Title
- split with scquere braket in java
- Category
- Java
- Title
- java 8 stream group by example
- Category
- Java
- Title
- read int from keyboard java
- Category
- Java
- Title
- how to count the number of occurrences of an element in a arraylist in java
- Category
- Java
- Title
- java xml element get attribute value
- Category
- Java
- Title
- get raondom from array java
- Category
- Java
- Title
- java obtain list string from list object
- Category
- Java
- Title
- java sql question mark
- Category
- Java
- Title
- how to crate a list in java script
- Category
- Java
- Title
- java hello world
- Category
- Java
- Title
- regex get string between quotes java
- Category
- Java
- Title
- java string to double
- Category
- Java
- Title
- java swing button on click
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- import
- Category
- Java
- Title
- linux command to see all the java version installed
- Category
- Java
- Title
- how to make a variable unchangeable in java
- Category
- Java
- Title
- binary string to int java
- Category
- Java
- Title
- how to get the screen dimensions in java
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- java add a list to a list
- Category
- Java
- Title
- add view to relativelayout programmatically
- Category
- Java
- Title
- java array copy
- Category
- Java
- Title
- converter int array para string java
- Category
- Java
- Title
- how to create a random number in java
- Category
- Java
- Title
- filter in list by time java
- Category
- Java
- Title
- java code to get all leaf nodes of a xml file
- Category
- Java
- Title
- arraylist to array java
- Category
- Java
- Title
- multiplication program java
- Category
- Java
- Title
- java manacher's algorithm
- Category
- Java
- Title
- Java for loop
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- how to calculate min, max and average and write the output into into a text file in java
- Category
- Java
- Title
- java string contains char
- Category
- Java
- Title
- charat(0).touppercase() java
- Category
- Java
- Title
- java cast duration to long
- Category
- Java
- Title
- java random integer
- Category
- Java
- Title
- java script dynamic varibale creation
- Category
- Java
- Title
- java hashmap example
- Category
- Java
- Title
- print hashtable in java
- Category
- Java
- Title
- java initialize float to zero
- Category
- Java
- Title
- java string util if empty default
- Category
- Java
- Title
- check if map contains key java
- Category
- Java
- Title
- vector in java
- Category
- Java
- Title
- python vs java
- Category
- Java
- Title
- 2d array length in java
- Category
- Java
- Title
- how to format a double in java to 2 decimal places
- Category
- Java
- Title
- java make arraylist
- Category
- Java
- Title
- java create circle
- Category
- Java
- Title
- how to create an abstract method in java
- Category
- Java
- Title
- time conversion solution
- Category
- Java
- Title
- java console text color
- Category
- Java
- Title
- bigdecimal divide java
- Category
- Java
- Title
- boolean checkbox swing
- Category
- Java
- Title
- java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.security.MessageDigest$Delegate
- Category
- Java
- Title
- android dynamically create layer-list with item and shape site:stackoverflow.com
- Category
- Java
- Title
- how to create array of linkedlist in java
- Category
- Java
- Title
- not equal to java
- Category
- Java
- Title
- do statement java
- Category
- Java
- Title
- how to make a new arraylist java
- Category
- Java
- Title
- guess the number java
- Category
- Java
- Title
- how to make a pre set list java
- Category
- Java
- Title
- recursion in java
- Category
- Java
- Title
- switch java 11
- Category
- Java
- Title
- run spring boot application command line
- Category
- Java
- Title
- print in java
- Category
- Java
- Title
- iterator loop java
- Category
- Java
- Title
- Android recycleView
- Category
- Java
- Title
- java how to read a text file
- Category
- Java
- Title
- how to iterate hashset in java 8
- Category
- Java
- Title
- rewrite file java
- Category
- Java
- Title
- how to install java 8 on terminal os
- Category
- Java