Java Code Examples for android.support.v4.app.NotificationManagerCompat#from()

The following examples show how to use android.support.v4.app.NotificationManagerCompat#from() . 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: CustomTransitionsIntentService.java    From JCVD with MIT License 6 votes vote down vote up
private void sendNotification(String text) {
    createNotificationChannel();
    Notification notif = new NotificationCompat.Builder(this, TEST_CHANNEL)
            .setSmallIcon(R.drawable.default_notif)
            .setContentTitle("Custom")
            .setContentText(text)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setCategory(NotificationCompat.CATEGORY_EVENT)
            .build();


    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Issue the notification
    notificationManager.notify(0, notif);
}
 
Example 2
Source File: AutoCleanService.java    From share-to-delete with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
    context = this;
    notificationManagerCompat = NotificationManagerCompat.from(context);
    preferences = PreferenceManager.getDefaultSharedPreferences(context);
    if (!preferences.getBoolean(AutoCleanSettingsActivity.PREF_AUTO_CLEAN, false)) return false;
    sendNotification();
    cleanUp();
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Log.v(MyUtil.PACKAGE_NAME, getString(R.string.toast_auto_clean, deletedFileCount));
            Toast.makeText(
                    context,
                    getString(R.string.toast_auto_clean, deletedFileCount),
                    Toast.LENGTH_SHORT
            ).show();
            notificationManagerCompat.cancel(NOTIFICATION_JOB_ID);
        }
    }, 3000);
    return true;
}
 
Example 3
Source File: MyActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing11_17(Context context) {
  NotificationManagerCompat notificationManager =
    NotificationManagerCompat.from(this);

  // Listing 11-17: Creating and posting a Notification
  final int NEW_MESSAGE_ID = 0;
  createMessagesNotificationChannel(context);

  NotificationCompat.Builder builder = new NotificationCompat.Builder(
    context, MESSAGES_CHANNEL);

  // These would be dynamic in a real app
  String title = "Reto Meier";
  String text = "Interested in a new book recommendation?" +
                  " I have one you should check out!";

  builder.setSmallIcon(R.drawable.ic_notification)
    .setContentTitle(title)
    .setContentText(text);

  notificationManager.notify(NEW_MESSAGE_ID, builder.build());
}
 
Example 4
Source File: PushTemplateHelper.java    From Android-SDK with MIT License 5 votes vote down vote up
static void showNotification( final Context context, final Notification notification, final String tag, final int notificationId )
{
  final NotificationManagerCompat notificationManager = NotificationManagerCompat.from( context.getApplicationContext() );
  Handler handler = new Handler( Looper.getMainLooper() );
  handler.post( new Runnable()
  {
    @Override
    public void run()
    {
      notificationManager.notify( tag, notificationId, notification );
    }
  } );
}
 
Example 5
Source File: DownloadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void updateNotification(FileItem downloadItem, String content, String[] bigTextArray) {
    StringBuilder bigText = new StringBuilder();
    for (int i = 0; i < bigTextArray.length; i++) {
        bigText.append(bigTextArray[i]);
        if (i < 4) {
            bigText.append("\n");
        }
    }

    Intent foregroundIntent = new Intent(this, DownloadService.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, foregroundIntent, 0);

    Intent cancelIntent = new Intent(this, DownloadCancelAction.class);
    PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_download)
            .setContentTitle(downloadItem.getName())
            .setContentText(content)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString()))
            .addAction(R.drawable.ic_cancel_download, getString(R.string.cancel), cancelPendingIntent);

    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
    notificationManagerCompat.notify(PERSISTENT_NOTIFICATION_ID, builder.build());
}
 
Example 6
Source File: UploadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showUploadFinishedNotification(int notificationID, String contentText) {
    createSummaryNotificationForFinished();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_upload_done)
            .setContentTitle(getString(R.string.upload_complete))
            .setContentText(contentText)
            .setGroup(UPLOAD_FINISHED_GROUP)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationID, builder.build());
}
 
