本文整理汇总了Java中android.app.Notification.Action方法的典型用法代码示例。如果您正苦于以下问题:Java Notification.Action方法的具体用法?Java Notification.Action怎么用?Java Notification.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.Action方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNotification
import android.app.Notification; //导入方法依赖的package包/类
private static Notification buildNotification(Service context, String channelId) {
// Create Pending Intents.
PendingIntent piLaunchMainActivity = getLaunchActivityPI(context);
PendingIntent piStopService = getStopServicePI(context);
// Action to stop the service.
Notification.Action stopAction =
new Notification.Action.Builder(
STOP_ACTION_ICON,
getNotificationStopActionText(context),
piStopService)
.build();
// Create a notification.
return new Notification.Builder(context, channelId)
.setContentTitle(getNotificationTitle(context))
.setContentText(getNotificationContent(context))
.setSmallIcon(SMALL_ICON)
.setContentIntent(piLaunchMainActivity)
.setActions(stopAction)
.setStyle(new Notification.BigTextStyle())
.build();
}
示例2: handleStatusBarNotification
import android.app.Notification; //导入方法依赖的package包/类
private void handleStatusBarNotification(@NonNull StatusBarNotification statusBarNotification, @NonNull String intentAction) {
String packageName = statusBarNotification.getPackageName();
String tickerText = "";
if (statusBarNotification.getNotification().tickerText != null) {
tickerText = statusBarNotification.getNotification().tickerText.toString();
}
Bundle extras = statusBarNotification.getNotification().extras;
String title = extras.getString("android.title");
String text = "";
CharSequence textCharSequence = extras.getCharSequence("android.text");
if (textCharSequence != null) {
text = textCharSequence.toString();
} else {
Logger.getInstance().Warning(TAG, "textCharSequence is null!");
}
Bitmap bitmap = statusBarNotification.getNotification().largeIcon;
Notification.Action[] notificationActions = statusBarNotification.getNotification().actions;
Intent messageReceiveIntent = new Intent(intentAction);
messageReceiveIntent.putExtra(EXTRA_KEY_PACKAGE_NAME, packageName);
messageReceiveIntent.putExtra(EXTRA_KEY_TICKER_TEXT, tickerText);
messageReceiveIntent.putExtra(EXTRA_KEY_TITLE, title);
messageReceiveIntent.putExtra(EXTRA_KEY_TEXT, text);
messageReceiveIntent.putExtra(EXTRA_KEY_NOTIFICATION_ACTIONS, notificationActions);
if (bitmap != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
messageReceiveIntent.putExtra(EXTRA_KEY_ICON, byteArray);
}
LocalBroadcastManager.getInstance(_context).sendBroadcast(messageReceiveIntent);
}
示例3: onNotificationPosted
import android.app.Notification; //导入方法依赖的package包/类
@Override
public void onNotificationPosted(StatusBarNotification statusBarNotification) {
super.onNotificationPosted(statusBarNotification);
if(statusBarNotification.getPackageName().equals(KAKAO_TALK)) {
Notification.WearableExtender extender = new Notification.WearableExtender(statusBarNotification.getNotification());
for(Notification.Action act : extender.getActions()) {
if(act.getRemoteInputs() != null && act.getRemoteInputs().length > 0) {
context = getApplicationContext();
Object title = null;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
title = statusBarNotification.getNotification().extras.getString("android.summaryText");
} else {
title = statusBarNotification.getNotification().extras.getString("android.title");
}
Object text = statusBarNotification.getNotification().extras.get("android.text");
KakaoData data = getKakaoData(title.toString(), text);
data.session = act;
KakaoManager.getInstance().addKakaoData(data);
}
}
}
}
示例4: send
import android.app.Notification; //导入方法依赖的package包/类
public static void send(String room, String message) throws IllegalArgumentException { // @author ManDongI
Notification.Action session = null;
for(KakaoData data : KakaoManager.getInstance().getDataList().toArray(new KakaoData[0])) {
if(data.room.equals(room)) {
session = data.session;
break;
}
}
if(session == null) {
throw new IllegalArgumentException("Can't find the room");
}
Intent sendIntent = new Intent();
Bundle msg = new Bundle();
for (RemoteInput inputable : session.getRemoteInputs()) msg.putCharSequence(inputable.getResultKey(), message);
RemoteInput.addResultsToIntent(session.getRemoteInputs(), sendIntent, msg);
try {
session.actionIntent.send(context, 0, sendIntent);
Logger.Log log = new Logger.Log();
log.type = Logger.Type.APP;
log.title = "send message";
log.index = "room: " + room +"\nmessage: " + message;
Logger.getInstance().add(log);
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
示例5: createNotify
import android.app.Notification; //导入方法依赖的package包/类
private void createNotify(){
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent piShot = PendingIntent.getService(this, 0, shotIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Icon icon = Icon.createWithResource(this, R.drawable.ic_camera);
Notification.Action shotAction = new Notification.Action.Builder(icon, getString(R.string.notify_title_shot), piShot).build();
NotifyUtil.notifyShot(this, resultIntent, 1, shotAction);
}
示例6: writeActions
import android.app.Notification; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
private void writeActions(JsonWriter writer, Notification notification) throws IOException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
if (notification.actions != null) {
Log.d(TAG, "writing action");
writer.name("actions");
writer.beginArray();
for (Notification.Action a : notification.actions) {
Log.d(TAG, "writing action : " + a.title.toString());
writer.beginObject();
writer.name("title").value(a.title.toString());
writer.endObject();
}
writer.endArray();
}
}
示例7: send
import android.app.Notification; //导入方法依赖的package包/类
public static void send(String room, String message) throws IllegalArgumentException { // @author ManDongI
Notification.Action session = null;
for(Session i : sessions) {
if(i.room.equals(room)) {
session = i.session;
break;
}
}
if(session == null) {
throw new IllegalArgumentException("Can't find the room");
}
Intent sendIntent = new Intent();
Bundle msg = new Bundle();
for (RemoteInput inputable : session.getRemoteInputs()) msg.putCharSequence(inputable.getResultKey(), message);
RemoteInput.addResultsToIntent(session.getRemoteInputs(), sendIntent, msg);
try {
session.actionIntent.send(context, 0, sendIntent);
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
示例8: createRunningNotification
import android.app.Notification; //导入方法依赖的package包/类
private Notification createRunningNotification() {
Log.i(TAG, "Create running notification");
if (mNotificationRunning != null) return mNotificationRunning;
Intent openIntent = new Intent(this, MainActivity.class);
Intent pauseIntent = new Intent(Constants.ACTION_UPDATE_FROM_NOTIFICATION);
pauseIntent.putExtra(Constants.EXTRA_ACTION, Constants.ACTION_PAUSE);
Notification.Action pauseAction = new Notification.Action(
R.drawable.ic_wb_incandescent_black_24dp,
getString(R.string.notification_action_turn_off),
PendingIntent.getBroadcast(getBaseContext(), 0, pauseIntent, Intent.FILL_IN_DATA));
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, openIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mNotificationRunning = new Notification.Builder(getApplicationContext())
.setContentTitle(getString(R.string.notification_running_title))
.setContentText(getString(R.string.notification_running_msg))
.setSmallIcon(R.drawable.ic_brightness_2_white_36dp)
.addAction(pauseAction)
.setContentIntent(resultPendingIntent)
.setAutoCancel(false)
.setOngoing(true)
.setOnlyAlertOnce(true)
.setShowWhen(false)
.build();
return mNotificationRunning;
}
示例9: createPauseNotification
import android.app.Notification; //导入方法依赖的package包/类
private Notification createPauseNotification() {
if (mNotificationPause != null) {
return mNotificationPause;
}
Log.i(TAG, "Create paused notification");
Intent openIntent = new Intent(this, MainActivity.class);
Intent resumeIntent = new Intent();
resumeIntent.setAction(Constants.ACTION_UPDATE_FROM_NOTIFICATION);
resumeIntent.putExtra(Constants.EXTRA_ACTION, Constants.ACTION_START);
resumeIntent.putExtra(Constants.EXTRA_COLOR_PROFILE, mColorProfile);
Intent closeIntent = new Intent(this, MaskService.class);
closeIntent.putExtra(Constants.EXTRA_ACTION, Constants.ACTION_STOP);
Notification.Action resumeAction = new Notification.Action(R.drawable.ic_wb_incandescent_black_24dp,
getString(R.string.notification_action_turn_on),
PendingIntent.getBroadcast(getBaseContext(), 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT));
mNotificationPause = new Notification.Builder(getApplicationContext())
.setContentTitle(getString(R.string.notification_paused_title))
.setContentText(getString(R.string.notification_paused_msg))
.setSmallIcon(R.drawable.ic_brightness_2_white_36dp)
.addAction(resumeAction)
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.setAutoCancel(true)
.setOngoing(false)
.setOnlyAlertOnce(true)
.setShowWhen(false)
.setDeleteIntent(PendingIntent.getService(getBaseContext(), 0, closeIntent, PendingIntent.FLAG_UPDATE_CURRENT))
.build();
return mNotificationPause;
}
示例10: createStopAction
import android.app.Notification; //导入方法依赖的package包/类
private Notification.Action createStopAction() {
Intent stopIntent = GnirehtetService.createStopIntent(context);
PendingIntent stopPendingIntent = PendingIntent.getService(context, 0, stopIntent, PendingIntent.FLAG_ONE_SHOT);
// the non-deprecated constructor is not available in API 21
@SuppressWarnings("deprecation")
Notification.Action.Builder actionBuilder = new Notification.Action.Builder(R.drawable.ic_close_24dp, context.getString(R.string.stop_vpn),
stopPendingIntent);
return actionBuilder.build();
}
示例11: createAction
import android.app.Notification; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private Notification.Action createAction(int icon, String title, String intentAction) {
Intent intent = new Intent(getApplicationContext(), PlayMediaService.class);
intent.setAction(intentAction);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 1, intent, 0);
return new Notification.Action.Builder(icon, title, pendingIntent).build();
}
示例12: notifyShot
import android.app.Notification; //导入方法依赖的package包/类
public static void notifyShot(Context context, Intent intent, int id, Notification.Action... actions) {
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
context,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
ActionNotifyBuilder builder = new ActionNotifyBuilder(context, resultPendingIntent)
.createBuilder();
for (Notification.Action action : actions){
builder.addAction(action);
}
builder.show(id);
}
示例13: getActionFromActionCompat
import android.app.Notification; //导入方法依赖的package包/类
private static Notification.Action getActionFromActionCompat(Action actionCompat) {
android.app.Notification.Action.Builder actionBuilder = new android.app.Notification.Action.Builder(actionCompat.getIcon(), actionCompat.getTitle(), actionCompat.getActionIntent()).addExtras(actionCompat.getExtras());
RemoteInputCompatBase.RemoteInput[] remoteInputCompats = actionCompat.getRemoteInputs();
if (remoteInputCompats != null) {
for (RemoteInput remoteInput : RemoteInputCompatApi20.fromCompat(remoteInputCompats)) {
actionBuilder.addRemoteInput(remoteInput);
}
}
return actionBuilder.build();
}
示例14: addActionEvent
import android.app.Notification; //导入方法依赖的package包/类
public ActionNotifyBuilder addActionEvent(Notification.Action action) {
this.addAction(action);
return this;
}
示例15: getActionCompatFromAction
import android.app.Notification; //导入方法依赖的package包/类
private static Action getActionCompatFromAction(Notification.Action action, Factory actionFactory, RemoteInputCompatBase.RemoteInput.Factory remoteInputFactory) {
return actionFactory.build(action.icon, action.title, action.actionIntent, action.getExtras(), RemoteInputCompatApi20.toCompat(action.getRemoteInputs(), remoteInputFactory));
}