android.support.v4.app.NotificationCompat Java Examples

The following examples show how to use android.support.v4.app.NotificationCompat. 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: NotificationService.java    From Crimson with Apache License 2.0 6 votes vote down vote up
private void screenAlertMessage(Context context, String msg) {

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle("Relax your eyes a little bit.")
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setVibrate(new long[0])
                        .setAutoCancel(true)
                        .setContentText(msg);

        int mNotificationId = 001;

        NotificationManager mNotifyMgr =
                (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
        mNotifyMgr.notify(mNotificationId, mBuilder.build());

    }
 
Example #2
Source File: ActivityNotificationHandler.java    From glimmr with Apache License 2.0 6 votes vote down vote up
private Notification getNotification(final String tickerText,
        final String titleText, final String contentText,
        int number, int smallIcon, Bitmap image, Photo photo) {
    return new NotificationCompat.BigPictureStyle(
            new NotificationCompat.Builder(mContext)
            .setContentTitle(titleText)
            .setContentText(contentText)
            .setNumber(number)
            .setTicker(tickerText)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentIntent(getPendingIntent(photo))
            .setLargeIcon(BitmapFactory.decodeResource(
                    mContext.getResources(), R.drawable.ic_notification))
            .setSmallIcon(smallIcon))
        .bigPicture(image)
        .setSummaryText(contentText)
        .setBigContentTitle(titleText)
        .build();
}
 
Example #3
Source File: MainService.java    From android-play-games-in-motion with Apache License 2.0 6 votes vote down vote up
/**
 * Builds and posts a notification from a set of options.
 * @param options The options to build the notification.
 */
public void postActionNotification(NotificationOptions options) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(options.getSmallIconResourceId());
    builder.setContentTitle(options.getTitle());
    builder.setContentText(options.getContent());
    builder.setDefaults(options.getNotificationDefaults());
    builder.setPriority(options.getNotificationPriority());
    builder.setVibrate(options.getVibratePattern());
    if (options.getActions() != null) {
        for (NotificationCompat.Action action : options.getActions()) {
            builder.addAction(action);
        }
    }
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);
    notificationManager.notify(options.getNotificationId(), builder.build());
}
 
Example #4
Source File: DownloadNotification.java    From Cangol-appcore with Apache License 2.0 6 votes vote down vote up
public void failureNotification() {
    NotificationCompat.Builder builder = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        builder = new NotificationCompat.Builder(context, DOWNLOAD_NOTIFICATION_CHANNEL_ID);
    } else {
        builder = new NotificationCompat.Builder(context);
    }
    builder.setContentTitle(titleText)
            .setContentText(failureText)
            .setContentInfo("")
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setOngoing(false)
            .setSmallIcon(android.R.drawable.stat_sys_download);

    notificationManager.notify(id, builder.build());
}
 
Example #5
Source File: MissionListenerForNotification.java    From AnimeTaste with MIT License 6 votes vote down vote up
@Override
public void onSuccess(M3U8Mission mission) {
    Intent intent = new Intent(context, PlayActivity.class);
    Animation animation = (Animation)mission.getExtraInformation(mission.getUri());
    intent.putExtra("Animation", animation);
    PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
    notifyBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_action_emo_wink)
            .setContentTitle(mission.getShowName())
            .setContentText(context.getString(R.string.download_success))
            .setProgress(100,mission.getPercentage(),false)
            .setContentIntent(pendingIntent)
            .setOngoing(false);
    notificationManager.notify(mission.getMissionID(), notifyBuilder.build());
    MobclickAgent.onEvent(context,"download_success");
}
 
Example #6
Source File: NotificationUtils.java    From LNMOnlineAndroidSample with Apache License 2.0 6 votes vote down vote up
private void showBigNotification(Bitmap bitmap, NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.setBigContentTitle(title);
    bigPictureStyle.setSummaryText(Html.fromHtml(message).toString());
    bigPictureStyle.bigPicture(bitmap);
    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(bigPictureStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_BIG_IMAGE, notification);
}
 
