androidx.core.app.NotificationManagerCompat Java Examples

The following examples show how to use androidx.core.app.NotificationManagerCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From react-native-android-activity with MIT License 7 votes vote down vote up
/**
 * Demonstrates how to add a custom option to the dev menu.
 * https://stackoverflow.com/a/44882371/3968276
 * This only works from the debug build with dev options enabled.
 */
@Override
@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MainApplication application = (MainApplication) getApplication();
    ReactNativeHost reactNativeHost = application.getReactNativeHost();
    ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
    DevSupportManager devSupportManager = reactInstanceManager.getDevSupportManager();
    devSupportManager.addCustomDevOption("Custom dev option", new DevOptionHandler() {
        @Override
        public void onOptionSelected() {
            if (NotificationManagerCompat.from(MainActivity.this).areNotificationsEnabled()) {
                Toast.makeText(MainActivity.this, CUSTOM_DEV_OPTION_MESSAGE, Toast.LENGTH_LONG).show();
            } else {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).create();
                dialog.setTitle("Dev option");
                dialog.setMessage(CUSTOM_DEV_OPTION_MESSAGE);
                dialog.show();
            }
        }
    });
}
 
Example #2
Source File: ServiceSinkhole.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
private void showAutoStartNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_APPROVE, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify");
    builder.setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_autostart))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setOngoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        builder.setCategory(NotificationCompat.CATEGORY_STATUS)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_autostart));

    NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build());
}
 
Example #3
Source File: ReceiverPackageRemoved.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);

    String action = (intent == null ? null : intent.getAction());
    if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
        int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
        if (uid > 0) {
            DatabaseHelper dh = DatabaseHelper.getInstance(context);
            dh.clearLog(uid);
            dh.clearAccess(uid, false);

            NotificationManagerCompat.from(context).cancel(uid); // installed notification
            NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
        }
    }
}
 
Example #4
Source File: ServiceSinkhole.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
private void showUpdateNotification(String name, String url) {
    Intent download = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    PendingIntent pi = PendingIntent.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify");
    builder.setSmallIcon(R.drawable.ic_rocket_white)
            .setContentTitle(name)
            .setContentText(getString(R.string.msg_update))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setOngoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        builder.setCategory(NotificationCompat.CATEGORY_STATUS)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    NotificationManagerCompat.from(this).notify(NOTIFY_UPDATE, builder.build());
}
 
Example #5
Source File: MainSettingsActivity.java    From an2linuxclient with GNU General Public License v3.0 6 votes vote down vote up
private void displayNotificationHidingHelp() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, CHANNEL_ID_INFORMATION);

        notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE);
        notificationBuilder.setSmallIcon(R.drawable.an2linux_icon);
        notificationBuilder.setTicker(getString(R.string.main_enable_service_information_notification_title));
        notificationBuilder.setContentIntent(
                PendingIntent.getActivity(this, 0,
                        new Intent(this, MainSettingsActivity.class),
                        PendingIntent.FLAG_UPDATE_CURRENT)
        );
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setContentTitle(getString(R.string.main_enable_service_information_notification_title));
        notificationBuilder.setContentText(getString(R.string.main_enable_service_information_notification_text));
        notificationBuilder.setStyle(new NotificationCompat.BigTextStyle()
                .bigText(getString(R.string.main_enable_service_information_notification_text)));

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(NOTIFICATION_ID_HIDE_FOREGROUND_NOTIF, notificationBuilder.build());
    }
}
 
Example #6
Source File: ServiceSinkhole.java    From NetGuard with GNU General Public License v3.0 6 votes vote down vote up
private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify");
    builder.setSmallIcon(R.drawable.ic_error_white_24dp)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked))
            .setContentIntent(pi)
            .setColor(tv.data)
            .setOngoing(false)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        builder.setCategory(NotificationCompat.CATEGORY_STATUS)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_revoked));

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}
 
Example #7
Source File: NotificationsActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.prefs_notifications);

    mNotificationManagerCompat = NotificationManagerCompat.from(getActivity());

    final SwitchPreference mActionSwitchPref =
            (SwitchPreference) findPreference(getString(R.string.key_pref_action));
    final SwitchPreference mAvatarSwitchPref =
            (SwitchPreference) findPreference(getString(R.string.key_pref_avatar));
    Preference mPushNotificationPref =
            findPreference(getString(R.string.key_pref_push_notification));

    initInLineAction(mActionSwitchPref);
    initAvatar(mAvatarSwitchPref);
    initPushNotification(mPushNotificationPref);
}
 
