Skip to content

Instantly share code, notes, and snippets.

View Galarzaa90's full-sized avatar

Allan Galarza Galarzaa90

View GitHub Profile
@Galarzaa90
Galarzaa90 / showForegroundNotification.java
Last active March 2, 2023 13:12 — forked from kristopherjohnson/showForegroundNotification.java
Shows a foreground notification for an Android service. Tapping the notification will display the app as if it was tapped in application launcher
//In a service
public void showNotification(){
Intent notificationIntent = new Intent(getApplicationContext(),MainActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(),
0,