Example 7
Source File: PlumbleReconnectNotification.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
public void hide() {
    try {
        mContext.unregisterReceiver(mNotificationReceiver);
    } catch (IllegalArgumentException e) {
        // Thrown if receiver is not registered.
        e.printStackTrace();
    }
    NotificationManagerCompat nmc = NotificationManagerCompat.from(mContext);
    nmc.cancel(NOTIFICATION_ID);
}
 
Example 8
Source File: DeleteService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void createSummaryNotificationForFailed() {
    Notification summaryNotification =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setContentTitle(getString(R.string.operation_failed))
                    //set content text to support devices running API level < 24
                    .setContentText(getString(R.string.operation_failed))
                    .setSmallIcon(android.R.drawable.stat_sys_warning)
                    .setGroup(OPERATION_FAILED_GROUP)
                    .setGroupSummary(true)
                    .setAutoCancel(true)
                    .build();

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(OPERATION_FAILED_NOTIFICATION_ID, summaryNotification);
}
 
Example 9
Source File: DownloadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showDownloadFailedNotification(int notificationId, String contentText) {
    createSummaryNotificationForFailed();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_warning)
            .setContentTitle(getString(R.string.download_failed))
            .setContentText(contentText)
            .setGroup(DOWNLOAD_FAILED_GROUP)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());
}
 
Example 10
Source File: EarthquakeUpdateJobService.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void broadcastNotification(Earthquake earthquake) {
  createNotificationChannel();

  Intent startActivityIntent = new Intent(this, EarthquakeMainActivity.class);
  PendingIntent launchIntent = PendingIntent.getActivity(this, 0,
    startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

  final NotificationCompat.Builder earthquakeNotificationBuilder
    = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL);

  earthquakeNotificationBuilder
    .setSmallIcon(R.drawable.notification_icon)
    .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
    .setDefaults(NotificationCompat.DEFAULT_ALL)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setContentIntent(launchIntent)
    .setAutoCancel(true)
    .setShowWhen(true);

  earthquakeNotificationBuilder
    .setWhen(earthquake.getDate().getTime())
    .setContentTitle("M:" + earthquake.getMagnitude())
    .setContentText(earthquake.getDetails())
    .setStyle(new NotificationCompat.BigTextStyle()
                .bigText(earthquake.getDetails()));

  NotificationManagerCompat notificationManager
    = NotificationManagerCompat.from(this);

  notificationManager.notify(NOTIFICATION_ID,
    earthquakeNotificationBuilder.build());
}
 
Example 11
Source File: EarthquakeUpdateJobService.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void broadcastNotification(Earthquake earthquake) {
  createNotificationChannel();

  Intent startActivityIntent = new Intent(this, EarthquakeMainActivity.class);
  PendingIntent launchIntent = PendingIntent.getActivity(this, 0,
    startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

  final NotificationCompat.Builder earthquakeNotificationBuilder
    = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL);

  earthquakeNotificationBuilder
    .setSmallIcon(R.drawable.notification_icon)
    .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
    .setDefaults(NotificationCompat.DEFAULT_ALL)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setContentIntent(launchIntent)
    .setAutoCancel(true)
    .setShowWhen(true);

  earthquakeNotificationBuilder
    .setWhen(earthquake.getDate().getTime())
    .setContentTitle("M:" + earthquake.getMagnitude())
    .setContentText(earthquake.getDetails())
    .setStyle(new NotificationCompat.BigTextStyle()
                .bigText(earthquake.getDetails()));

  NotificationManagerCompat notificationManager
    = NotificationManagerCompat.from(this);

  notificationManager.notify(NOTIFICATION_ID,
    earthquakeNotificationBuilder.build());
}
 
Example 12
Source File: RecipeService.java    From android-RecipeAssistant with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    mNotificationManager = NotificationManagerCompat.from(this);
}
 
Example 13
Source File: AlarmNotifications.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
public static void dismissNotifications(Context context)
{
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.cancelAll();
}
 
Example 14
Source File: HidingManager.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private static void removeNotifications(Context context) {
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.cancelAll();
}
 