Example #8
Source File: ChannelNotificationManager.java    From revolution-irc with GNU General Public License v3.0 6 votes vote down vote up
public void setOpened(Context context, boolean opened) {
    boolean updateSummary = false;
    synchronized (this) {
        mOpened = opened;
        if (mOpened) {
            mMessages.clear();

            synchronized (mShowingNotificationLock) {
                // cancel the notification
                if (mShowingNotification) {
                    NotificationManagerCompat.from(context).cancel(mNotificationId);
                    mShowingNotification = false;
                    updateSummary = true;
                }
            }
        }
    }
    if (updateSummary)
        NotificationManager.getInstance().updateSummaryNotification(context, null);
}
 
Example #9
Source File: Floating.java    From loco-answers with GNU General Public License v3.0 6 votes vote down vote up
private void notification() {
    Intent i = new Intent(this, Floating.class);
    i.setAction("stop");
    PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext(), "stop");
    mBuilder.setContentText("Trivia Hack most accurate answer")
            .setContentTitle("Tap to remove overlay screen")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setContentIntent(pi)
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setOngoing(true).setAutoCancel(true)
            .addAction(android.R.drawable.ic_menu_more, "Open Trivia Hack", pendingIntent);

   // NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(1234, mBuilder.build());
}
 
Example #10
Source File: ReceiverPackageRemoved.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    Log.i(TAG, "Received " + intent);
    Util.logExtras(intent);

    String action = (intent == null ? null : intent.getAction());
    if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
        int uid = intent.getIntExtra(Intent.EXTRA_UID, 0);
        if (uid > 0) {
            DatabaseHelper dh = DatabaseHelper.getInstance(context);
            dh.clearLog(uid);
            dh.clearAccess(uid, false);

            NotificationManagerCompat.from(context).cancel(uid); // installed notification
            NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification
        }
    }
}
 
Example #11
Source File: DownloadTask.java    From tracker-control-android with GNU General Public License v3.0 6 votes vote down vote up
private void showNotification(int progress) {
    Intent main = new Intent(context, ActivitySettings.class);
    PendingIntent pi = PendingIntent.getActivity(context, ServiceSinkhole.NOTIFY_DOWNLOAD, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notify");
    builder.setSmallIcon(R.drawable.ic_file_download_white_24dp)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.msg_downloading, url.toString()))
            .setContentIntent(pi)
            .setProgress(100, progress, false)
            .setColor(tv.data)
            .setOngoing(true)
            .setAutoCancel(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        builder.setCategory(NotificationCompat.CATEGORY_STATUS)
                .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    NotificationManagerCompat.from(context).notify(ServiceSinkhole.NOTIFY_DOWNLOAD, builder.build());
}
 
Example #12
Source File: VideoEncodingService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.FileUploadProgressChanged) {
        String fileName = (String) args[0];
        if (account == currentAccount && path != null && path.equals(fileName)) {
            Long loadedSize = (Long) args[1];
            Long totalSize = (Long) args[2];
            float progress = Math.min(1f, loadedSize / (float) totalSize);
            Boolean enc = (Boolean) args[3];
            currentProgress = (int) (progress * 100);
            builder.setProgress(100, currentProgress, currentProgress == 0);
            try {
                NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(4, builder.build());
            } catch (Throwable e) {
                FileLog.e(e);
            }
        }
    } else if (id == NotificationCenter.stopEncodingService) {
        String filepath = (String) args[0];
        account = (Integer) args[1];
        if (account == currentAccount && (filepath == null || filepath.equals(path))) {
            stopSelf();
        }
    }
}
 
Example #13
Source File: BigTextIntentService.java    From android-Notifications with Apache License 2.0 5 votes vote down vote up
/**
 * Handles action Dismiss in the provided background thread.
 */
private void handleActionDismiss() {
    Log.d(TAG, "handleActionDismiss()");

    NotificationManagerCompat notificationManagerCompat =
            NotificationManagerCompat.from(getApplicationContext());
    notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID);
}
 