Example #7
Source File: NotificationHelper.java    From moVirt with Apache License 2.0 6 votes vote down vote up
public void showConnectionNotification(Context context,
                                       PendingIntent resultPendingIntent,
                                       ConnectionInfo connectionInfo) {
    MovirtAccount account = rxStore.getAllAccountsWrapped().getAccountById(connectionInfo.getAccountId());
    String location = account == null ? "" : " to " + account.getName();

    Log.d(TAG, "Displaying notification " + notificationCount);
    String shortMsg = "Check your settings/server";
    String bigMsg = shortMsg + "\nLast successful connection at: " +
            connectionInfo.getLastSuccessfulWithTimeZone(context);

    Notification notification = prepareNotification(context, resultPendingIntent, connectionInfo.getLastAttempt(), "Connection lost" + location + "!")
            .setContentText(shortMsg)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMsg))
            .build();
    notificationManager.notify(notificationCount++, notification);
    vibrator.vibrate(vibrationDuration);
}
 
Example #8
Source File: ActionsPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(Context context, NotificationCompat.Builder builder,
        NotificationCompat.WearableExtender wearableOptions) {
    RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
            .setLabel(context.getString(R.string.example_reply_answer_label))
            .setChoices(new String[] { context.getString(R.string.yes),
                    context.getString(R.string.no), context.getString(R.string.maybe) })
            .build();
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_full_reply,
            context.getString(R.string.example_reply_action),
            NotificationUtil.getExamplePendingIntent(context,
                    R.string.example_reply_action_clicked))
            .addRemoteInput(remoteInput)
            .build();
    wearableOptions.addAction(action);
}
 
Example #9
Source File: UrlManager.java    From delion with Apache License 2.0 6 votes vote down vote up
private void createNotification() {
    PendingIntent pendingIntent = createListUrlsIntent();

    // Get values to display.
    Resources resources = mContext.getResources();
    String title = resources.getString(R.string.physical_web_notification_title);
    Bitmap largeIcon = BitmapFactory.decodeResource(resources,
            R.drawable.physical_web_notification_large);

    // Create the notification.
    Notification notification = new NotificationCompat.Builder(mContext)
            .setLargeIcon(largeIcon)
            .setSmallIcon(R.drawable.ic_chrome)
            .setContentTitle(title)
            .setContentIntent(pendingIntent)
            .setPriority(NotificationCompat.PRIORITY_MIN)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true)
            .build();
    mNotificationManager.notify(NotificationConstants.NOTIFICATION_ID_PHYSICAL_WEB,
                                notification);
}
 
Example #10
Source File: SampleSchedulingService.java    From SpecialAlarmClock with Apache License 2.0 6 votes vote down vote up
private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(getString(R.string.doodle_alert))
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(msg))
            .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
 
Example #11
Source File: MyFirebaseMessagingService.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
private void sendMultilineNotification(String title, String messageBody) {
    //Log.e("DADA", "ADAD---"+title+"---message---"+messageBody);
    int notificationId = 0;
    Intent intent = new Intent(this, MainDashboard.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_custom_notification)
            .setLargeIcon(largeIcon)
            .setContentTitle(title/*"Firebase Push Notification"*/)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(messageBody))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notificationBuilder.build());
}
 
Example #12
Source File: NotificationParentActivity.java    From AndroidProjects with MIT License 6 votes vote down vote up
private void createAndShowNotification() {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.abc_popup_background_mtrl_mult)
                    .setContentTitle(getString(R.string.notification_title))
                    .setContentText(getString(R.string.notification_text));

    Intent resultIntent = new Intent(
            this.getApplicationContext(), NotificationParentActivity.class);

    resultIntent.putExtra(
            NotificationParentActivity.EXTRA_URL, getString(R.string.notification_sample_url));

    resultIntent.setAction(Intent.ACTION_VIEW);

    PendingIntent pendingIntent = PendingIntent.getActivity(
            this.getApplicationContext(), 0, resultIntent, 0);

    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setAutoCancel(true);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
 
Example #13
Source File: UpdateService.java    From XPrivacy with GNU General Public License v3.0 6 votes vote down vote up
private static void notifyProgress(Context context, int id, String format, int percentage) {
	String message = String.format(format, String.format("%d %%", percentage));
	Util.log(null, Log.WARN, message);

	NotificationManager notificationManager = (NotificationManager) context
			.getSystemService(Context.NOTIFICATION_SERVICE);
	NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
	builder.setSmallIcon(R.drawable.ic_launcher);
	builder.setContentTitle(context.getString(R.string.app_name));
	builder.setContentText(message);
	builder.setWhen(System.currentTimeMillis());
	builder.setAutoCancel(percentage == 100);
	builder.setOngoing(percentage < 100);
	Notification notification = builder.build();
	notificationManager.notify(id, notification);
}
 
