Skip to content

Instantly share code, notes, and snippets.

View einkaaf's full-sized avatar
🎃
Focusing

Erfan Kazemi M. einkaaf

🎃
Focusing
View GitHub Profile
@kristopherjohnson
kristopherjohnson / showForegroundNotification.java
Last active October 16, 2024 11:33
Shows a foreground notification for an Android service. Tapping the notification will display the app as if it was tapped in application launcher
private static final int NOTIFICATION_ID = 1;
private void showForegroundNotification(String contentText) {
// Create intent that will bring our app to the front, as if it was tapped in the app
// launcher
Intent showTaskIntent = new Intent(getApplicationContext(), MyMainActivity.class);
showTaskIntent.setAction(Intent.ACTION_MAIN);
showTaskIntent.addCategory(Intent.CATEGORY_LAUNCHER);
showTaskIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);