Java Code Examples for android.support.v4.app.NotificationCompat#Action

The following examples show how to use android.support.v4.app.NotificationCompat#Action . 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: PhoneNumberVerifier.java    From identity-samples with Apache License 2.0 6 votes vote down vote up
private Notification getNotification(Context context, int status, @Nullable String phoneNo) {
    if (phoneNo != null) {
        Intent cancelI = new Intent(this, PhoneNumberVerifier.class);
        cancelI.setAction(ACTION_CANCEL);
        PendingIntent cancelPI = PendingIntent.getService(this, 0, cancelI,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Action cancelA = new NotificationCompat.Action.Builder(
                R.drawable.ic_not_interested_black_24dp,
                getString(R.string.cancel_verification), cancelPI
        ).build();

        notification = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(context.getString(R.string.phone_verify_notify_title))
                .setContentText(context.getString(R.string.phone_verify_notify_message, phoneNo))
                .addAction(cancelA);
    } else if (notification == null) {
        throw new IllegalStateException("A Phone number needs to be provided initially");
    }

    notification.setProgress(STATUS_MAX, status, false);
    return notification.build();
}
 
Example 2
Source File: NotificationUtils.java    From wear with MIT License 6 votes vote down vote up
public static void showNotificationWithAction(Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(""));
    PendingIntent pendingIntent =
            PendingIntent.getActivity(context, 0, intent, 0);

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                    context.getString(R.string.action_button), pendingIntent)
                    .build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(context.getString(R.string.action_title))
                    .setContentText(context.getString(R.string.action_text))
                    .addAction(action)
                    .build());
}
 
Example 3
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
public void onClickSend(View view){
    Intent activityIntent = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(this,0,activityIntent,0);

    RemoteInput remoteInput = new RemoteInput.Builder(KEY_REPLY_TEXT)
            .setLabel("Reply")
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_revert,
                    "Reply", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(this,getChannelId())
                    .setSmallIcon(android.R.drawable.ic_dialog_email)
                    .setContentTitle("Reply")
                    .setContentText("Content")
                    .addAction(action);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(0, notificationBuilder.build());
}
 
Example 4
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 5
Source File: DownloadNotifier.java    From Downloader with Apache License 2.0 6 votes vote down vote up
void onDownloading(int progress) {
	if (!this.hasDeleteContent()) {
		this.setDelecte(buildCancelContent(mContext, mNotificationId, mDownloadTask.mUrl));
	}
	if (!mAddedCancelAction) {
		mAddedCancelAction = true;
		mAction = new NotificationCompat.Action(android.R.color.transparent,
				mContext.getString(android.R.string.cancel),
				buildCancelContent(mContext, mNotificationId, mDownloadTask.mUrl));
		mBuilder.addAction(mAction);

	}
	mBuilder.setContentText(this.mContent = mContext.getString(R.string.download_current_downloading_progress, (progress + "%")));
	this.setProgress(100, progress, false);
	sent();
}
 
Example 6
Source File: NotificationUtils.java    From wear with MIT License 6 votes vote down vote up
public static void showNotificationWithInputForSecondaryAction(Context context) {
    Intent intent = new Intent(ACTION_TEST);
    PendingIntent pendingIntent =
            PendingIntent.getActivity(context, 0, intent, 0);

    RemoteInput remoteInput = new RemoteInput.Builder(ACTION_EXTRA)
            .setLabel(context.getString(R.string.action_label))
            .build();

    NotificationCompat.Action action =
            new NotificationCompat.Action.Builder(R.drawable.ic_launcher,
                    "Action", pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

    NotificationManagerCompat.from(context).notify(getNewID(),
            new NotificationCompat.Builder(context)
                    .setContentTitle(context.getString(R.string.action_title))
                    .extend(new WearableExtender().addAction(action))
                    .build());
}
 
Example 7
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    Notification secondPage = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.second_page_content_title))
            .setContentText(context.getString(R.string.second_page_content_text))
            .extend(new NotificationCompat.WearableExtender()
                    .setContentAction(1))
            .build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(
            R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
                    context, R.string.example_content_action_clicked)).build();
    NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(
            R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
                    context, R.string.example_content_action2_clicked)).build();
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender()
                    .addAction(action)
                    .addAction(action2)
                    .addPage(secondPage)
                    .setContentAction(0)
                    .setHintHideIcon(true);
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 8
Source File: HeadsUp.java    From MoeQuest with Apache License 2.0 5 votes vote down vote up
@Override
public Builder addAction(int icon, CharSequence title, PendingIntent intent) {

  NotificationCompat.Action action = new NotificationCompat.Action(icon, title, intent);
  actions.add(action);
  super.addAction(icon, title, intent);
  return this;
}
 