Example #14
Source File: PPNotificationListenerService.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
public static boolean isNotificationListenerServiceEnabled(Context context) {
    /*
    ContentResolver contentResolver = context.getContentResolver();
    String enabledNotificationListeners = Settings.Secure.getString(contentResolver, "enabled_notification_listeners");
    String className = PPNotificationListenerService.class.getName();
    // check to see if the enabledNotificationListeners String contains our package name
    if ((enabledNotificationListeners == null) || (!enabledNotificationListeners.contains(className)))
    {
        // in this situation we know that the user has not granted the app the Notification access permission
        return false;
    }
    else
    {
        return true;
    }
    */

    Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages (context);
    //String className = PPNotificationListenerService.class.getName();
    String packageName = context.getPackageName();

    //if (packageNames != null) {
        synchronized (PPApplication.ppNotificationListenerService) {
            return packageNames.contains(packageName) && connected;
        }

        /*for (String pkgName : packageNames) {
            //if (className.contains(pkgName)) {
            if (packageName.equals(pkgName)) {
                return true;
            }
        }
        return false;*/
    //}
    //else
    //    return false;
}
 
Example #15
Source File: LocationSharingService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void onDestroy() {
    super.onDestroy();
    if (handler != null) {
        handler.removeCallbacks(runnable);
    }
    stopForeground(true);
    NotificationManagerCompat.from(ApplicationLoader.applicationContext).cancel(6);
    NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.liveLocationsChanged);
}
 
Example #16
Source File: MusicControlEventEmitter.java    From react-native-music-control with MIT License 5 votes vote down vote up
private void stopForegroundService() {
    NotificationManagerCompat.from(context).cancel(NOTIFICATION_ID);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        Intent myIntent =
                new Intent(context, MusicControlNotification.NotificationService.class);
        context.stopService(myIntent);
    }
}
 
Example #17
Source File: MobileCellsRegistrationService.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void showResultNotification() {
    String text = getString(R.string.mobile_cells_registration_pref_dlg_status_stopped);
    String newCount = getString(R.string.mobile_cells_registration_pref_dlg_status_new_cells_count);
    long iValue = DatabaseHandler.getInstance(getApplicationContext()).getNewMobileCellsCount();
    newCount = newCount + " " + iValue;
    text = text + "; " + newCount;
    if (android.os.Build.VERSION.SDK_INT < 24) {
        text = text+" ("+getString(R.string.ppp_app_name)+")";
    }

    PPApplication.createMobileCellsRegistrationNotificationChannel(this);
    NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this, PPApplication.MOBILE_CELLS_REGISTRATION_NOTIFICATION_CHANNEL)
            .setColor(ContextCompat.getColor(this, R.color.notificationDecorationColor))
            .setSmallIcon(R.drawable.ic_exclamation_notify) // notification icon
            .setContentTitle(getString(R.string.phone_profiles_pref_applicationEventMobileCellsRegistration_notification)) // title for notification
            .setContentText(text) // message for notification
            .setAutoCancel(true); // clear notification after click

    //mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
    //if (android.os.Build.VERSION.SDK_INT >= 21)
    //{
        mBuilder.setCategory(NotificationCompat.CATEGORY_RECOMMENDATION);
        mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    //}

    Notification notification = mBuilder.build();
    NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(this);
    try {
        mNotificationManager.notify(
                PPApplication.MOBILE_CELLS_REGISTRATION_RESULT_NOTIFICATION_TAG,
                PPApplication.MOBILE_CELLS_REGISTRATION_RESULT_NOTIFICATION_ID, notification);
    } catch (Exception e) {
        //Log.e("MobileCellsRegistrationService.showResultNotification", Log.getStackTraceString(e));
        PPApplication.recordException(e);
    }
}
 
Example #18
Source File: MainActivity.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
protected void onDestroy() {
    unregisterReceivers();
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    if (receivedStopService || !isServiceRunning(this, LbrynetService.class)) {
        notificationManager.cancelAll();
    }
    if (dbHelper != null) {
        dbHelper.close();
    }
    if (mediaSession != null && !isBackgroundPlaybackEnabled()) {
        mediaSession.release();
    }
    if (!isBackgroundPlaybackEnabled()) {
        playerNotificationManager.setPlayer(null);
        stopExoplayer();
        nowPlayingClaim = null;
        nowPlayingClaimUrl = null;
        nowPlayingClaimBitmap = null;
    }
    appStarted = false;

    if (!keepSdkBackground()) {
        sendBroadcast(new Intent(LbrynetService.ACTION_STOP_SERVICE));
    }

    super.onDestroy();
}
 