Example #14
Source File: RMBTLoopService.java    From open-rmbt with Apache License 2.0 6 votes vote down vote up
private void setFinishedNotification() {
    Intent notificationIntent = new Intent(getApplicationContext(), RMBTMainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent openAppIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
    
	final Resources res = getResources();
	final Notification notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_icon_loop)
            .setContentTitle(res.getText(R.string.loop_notification_finished_title))
            .setTicker(res.getText(R.string.loop_notification_finished_ticker))
            .setContentIntent(openAppIntent)
            .build();

    //notification.flags |= Notification.FLAG_AUTO_CANCEL;

	notificationManager.notify(NotificationIDs.LOOP_ACTIVE, notification);
}
 
Example #15
Source File: Wear.java    From Pugnotification with Apache License 2.0 6 votes vote down vote up
public Wear remoteInput(@DrawableRes int icon, String title, PendingIntent pendingIntent) {
    if (icon <= 0) {
        throw new IllegalArgumentException("Resource ID Icon Should Not Be Less Than Or Equal To Zero!");
    }

    if (title == null) {
        throw new IllegalArgumentException("Title Must Not Be Null!");
    }

    if (pendingIntent == null) {
        throw new IllegalArgumentException("PendingIntent Must Not Be Null!");
    }

    this.remoteInput = new RemoteInput.Builder(PugNotification.mSingleton.mContext.getString(R.string.pugnotification_key_voice_reply))
            .setLabel(PugNotification.mSingleton.mContext.getString(R.string.pugnotification_label_voice_reply))
            .setChoices(PugNotification.mSingleton.mContext.getResources().getStringArray(R.array.pugnotification_reply_choices))
            .build();
    wearableExtender.addAction(new NotificationCompat.Action.Builder(icon,
            title, pendingIntent)
            .addRemoteInput(remoteInput)
            .build());
    return this;
}
 
Example #16
Source File: CheckUpdateTask.java    From fingerpoetry-android with Apache License 2.0 6 votes vote down vote up
/**
 * Show Notification
 */
private void showNotification(Context context, String content, String apkUrl) {
    Intent myIntent = new Intent(context, DownloadService.class);
    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    myIntent.putExtra(Constants.APK_DOWNLOAD_URL, apkUrl);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    int smallIcon = context.getApplicationInfo().icon;
    Notification notify = new NotificationCompat.Builder(context)
            .setTicker(context.getString(R.string.android_auto_update_notify_ticker))
            .setContentTitle(context.getString(R.string.android_auto_update_notify_content))
            .setContentText(content)
            .setSmallIcon(smallIcon)
            .setContentIntent(pendingIntent).build();

    notify.flags = Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notify);
}
 
Example #17
Source File: MyActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private void listing11_19(NotificationCompat.Builder builder, Context context) {
  String title = "This is a title";
  String text = "This is the body text, that goes on for some length";
  Bitmap profilePicture = BitmapFactory.decodeResource(context.getResources(),
                                                       R.drawable.ic_launcher_background);

  // Listing 11-19: Applying a Big Text Style to a Notification
  builder.setSmallIcon(R.drawable.ic_notification)
    .setContentTitle(title)
    .setContentText(text)
    .setLargeIcon(profilePicture)
    .setStyle(new NotificationCompat.BigTextStyle().bigText(text));
}
 
Example #18
Source File: NotificationHelper.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
public static void notifyShort(@NonNull Context context, @NonNull String title, @NonNull String msg, @DrawableRes int iconId, int nId,
                               @Nullable PendingIntent pendingIntent) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new NotificationCompat.Builder(context)
            .setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentTitle(title)
            .setContentText(msg)
            .setSmallIcon(iconId)
            .setContentIntent(pendingIntent)
            .build();
    notificationManager.notify(nId, notification);
}
 
Example #19
Source File: MoveService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showFailedNotification(String title, String content, int notificationId) {
    createSummaryNotificationForFailed();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_warning)
            .setContentTitle(title)
            .setContentText(content)
            .setGroup(OPERATION_FAILED_GROUP)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationId, builder.build());

}
 