Example 15
Source File: KcaFleetCheckPopupService.java    From kcanotify_h5-master with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    active = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && !Settings.canDrawOverlays(getApplicationContext())) {
        // Can not draw overlays: pass
        stopSelf();
    } else {
        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        deckInfoCalc = new KcaDeckInfo(getApplicationContext(), getBaseContext());

        contextWithLocale = getContextWithLocale(getApplicationContext(), getBaseContext());

        mInflater = LayoutInflater.from(contextWithLocale);
        notificationManager = NotificationManagerCompat.from(getApplicationContext());
        mView = mInflater.inflate(R.layout.view_fleet_check, null);
        mView.setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.view_fchk_head).setOnTouchListener(mViewTouchListener);
        ((TextView) mView.findViewById(R.id.view_fchk_title)).setText(getStringWithLocale(R.string.fleetcheckview_title));

        for (int fchk_id: FCHK_BTN_LIST) {
            mView.findViewById(fchk_id).setOnTouchListener(mViewTouchListener);
        }
        for (int fleet_id: FCHK_FLEET_LIST) {
            mView.findViewById(fleet_id).setOnTouchListener(mViewTouchListener);
        }

        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWidth = mView.getMeasuredWidth();
        popupHeight = mView.getMeasuredHeight();

        fchk_info = mView.findViewById(R.id.fchk_value);

        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                getWindowLayoutType(),
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mParams.gravity = Gravity.TOP | Gravity.START;
        Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
        Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));

        mParams.x = (screenWidth - popupWidth) / 2;
        mParams.y = (screenHeight - popupHeight) / 2;
        mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mManager.addView(mView, mParams);
    }
}
 
Example 16
Source File: SimpleUpdateChecker.java    From ForPDA with GNU General Public License v3.0 4 votes vote down vote up
private void checkUpdate(JSONObject updateObject, Context context, String jsonSource) throws JSONException {
    if (context == null) {
        context = App.getContext();
    }
    final int currentVersionCode = BuildConfig.VERSION_CODE;
    final int versionCode = Integer.parseInt(updateObject.getString("version_code"));

    if (versionCode > currentVersionCode) {
        final String versionName = updateObject.getString("version_name");


        String channelId = "forpda_channel_updates";
        String channelName = context.getString(R.string.updater_notification_title);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
            NotificationManager manager = context.getSystemService(NotificationManager.class);
            if (manager != null) {
                manager.createNotificationChannel(channel);
            }
        }


        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId);

        NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);

        mBuilder.setSmallIcon(R.drawable.ic_notify_mention);

        mBuilder.setContentTitle(context.getString(R.string.updater_notification_title));
        mBuilder.setContentText(String.format(context.getString(R.string.updater_notification_content_VerName), versionName));
        mBuilder.setChannelId(channelId);


        Intent notifyIntent = new Intent(context, UpdateCheckerActivity.class);
        //notifyIntent.setData(Uri.parse(createIntentUrl(notificationEvent)));
        notifyIntent.putExtra(UpdateCheckerActivity.JSON_SOURCE, jsonSource);
        notifyIntent.setAction(Intent.ACTION_VIEW);
        PendingIntent notifyPendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);
        mBuilder.setContentIntent(notifyPendingIntent);

        mBuilder.setAutoCancel(true);

        mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
        mBuilder.setCategory(NotificationCompat.CATEGORY_EVENT);


        int defaults = 0;
        /*if (Preferences.Notifications.Main.isSoundEnabled()) {
            defaults |= NotificationCompat.DEFAULT_SOUND;
        }*/
        if (Preferences.Notifications.Main.isVibrationEnabled(null)) {
            defaults |= NotificationCompat.DEFAULT_VIBRATE;
        }
        mBuilder.setDefaults(defaults);

        mNotificationManager.notify(versionCode, mBuilder.build());
    }
}
 