Example 9
Source File: MainActivity.java    From wearable with Apache License 2.0 5 votes vote down vote up
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,
	                "take a Picutre", 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)
	        .setSmallIcon(R.drawable.ic_launcher)
	        .setContentTitle("add button Noti")
	        .setContentText("swipe left to open camera.")
	        .setContentIntent(viewPendingIntent)
	        .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 10
Source File: RecorderService.java    From screenrecorder with GNU Affero General Public License v3.0 5 votes vote down vote up
@TargetApi(24)
private void resumeScreenRecording() {
    mMediaRecorder.resume();

    //Reset startTime to current time again
    startTime = System.currentTimeMillis();

    //set Pause action to Notification and update current Notification
    Intent recordPauseIntent = new Intent(this, RecorderService.class);
    recordPauseIntent.setAction(Const.SCREEN_RECORDING_PAUSE);
    PendingIntent precordPauseIntent = PendingIntent.getService(this, 0, recordPauseIntent, 0);
    NotificationCompat.Action action = new NotificationCompat.Action(android.R.drawable.ic_media_pause,
            getString(R.string.screen_recording_notification_action_pause), precordPauseIntent);
    updateNotification(createRecordingNotification(action).setUsesChronometer(true)
            .setWhen((System.currentTimeMillis() - elapsedTime)).build(), Const.SCREEN_RECORDER_NOTIFICATION_ID);
    Toast.makeText(this, R.string.screen_recording_resumed_toast, Toast.LENGTH_SHORT).show();

    if (isBound)
        floatingControlService.setRecordingState(Const.RecordingState.RECORDING);


    //Send a broadcast receiver to the plugin app to enable show touches since the recording is resumed
    if (showTouches) {
        if (showTouches) {
            Intent TouchIntent = new Intent();
            TouchIntent.setAction("com.orpheusdroid.screenrecorder.SHOWTOUCH");
            TouchIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            sendBroadcast(TouchIntent);
        }
    }
}
 
Example 11
Source File: NotifyUtils.java    From android with MIT License 5 votes vote down vote up
private static NotificationCompat.Action getButtonAction(Context context, long checkinId) {
    final PendingIntent checkoutIntent = PendingIntent.getService(
            context,
            0,
            CheckoutService.newIntent(context, checkinId),
            PendingIntent.FLAG_UPDATE_CURRENT
    );

    return new NotificationCompat.Action(R.drawable.ic_action_done,
            context.getResources().getString(R.string.btn_checkout),
            checkoutIntent);
}
 
Example 12
Source File: patientIntentService.java    From Doctorave with MIT License 5 votes vote down vote up
public static NotificationCompat.Action FirstAction(Context context, String firstActionText) {

        Intent ignoreReminderIntent = new Intent(context, notificationIntentService.class);
        PendingIntent ignoreReminderPendingIntent = PendingIntent.getService(
                context,
                ACTION_CANCEL_SYNCING,
                ignoreReminderIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_launcher_background,
                firstActionText,
                ignoreReminderPendingIntent);
        return action;

    }
 
Example 13
Source File: NotificationHelper.java    From FastAccess with GNU General Public License v3.0 4 votes vote down vote up
public static void notifyShort(@NonNull Context context, @NonNull String title, String msg, @DrawableRes int iconId,
                               @NonNull NotificationCompat.Action action) {
    notifyShort(context, title, msg, iconId, action, NOTIFICATION_ID);
}
 
Example 14
Source File: AlarmChecker.java    From com.ruuvi.station with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void sendAlert(int stringResId, int _id, String name, String mac, Context context) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
    int notificationId = _id + stringResId;
    NotificationCompat.Builder notification;

    Intent intent = new Intent(context, TagDetails.class);
    intent.putExtra("id", mac);

    PendingIntent pendingIntent = TaskStackBuilder.create(context)
            .addNextIntent(intent)
            .getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent cancelIntent = new Intent(context, CancelAlarmReceiver.class);
    cancelIntent.putExtra("alarmId", _id);
    cancelIntent.putExtra("notificationId", notificationId);
    PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(context, _id, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_ruuvi_app_notification_icon_v2, context.getString(R.string.disable_this_alarm), cancelPendingIntent);

    notification
            = new NotificationCompat.Builder(context, "notify_001")
            .setContentTitle(name)
            .setTicker(name + " " + context.getString(stringResId))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(stringResId)))
            .setContentText(context.getString(stringResId))
            .setDefaults(Notification.DEFAULT_ALL)
            .setOnlyAlertOnce(true)
            .setAutoCancel(true)
            .setPriority(NotificationCompat.PRIORITY_MAX)
            .setContentIntent(pendingIntent)
            .setLargeIcon(bitmap)
            .setSmallIcon(R.drawable.ic_ruuvi_app_notification_icon_v2)
            .addAction(action);

    try {
        NotificationManager NotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            NotificationChannel channel = new NotificationChannel("notify_001",
                    "Alert notifications",
                    NotificationManager.IMPORTANCE_DEFAULT);
            NotifyMgr.createNotificationChannel(channel);
        }

        NotifyMgr.notify(notificationId, notification.build());
    } catch (Exception e) {
        Log.d(TAG, "Failed to create notification");
    }
}
 