Example #19
Source File: DataWrapper.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
void deleteAllProfiles()
{
    synchronized (profileList) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        // remove notifications about profile parameters errors
        //noinspection ForLoopReplaceableByForEach
        for (Iterator<Profile> it = profileList.iterator(); it.hasNext(); ) {
            Profile profile = it.next();
            try {
                notificationManager.cancel(
                        PPApplication.DISPLAY_PREFERENCES_PROFILE_ERROR_NOTIFICATION_TAG+"_"+profile._id,
                        PPApplication.PROFILE_ID_NOTIFICATION_ID + (int) profile._id);
            } catch (Exception e) {
                PPApplication.recordException(e);
            }
        }
        profileList.clear();
    }
    synchronized (eventList) {
        fillEventList();
        // unlink profiles from events
        //noinspection ForLoopReplaceableByForEach
        for (Iterator<Event> it = eventList.iterator(); it.hasNext(); ) {
            Event event = it.next();
            event._fkProfileStart = 0;
            event._fkProfileEnd = Profile.PROFILE_NO_ACTIVATE;
            event._startWhenActivatedProfile = "";
        }
    }
    // unlink profiles from Background profile
    Editor editor = ApplicationPreferences.getEditor(context);
    editor.putString(ApplicationPreferences.PREF_APPLICATION_DEFAULT_PROFILE, String.valueOf(Profile.PROFILE_NO_ACTIVATE));
    editor.apply();
    ApplicationPreferences.applicationDefaultProfile(context);
}
 
Example #20
Source File: MainActivity.java    From wearable with Apache License 2.0 5 votes vote down vote up
/**
 * using the bigtext notification.
 */
void bigTextNoti() {
    //create the intent to launch the notiactivity, then the pentingintent.
    Intent viewIntent = new Intent(this, NotiActivity.class);
    viewIntent.putExtra("NotiID", "Notification ID is " + notificationID);

    PendingIntent viewPendingIntent =
        PendingIntent.getActivity(this, 0, viewIntent, 0);

    BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
    bigStyle.bigText("Big text style.\n"
        + "We should have more room to add text for the user to read, instead of a short message.");


    //Now create the notification.  We must use the NotificationCompat or it will not work on the wearable.
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this, id)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Simple Noti")
            .setContentText("This is a simple notification")
            .setContentIntent(viewPendingIntent)
            .setChannelId(id)
            .setStyle(bigStyle);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
        NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationID, notificationBuilder.build());
    notificationID++;
}
 
Example #21
Source File: NotificationHelper.java    From MaxLock with GNU General Public License v3.0 5 votes vote down vote up
public static void postIModNotification(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createNotificationChannels(context);
    }

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    if (!MLPreferences.getPrefsApps(context).getBoolean(Common.SHOW_RESET_RELOCK_TIMER_NOTIFICATION, false)) {
        nm.cancel(IMOD_NOTIFICATION_ID);
        return;
    }
    Intent notifyIntent = new Intent(context, ActionActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notifyIntent.putExtra(ActionsHelper.ACTION_EXTRA_KEY, ActionsHelper.ACTION_IMOD_RESET);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, IMOD_CHANNEL)
            .setContentTitle(context.getString(R.string.action_imod_reset))
            .setContentText("")
            .setSmallIcon(R.drawable.ic_apps_24dp)
            .setContentIntent(PendingIntent.getActivity(context.getApplicationContext(), 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .setOngoing(true)
            .setAutoCancel(true)
            .setShowWhen(false)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setCategory(NotificationCompat.CATEGORY_STATUS)
            .setColor(ContextCompat.getColor(context, R.color.accent));
    nm.notify(IMOD_NOTIFICATION_ID, builder.build());
}
 
Example #22
Source File: GeofencesScanner.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void showErrorNotification(int errorCode) {
    String nTitle = context.getString(R.string.event_preferences_location_google_api_connection_error_title);
    String nText = context.getString(R.string.event_preferences_location_google_api_connection_error_text);
    if (android.os.Build.VERSION.SDK_INT < 24) {
        nTitle = context.getString(R.string.ppp_app_name);
        nText = context.getString(R.string.event_preferences_location_google_api_connection_error_title)+": "+
                context.getString(R.string.event_preferences_location_google_api_connection_error_text);
    }
    PPApplication.createExclamationNotificationChannel(context);
    NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(context, PPApplication.EXCLAMATION_NOTIFICATION_CHANNEL)
            .setColor(ContextCompat.getColor(context, R.color.notificationDecorationColor))
            .setSmallIcon(R.drawable.ic_exclamation_notify) // notification icon
            .setContentTitle(nTitle) // title for notification
            .setContentText(nText) // message for notification
            .setAutoCancel(true); // clear notification after click
    mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(nText));
    Intent intent = new Intent(context, GeofenceScannerErrorActivity.class);
    intent.putExtra(DIALOG_ERROR, errorCode);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pi);
    mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
    //if (android.os.Build.VERSION.SDK_INT >= 21)
    //{
        mBuilder.setCategory(NotificationCompat.CATEGORY_RECOMMENDATION);
        mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    //}
    NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
    try {
        mNotificationManager.notify(
                PPApplication.GEOFENCE_SCANNER_ERROR_NOTIFICATION_TAG,
                PPApplication.GEOFENCE_SCANNER_ERROR_NOTIFICATION_ID, mBuilder.build());
    } catch (Exception e) {
        //Log.e("GeofencesScanner.showErrorNotification", Log.getStackTraceString(e));
        PPApplication.recordException(e);
    }
}
 