Example #20
Source File: PlaybackNotificationFactoryImpl.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
private static void addActionPrev(@NonNull final Context context,
                                  @NonNull final NotificationCompat.Builder b) {
    final PendingIntent prevIntent = PendingIntent.getService(context, 1,
            PlaybackServiceIntentFactory.intentPrev(context),
            PendingIntent.FLAG_UPDATE_CURRENT);

    b.addAction(R.drawable.ic_fast_rewind_white_24dp,
            context.getText(R.string.Previous), prevIntent);
}
 
Example #21
Source File: ExportService.java    From PlayMusicExporter with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Logger.getInstance().logDebug("ExportService", "Start");

    // Creates a notification builder
    mNotificationBuilder = new NotificationCompat.Builder(this);
}
 
Example #22
Source File: fileDlService.java    From service with Apache License 2.0 5 votes vote down vote up
public void shownoti(int val, String message, File file) {
	NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	Notification noti ;
	
	if (val >=0) {
   	Intent notificationIntent = new Intent();
   	notificationIntent.setAction(Intent.ACTION_VIEW); 
   	notificationIntent.setDataAndType(
   	  Uri.parse("file://"+file.getAbsolutePath()), "image/*"
   			                              );
       PendingIntent contentIntent = PendingIntent.getActivity(this, 100, notificationIntent, 0);

	 noti = new NotificationCompat.Builder(getApplicationContext())
	.setSmallIcon(R.drawable.ic_launcher)
	.setWhen(System.currentTimeMillis())  //When the event occurred, now, since noti are stored by time.
	.setContentIntent(contentIntent)  //what activity to open.
	.setContentTitle("FileDownload")   //Title message top row.
	.setContentText(message)  //message when looking at the notification, second row
	.setAutoCancel(true)   //allow auto cancel when pressed.
	.build();  //finally build and return a Notification.
	
	} else {
		noti = new NotificationCompat.Builder(getApplicationContext())
		.setSmallIcon(R.drawable.ic_launcher)
		.setWhen(System.currentTimeMillis())  //When the event occurred, now, since noti are stored by time.
		.setContentTitle("File Download")   //Title message top row.
		.setContentText(message)  //message when looking at the notification, second row
		.setAutoCancel(true)   //allow auto cancel when pressed.
		.build();  //finally build and return a Notification.
	}
	//finally Show the notification
	nm.notify(100, noti);	
}
 
Example #23
Source File: DownloadService.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public void resumeDownload(long downloadId) {
    startService(new Intent(getApplicationContext(), DownloadService.class));

    if (mBuilder == null) mBuilder = createDefaultNotification();
    startForeground(-3, mBuilder.build());

    //Logger.d("donwload-trace", "setmBuilder: resumeDownload");
    DownloadInfoRunnable info = getDownload(downloadId);
    NotificationCompat.Builder builder = setNotification(downloadId);
    info.setmBuilder(builder);

    info.download();

    startIfStopped();
}
 
Example #24
Source File: CrashUtil.java    From CrashReporter with Apache License 2.0 5 votes vote down vote up
private static void showNotification(String localisedMsg, boolean isCrash) {

        if (CrashReporter.isNotificationEnabled()) {
            Context context = CrashReporter.getContext();
            NotificationManager notificationManager = (NotificationManager) context.
                    getSystemService(NOTIFICATION_SERVICE);
            createNotificationChannel(notificationManager, context);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_NOTIFICATION_ID);
            builder.setSmallIcon(R.drawable.ic_warning_black_24dp);

            Intent intent = CrashReporter.getLaunchIntent();
            intent.putExtra(Constants.LANDING, isCrash);
            intent.setAction(Long.toString(System.currentTimeMillis()));

            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
            builder.setContentIntent(pendingIntent);

            builder.setContentTitle(context.getString(R.string.view_crash_report));

            if (TextUtils.isEmpty(localisedMsg)) {
                builder.setContentText(context.getString(R.string.check_your_message_here));
            } else {
                builder.setContentText(localisedMsg);
            }

            builder.setAutoCancel(true);
            builder.setColor(ContextCompat.getColor(context, R.color.colorAccent_CrashReporter));

            notificationManager.notify(Constants.NOTIFICATION_ID, builder.build());
        }
    }
 