Example 15
Source File: NotificationOptions.java    From android-play-games-in-motion with Apache License 2.0 4 votes vote down vote up
public NotificationCompat.Action[] getActions() {
    return mActions;
}
 
Example 16
Source File: NotificationSampleListener.java    From okdownload with Apache License 2.0 4 votes vote down vote up
public void setAction(NotificationCompat.Action action) {
    this.action = action;
}
 
Example 17
Source File: MainActivity.java    From AndroidProjects with MIT License 4 votes vote down vote up
public void simpleNotify(View view) {
        count++;

//        PendingIntent.getBroadcast();
//        PendingIntent.getService();
//        PendingIntent.getActivities();
//        PendingIntent.getActivity();

        PendingIntent activities = PendingIntent.getActivity(getApplicationContext()
                , 1
                , new Intent(getApplicationContext(), ResultActivity.class)
                , Intent.FILL_IN_ACTION);


        RemoteInput remoteInput = new RemoteInput.Builder("")
                .setLabel("label")
                .build();

        // Build an Android N compatible Remote Input enabled action.
        NotificationCompat.Action actionReplyByRemoteInput = new NotificationCompat.Action.Builder(
                R.mipmap.ic_launcher, "输入框", activities)
                .addRemoteInput(remoteInput)
                .build();

        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.item_remote_view);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setVisibility(View.VISIBLE)
                .setContentTitle("My notification")//标题
                .setContentText("Hello World!")//正文
                .setSubText("SubText")//设置在平台通知模板文本的第三行
                .setRemoteInputHistory(new CharSequence[]{"1", "2", "3"})//设置远程输入历史。
                .setContent(remoteViews)//提供一个定制RemoteViews,而不是使用标准之一。
                .setDeleteIntent(activities)//供应PendingIntent时通报用户直接从通知面板清除发送。
                .setFullScreenIntent(activities, false)//意图发动,而不是张贴通知状态栏。
                .setTicker("Tocker")//设置显示在状态栏时通报首先到达的文本。
                .setSortKey("排序键")//设置听命于同一包内的其他通知中此通知的排序键
                .setOnlyAlertOnce(false)//设置此标志,如果你只喜欢的声音,震动和股票要如果通知尚未显示播放。
                .setPriority(NotificationCompat.PRIORITY_MAX)//设置相对优先级此通知。
                .setColor(Color.GREEN)//颜色
                .setCategory(NotificationCompat.CATEGORY_PROMO)//设置的通知类别。
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.qq))//设置大图标所示股票和通知。
                .setNumber(3)//设置信息条数
                .setContentInfo("在右边设置大型文本的通知")
                .setWhen(System.currentTimeMillis())//设置时间
                .setShowWhen(true)//现实When
                .setContentIntent(activities)//设置Intent
                .setVibrate(new long[]{3000, 1000, 3000, 1000})//震动
                .setLights(0xff0000ff, 300, 0)//闪光灯
                .setAutoCancel(true)//点击之后自动消失
                .setOngoing(false)//用户不能手动清除
                .setProgress(100, 50, false)//进度条
                .addAction(actionReplyByRemoteInput);

        // 适配Android8.0图标
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            mBuilder.setSmallIcon(R.mipmap.android_os);
        } else {
            mBuilder.setSmallIcon(R.mipmap.ic_launcher);
        }

        if (isPlayMusic)
            mBuilder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.actor));//设置声音播放。它将在默认流上播放。
        else
            mBuilder.setDefaults(Notification.DEFAULT_ALL);//设置将要使用的默认通知选项。

        NotificationManagerCompat.from(getApplicationContext()).notify(count, mBuilder.build());
    }
 
Example 18
Source File: Load.java    From ZadakNotification with MIT License 4 votes vote down vote up
public Load button(@NonNull NotificationCompat.Action action) {
    this.builder.addAction(action);
    return this;
}
 
Example 19
Source File: HeadsUp.java    From MoeQuest with Apache License 2.0 2 votes vote down vote up
protected void setActions(List<NotificationCompat.Action> actions) {

    this.actions = actions;
  }
 
Example 20
Source File: HeadsUp.java    From MoeQuest with Apache License 2.0 2 votes vote down vote up
protected List<NotificationCompat.Action> getActions() {

    return actions;
  }