Example #23
Source File: ImportantInfoNotification.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
static private void showNotification(Context context,
                                     @SuppressWarnings("SameParameterValue") boolean firstInstallation,
                                     String title, String text) {
    String nTitle = title;
    String nText = text;
    if (android.os.Build.VERSION.SDK_INT < 24) {
        nTitle = context.getString(R.string.ppp_app_name);
        nText = title+": "+text;
    }
    PPApplication.createExclamationNotificationChannel(context);
    NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(context, PPApplication.EXCLAMATION_NOTIFICATION_CHANNEL)
            .setColor(ContextCompat.getColor(context, R.color.notificationDecorationColor))
            .setSmallIcon(R.drawable.ic_exclamation_notify) // notification icon
            .setContentTitle(nTitle) // title for notification
            .setContentText(nText) // message for notification
            .setAutoCancel(true); // clear notification after click
    mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(nText));
    Intent intent = new Intent(context, ImportantInfoActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(EXTRA_FIRST_INSTALLATION, firstInstallation);
    PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pi);
    mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
    //if (android.os.Build.VERSION.SDK_INT >= 21)
    //{
        mBuilder.setCategory(NotificationCompat.CATEGORY_RECOMMENDATION);
        mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    //}
    NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
    try {
        mNotificationManager.notify(
                PPApplication.IMPORTANT_INFO_NOTIFICATION_TAG,
                PPApplication.IMPORTANT_INFO_NOTIFICATION_ID, mBuilder.build());
    } catch (Exception e) {
        //Log.e("ImportantInfoNotification.showNotification", Log.getStackTraceString(e));
        PPApplication.recordException(e);
    }
}
 
Example #24
Source File: SoundService.java    From volume_control_android with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    notificationManagerCompat = NotificationManagerCompat.from(this);
    soundProfileStorage = SoundApplication.getSoundProfileStorage(this);
    control = SoundApplication.getVolumeControl(this);
}
 
Example #25
Source File: LocationSharingService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void updateNotification(boolean post) {
    if (builder == null) {
        return;
    }
    String param;
    ArrayList<LocationController.SharingLocationInfo> infos = getInfos();
    if (infos.size() == 1) {
        LocationController.SharingLocationInfo info = infos.get(0);
        int lower_id = (int) info.messageObject.getDialogId();
        int currentAccount = info.messageObject.currentAccount;
        if (lower_id > 0) {
            TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
            param = UserObject.getFirstName(user);
        } else {
            TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
            if (chat != null) {
                param = chat.title;
            } else {
                param = "";
            }
        }
    } else {
        param = LocaleController.formatPluralString("Chats", infos.size());
    }
    String str = String.format(LocaleController.getString("AttachLiveLocationIsSharing", R.string.AttachLiveLocationIsSharing), LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation), param);
    builder.setTicker(str);
    builder.setContentText(str);
    if (post) {
        NotificationManagerCompat.from(ApplicationLoader.applicationContext).notify(6, builder.build());
    }
}
 
Example #26
Source File: MainActivity.java    From wearable with Apache License 2.0 5 votes vote down vote up
/**
 * Both the phone and wear will have a notification.  This adds the button so it only shows
 * on the wearable device and not the phone notification.
 */