Example #25
Source File: WalkEditService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addNotification() {
    if (!mShowNotification)
        return;

    MapBase map = MapBase.getInstance();
    ILayer layer = map.getLayerById(mLayerId);
    String name = "";
    if (null != layer)
        name = layer.getName();

    mTicker = String.format(getString(R.string.walkedit_title), name);
    Bitmap largeIcon = NotificationHelper.getLargeIcon(mSmallIcon, getResources());

    NotificationCompat.Builder builder = createBuilder(this, R.string.title_edit_by_walk);

    builder.setContentIntent(mOpenActivity)
           .setSmallIcon(mSmallIcon)
           .setLargeIcon(largeIcon)
           .setTicker(mTicker)
           .setWhen(System.currentTimeMillis())
           .setAutoCancel(false)
           .setContentTitle(mTicker)
           .setContentText(mTicker)
           .setOngoing(true);

    builder.addAction(R.drawable.ic_location, getString(R.string.tracks_open), mOpenActivity);

    mNotificationManager.notify(WALK_NOTIFICATION_ID, builder.build());
    startForeground(WALK_NOTIFICATION_ID, builder.build());
}
 
Example #26
Source File: DownloadService.java    From rcloneExplorer with MIT License 5 votes vote down vote up
private void showDownloadFinishedNotification(int notificationID, String contentText) {
    createSummaryNotificationForFinished();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(android.R.drawable.stat_sys_download_done)
            .setContentTitle(getString(R.string.download_complete))
            .setContentText(contentText)
            .setGroup(DOWNLOAD_FINISHED_GROUP)
            .setAutoCancel(true)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(notificationID, builder.build());
}
 
Example #27
Source File: SetTimerActivity.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
/**
 * Build a notification including different actions and other various setup and return it.
 *
 * @param duration the duration of the timer.
 * @return the notification to display.
 */

private Notification buildNotification(long duration) {
    // Intent to restart a timer.
    Intent restartIntent = new Intent(Constants.ACTION_RESTART_ALARM, null, this,
            TimerNotificationService.class);
    PendingIntent pendingIntentRestart = PendingIntent
            .getService(this, 0, restartIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Intent to delete a timer.
    Intent deleteIntent = new Intent(Constants.ACTION_DELETE_ALARM, null, this,
            TimerNotificationService.class);
    PendingIntent pendingIntentDelete = PendingIntent
            .getService(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create countdown notification using a chronometer style.
    return new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_cc_alarm)
            .setContentTitle(getString(R.string.timer_time_left))
            .setContentText(TimerFormat.getTimeString(duration))
            .setUsesChronometer(true)
            .setWhen(System.currentTimeMillis() + duration)
            .addAction(R.drawable.ic_cc_alarm, getString(R.string.timer_restart),
                    pendingIntentRestart)
            .addAction(R.drawable.ic_cc_alarm, getString(R.string.timer_delete),
                    pendingIntentDelete)
            .setDeleteIntent(pendingIntentDelete)
            .setLocalOnly(true)
            .build();
}
 
Example #28
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private NotificationCompat.Builder notificationBuilder(String title, String content, Intent intent) {
    return new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setContentTitle(title)
            .setContentText(content)
            .setContentIntent(notificationIntent(intent));
}
 
Example #29
Source File: myIntentService.java    From service with Apache License 2.0 5 votes vote down vote up
public void makenoti(String message) {

		Notification noti = new NotificationCompat.Builder(getApplicationContext())
		.setSmallIcon(R.drawable.ic_launcher)
		.setWhen(System.currentTimeMillis())  //When the event occurred, now, since noti are stored by time.
		
		.setContentTitle("Service")   //Title message top row.
		.setContentText(message)  //message when looking at the notification, second row
		.setAutoCancel(true)   //allow auto cancel when pressed.
		.build();  //finally build and return a Notification.

		//Show the notification
		nm.notify(NotID, noti);
		NotID++;
	}
 
Example #30
Source File: NewsDetailActivity.java    From Social with Apache License 2.0 5 votes vote down vote up
private void handleAutoLogin(Message msg){
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setTicker("自动登录");
    builder.setContentTitle("已自动登录");
    builder.setContentText("请重新操作...");
    builder.setSmallIcon(R.mipmap.logo);
    builder.setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(4, builder.build());

    //发广播通知MainActivity修改界面
    Intent intent = new Intent("com.allever.autologin");
    sendBroadcast(intent);

    String result = msg.obj.toString();
    Log.d("Setting", result);
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
    LoginRoot root = gson.fromJson(result, LoginRoot.class);
    JPushInterface.setAlias(this, root.user.username, new TagAliasCallback() {
        @Override
        public void gotResult(int i, String s, Set<String> set) {

        }
    });


}