Example 17
Source File: Notifications.java    From HAPP with GNU General Public License v3.0 4 votes vote down vote up
public static void newTemp(TempBasal basal, Context c, Realm realm){
    Log.d(TAG, "newTemp: START");
    
    String title, msg;
    Pump pump = new Pump(new Profile(new Date()), realm);
    pump.setNewTempBasal(null, basal);

    if (basal.checkIsCancelRequest()){
        title = "Set: " + basal.getBasal_adjustemnt();
        msg = pump.displayCurrentBasal(true);
    } else {
        title = "Set: " + pump.displayBasalDesc(false);
        msg = pump.displayCurrentBasal(true) + " for " + pump.temp_basal_duration + " mins";
    }

    Intent intent_accept_temp = new Intent();
    try {
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Class.forName("io.realm.TempBasalRealmProxy"), new TempBasalSerializer())
                .create();
        intent_accept_temp.putExtra("SUGGESTED_BASAL", gson.toJson(basal, TempBasal.class));
    } catch (ClassNotFoundException e){
        Log.e(TAG, "Error creating gson object: " + e.getLocalizedMessage());
    }
    intent_accept_temp.setAction(Intents.NOTIFICATION_UPDATE);
    intent_accept_temp.putExtra("NOTIFICATION_TYPE", "newTemp");
    PendingIntent pending_intent_accept_temp = PendingIntent.getBroadcast(c,1,intent_accept_temp,PendingIntent.FLAG_CANCEL_CURRENT);

    Intent intent_open_activity = new Intent(c,MainActivity.class);
    PendingIntent pending_intent_open_activity = PendingIntent.getActivity(c, 2, intent_open_activity, PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap bitmap = Bitmap.createBitmap(320, 320, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(c.getResources().getColor(R.color.secondary_text_light));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(c);
    notificationBuilder.setSmallIcon(R.drawable.exit_to_app);
    notificationBuilder.setColor(c.getResources().getColor(R.color.primary));
    notificationBuilder.extend(new NotificationCompat.WearableExtender().setBackground(bitmap));
    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(msg);
    notificationBuilder.setContentIntent(pending_intent_open_activity);
    notificationBuilder.setPriority(Notification.PRIORITY_MAX);
    notificationBuilder.setCategory(Notification.CATEGORY_ALARM);
    notificationBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    notificationBuilder.setVibrate(new long[]{500, 1000, 500, 500, 500, 1000, 500});
    notificationBuilder.addAction(R.drawable.exit_to_app, "Accept Temp", pending_intent_accept_temp);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    if (prefs.getBoolean("temp_basal_notification_make_sound", false)) {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        notificationBuilder.setSound(notification);
    }

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(MainApp.instance());
    notificationManager.notify(NEW_TEMP, notificationBuilder.build());

    Log.d(TAG, "newTemp: FINISH");
}
 
Example 18
Source File: RNPushNotification.java    From react-native-push-notification-CE with MIT License 4 votes vote down vote up
@ReactMethod
public void checkPermissions(Promise promise) {
    ReactContext reactContext = getReactApplicationContext();
    NotificationManagerCompat managerCompat = NotificationManagerCompat.from(reactContext);
    promise.resolve(managerCompat.areNotificationsEnabled());
}
 
Example 19
Source File: LocalNotificationManager.java    From OsmGo with MIT License 4 votes vote down vote up
public boolean areNotificationsEnabled(){
  NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
  return notificationManager.areNotificationsEnabled();
}
 
Example 20
Source File: MainActivity.java    From wearable with Apache License 2.0 4 votes vote down vote up
void voiceReplytNoti() {
	

	//create the intent to launch the notiactivity, then the pentingintent.
	Intent replyIntent = new Intent(this, VoiceNotiActivity.class);
	replyIntent.putExtra("NotiID", "Notification ID is " + notificationID);
	
	PendingIntent replyPendingIntent =
	        PendingIntent.getActivity(this, 0, replyIntent, 0);
	
	// create the remote input part for the notification.
	RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
       .setLabel("Reply")
       .build();
	
	
	// Create the reply action and add the remote input
	NotificationCompat.Action action =
	        new NotificationCompat.Action.Builder(R.drawable.ic_action_map,
	                "Reply", replyPendingIntent)
	                .addRemoteInput(remoteInput)
	                .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)
	        .setSmallIcon(R.drawable.ic_launcher)
	        .setContentTitle("reply Noti")
	        .setContentText("voice reply example.")
	        .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++;
	
}