void onlywearableNoti() {
    //create the intent to launch the notiactivity, then the pentingintent.
    Intent viewIntent = new Intent(this, NotiActivity.class);
    viewIntent.putExtra("NotiID", "Notification ID is " + notificationID);

    PendingIntent viewPendingIntent =
        PendingIntent.getActivity(this, 0, viewIntent, 0);

    // we are going to add an intent to open the camera here.
    Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    PendingIntent cameraPendingIntent =
        PendingIntent.getActivity(this, 0, cameraIntent, 0);

    // Create the action
    NotificationCompat.Action action =
        new NotificationCompat.Action.Builder(R.drawable.ic_action_time,
            "Open Camera", cameraPendingIntent)
            .build();


    //Now create the notification.  We must use the NotificationCompat or it will not work on the wearable.
    NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this, id)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Button on Wear Only")
            .setContentText("tap to open message")
            .setContentIntent(viewPendingIntent)
            .setChannelId(id)
            .extend(new WearableExtender().addAction(action));

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
        NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(notificationID, notificationBuilder.build());
    notificationID++;
}
 
Example #27
Source File: NotificationCenter.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private String getNotificationChannelGroup(NotificationManagerCompat notificationManager) {
    if (notificationChannelsSupported() && notificationManager.getNotificationChannelGroup(CH_GRP_MSG) == null) {
        NotificationChannelGroup chGrp = new NotificationChannelGroup(CH_GRP_MSG, context.getString(R.string.pref_chats));
        notificationManager.createNotificationChannelGroup(chGrp);
    }
    return CH_GRP_MSG;
}
 
Example #28
Source File: BigTextIntentService.java    From user-interface-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Handles action Snooze in the provided background thread.
 */
private void handleActionSnooze() {
    Log.d(TAG, "handleActionSnooze()");

    // You could use NotificationManager.getActiveNotifications() if you are targeting SDK 23
    // and above, but we are targeting devices with lower SDK API numbers, so we saved the
    // builder globally and get the notification back to recreate it later.

    NotificationCompat.Builder notificationCompatBuilder =
            GlobalNotificationBuilder.getNotificationCompatBuilderInstance();

    // Recreate builder from persistent state if app process is killed
    if (notificationCompatBuilder == null) {
        // Note: New builder set globally in the method
        notificationCompatBuilder = recreateBuilderWithBigTextStyle();
    }

    Notification notification;
    notification = notificationCompatBuilder.build();


    if (notification != null) {
        NotificationManagerCompat notificationManagerCompat =
                NotificationManagerCompat.from(getApplicationContext());

        notificationManagerCompat.cancel(MainActivity.NOTIFICATION_ID);

        try {
            Thread.sleep(SNOOZE_TIME);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
        notificationManagerCompat.notify(MainActivity.NOTIFICATION_ID, notification);
    }

}
 
Example #29
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private void showBolusProgress(int progresspercent, String progresstatus) {
    Intent cancelIntent = new Intent(this, ListenerService.class);
    cancelIntent.setAction(ACTION_CANCELBOLUS);
    PendingIntent cancelPendingIntent = PendingIntent.getService(this, 0, cancelIntent, 0);

    long[] vibratePattern;
    boolean vibreate = PreferenceManager
            .getDefaultSharedPreferences(this).getBoolean("vibrateOnBolus", true);
    if(vibreate){
        vibratePattern = new long[]{0, 50, 1000};
    } else {
        vibratePattern = new long[]{0, 1, 1000};
    }

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_icon)
                    .setContentTitle("Bolus Progress")
                    .setContentText(progresspercent + "% - " + progresstatus)
                    .setContentIntent(cancelPendingIntent)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setVibrate(vibratePattern)
                    .addAction(R.drawable.ic_cancel, "CANCEL BOLUS", cancelPendingIntent);

    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    if(confirmThread != null){
        confirmThread.invalidate();
    }
    notificationManager.notify(BOLUS_PROGRESS_NOTIF_ID, notificationBuilder.build());
    notificationManager.cancel(CONFIRM_NOTIF_ID); // multiple watch setup


    if (progresspercent == 100){
        scheduleDismissBolusprogress(5);
    }
}
 
Example #30
Source File: NotificationHelper.java    From NekoSMS with GNU General Public License v3.0 5 votes vote down vote up
public static void displayNotification(Context context, Uri messageUri) {
    if (!areNotificationsEnabled(context)) {
        BlockedSmsLoader.get().setSeenStatus(context, messageUri, true);
        return;
    }

    SmsMessageData messageData = BlockedSmsLoader.get().query(context, messageUri);
    Notification notification = buildNotificationSingle(context, messageData);
    applyNotificationStyle(context, notification);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(uriToNotificationId(messageUri), notification);
}