本文整理汇总了Java中android.app.Notification.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Notification.Builder方法的具体用法?Java Notification.Builder怎么用?Java Notification.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notification
import android.app.Notification; //导入方法依赖的package包/类
public void notification(Context context) {
notif = new Notification.Builder(context);
notif.setSmallIcon(R.mipmap.ic_launcher);
int notificationId = new Random().nextInt();
notif.setContentTitle("Do you want to send battery level msg to others?");
Uri path = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notif.setSound(path);
nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
Intent yesReceive = new Intent();
yesReceive.putExtra("notificationId",notificationId);
yesReceive.setAction(AppConstant.YES_ACTION);
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(context, 12345, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT);
notif.addAction(R.drawable.ic_notifications, "Yes", pendingIntentYes);
Intent yesReceive2 = new Intent();
yesReceive.putExtra("notificationId",notificationId);
yesReceive2.setAction(AppConstant.STOP_ACTION);
PendingIntent pendingIntentYes2 = PendingIntent.getBroadcast(context, 12345, yesReceive2, PendingIntent.FLAG_UPDATE_CURRENT);
notif.addAction(R.drawable.ic_notifications, "No", pendingIntentYes2);
nm.notify(10, notif.getNotification());
}
示例2: showNotification
import android.app.Notification; //导入方法依赖的package包/类
/**
* Displays a notification with the location results.
*/
void showNotification() {
Intent notificationIntent = new Intent(mContext, MainActivity.class);
// Construct a task stack.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
// Add the main Activity to the task stack as the parent.
stackBuilder.addParentStack(MainActivity.class);
// Push the content Intent onto the stack.
stackBuilder.addNextIntent(notificationIntent);
// Get a PendingIntent containing the entire back stack.
PendingIntent notificationPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder notificationBuilder = new Notification.Builder(mContext)
.setContentTitle(getLocationResultTitle())
.setContentText(getLocationResultText())
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentIntent(notificationPendingIntent);
getNotificationManager().notify(0, notificationBuilder.build());
}
开发者ID:googlecodelabs,项目名称:background-location-updates-android-o,代码行数:29,代码来源:LocationResultHelper.java
示例3: onCreate
import android.app.Notification; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
//添加下列代码将后台Service变成前台Service
//构建"点击通知后打开MainActivity"的Intent对象
Intent notificationIntent = new Intent(this,MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
//新建Builer对象
Notification.Builder builer = new Notification.Builder(this);
builer.setContentTitle("前台服务通知的标题");//设置通知的标题
builer.setContentText("前台服务通知的内容");//设置通知的内容
builer.setSmallIcon(R.mipmap.ic_launcher);//设置通知的图标
builer.setContentIntent(pendingIntent);//设置点击通知后的操作
Notification notification = builer.getNotification();//将Builder对象转变成普通的notification
startForeground(1, notification);//让Service变成前台Service,并在系统的状态栏显示出来
}
示例4: selectNotofovatiomLevel
import android.app.Notification; //导入方法依赖的package包/类
private void selectNotofovatiomLevel(Notification.Builder builder) {
switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.rb_public:
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setContentText("public");
break;
case R.id.rb_private:
builder.setVisibility(Notification.VISIBILITY_PRIVATE);
builder.setContentText("private");
break;
case R.id.rb_secret:
builder.setVisibility(Notification.VISIBILITY_SECRET);
builder.setContentText("secret");
break;
default:
builder.setVisibility(Notification.VISIBILITY_PUBLIC);
builder.setContentText("public");
break;
}
}
示例5: onReceive
import android.app.Notification; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Notification.Builder notificationBuilder = new Notification.Builder(
context)
.setSmallIcon(android.R.drawable.alert_light_frame)
.setAutoCancel(true)
.setContentTitle("NOTÍCIAS NOVAS!")
.setContentText("Clique aqui para ver...")
.setVibrate(longVibracao);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1,notificationBuilder.build());
}
示例6: fixNotificationRemoteViews
import android.app.Notification; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void fixNotificationRemoteViews(Context pluginContext, Notification notification) {
Notification.Builder rebuild = null;
try {
rebuild = Reflect.on(Notification.Builder.class).create(pluginContext, notification).get();
} catch (Exception e) {
// ignore
}
if (rebuild != null) {
Notification renotification = rebuild.build();
if (notification.tickerView == null) {
notification.tickerView = renotification.tickerView;
}
if (notification.contentView == null) {
notification.contentView = renotification.contentView;
}
if (notification.bigContentView == null) {
notification.bigContentView = renotification.bigContentView;
}
if (notification.headsUpContentView == null) {
notification.headsUpContentView = renotification.headsUpContentView;
}
}
}
示例7: makeNotification
import android.app.Notification; //导入方法依赖的package包/类
/**
* Create a notification as the visible part to be able to put the service
* in a foreground state.
*
* @param settings The config settings
*/
private Notification makeNotification(JSONObject settings) {
String title = settings.optString("title", NOTIFICATION_TITLE);
String text = settings.optString("text", NOTIFICATION_TEXT);
boolean bigText = settings.optBoolean("bigText", false);
Context context = getApplicationContext();
String pkgName = context.getPackageName();
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(pkgName);
Notification.Builder notification = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(text)
.setOngoing(true)
.setSmallIcon(getIconResId(settings));
if (settings.optBoolean("hidden", true)) {
notification.setPriority(Notification.PRIORITY_MIN);
}
if (bigText || text.contains("\n")) {
notification.setStyle(
new Notification.BigTextStyle().bigText(text));
}
setColor(notification, settings);
if (intent != null && settings.optBoolean("resume")) {
PendingIntent contentIntent = PendingIntent.getActivity(
context, NOTIFICATION_ID, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(contentIntent);
}
return notification.build();
}
示例8: createNotificationBuilder
import android.app.Notification; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private Notification.Builder createNotificationBuilder() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return new Notification.Builder(context, CHANNEL_ID);
}
return new Notification.Builder(context);
}
示例9: sendNotification
import android.app.Notification; //导入方法依赖的package包/类
public static void sendNotification(final Context context,final String postfix,final String message){
final Notification.Builder mBuilder =
new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(context.getText(R.string.app_name)+" "+postfix)
.setContentText(message);
// Creates an explicit intent for an Activity in your app
final Intent resultIntent = new Intent(context, MainActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager!=null) {
// mId allows you to update the notification later on.
int mId = 0;
mNotificationManager.notify(mId, mBuilder.build());
Analytics.getInstance().logEvent(TAG, "sendNotification", "message");
}
}
示例10: build
import android.app.Notification; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Notification build(final Notification.Builder builder) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
// #build was added in API level 16, JELLY_BEAN
return (Notification) CompatUtils.invoke(builder, null, METHOD_build);
}
// #getNotification was deprecated in API level 16, JELLY_BEAN
return builder.getNotification();
}
示例11: NotifyUser
import android.app.Notification; //导入方法依赖的package包/类
public void NotifyUser(Bill bill, String title, String details) {
// TODO: make the builder member, built once only
Notification.Builder builder = new Notification.Builder(mContext);
builder.setContentTitle(title);
builder.setContentText(details);
builder.setSmallIcon(mContext.getApplicationInfo().icon);
Intent intent = new Intent(mActivity, BillActivity.class);
Bundle bundle = new Bundle();
bundle.putString("wallet_address", bill.getWalletID());
intent.putExtras(bundle);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(PayActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(intent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
builder.setContentIntent(resultPendingIntent);
Notification n = builder.build();
mNotificationManager.notify(++mLastNotificationID, n);
}
示例12: showAlarmNotification
import android.app.Notification; //导入方法依赖的package包/类
private void showAlarmNotification() {
Notification.Builder builder = new Notification.Builder(this);
builder.setPriority(Notification.PRIORITY_MAX).
setCategory(Notification.CATEGORY_ALARM).
setContentTitle(getString(R.string.app_name)).
setSmallIcon(R.drawable.ic_crockpod_mascot).
setStyle(new Notification.BigTextStyle().bigText(getString(R.string.alarm_notification_text)));
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(ALARM_NOTIFICATION_ID, builder.build());
}
示例13: updateNotification
import android.app.Notification; //导入方法依赖的package包/类
public static void updateNotification(Context context) {
ConnectionStatus status = connectionEngine.getConnectionStatus();
Notification.Builder builder = new Notification.Builder(context);
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentIntent(pendingIntent);
int iconId = R.drawable.ic_stat_discon;
String msg = "RepWifi";
if (status != null) {
if (status.isConnected()) {
iconId = R.drawable.ic_stat_repwifi;
msg += " - " + status.SSID;
} else {
msg += " - " + status.status;
}
}
builder.setSmallIcon(iconId);
builder.setContentTitle(msg);
builder.setContentText("Touch to open.");
Notification n = builder.build();
n.flags |= Notification.FLAG_NO_CLEAR;
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Service.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, n);
}
示例14: sendNomalNotification
import android.app.Notification; //导入方法依赖的package包/类
private void sendNomalNotification() {
Notification.Builder builder = new Notification.Builder(this);
Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://blog.csdn.net/itachi85/"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mIntent, 0);
builder.setContentIntent(pendingIntent);
builder.setSmallIcon(R.drawable.lanucher);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.lanucher));
builder.setAutoCancel(true);
builder.setContentTitle("普通通知");
selectNotofovatiomLevel(builder);
notificationManager.notify(0, builder.build());
}
示例15: getNotificationBuilder
import android.app.Notification; //导入方法依赖的package包/类
/**
* Gets Notification.Builder with 2 lines at BigPictureStyle notification text.
*
* @param context The application context.
* @param message Push notification Bundle.
* @param contentIntent PendingIntent.
* @param title String with title for push notification.
* @param messageText String with text for push notification.
* @param bigPicture Bitmap for BigPictureStyle notification.
* @param defaultNotificationIconResourceId int Resource id for default push notification icon.
* @return Notification.Builder or null.
*/
static Notification.Builder getNotificationBuilder(Context context, Bundle message,
PendingIntent contentIntent, String title, final String messageText, Bitmap bigPicture,
int defaultNotificationIconResourceId) {
if (Build.VERSION.SDK_INT < 16) {
return null;
}
Notification.Builder notificationBuilder =
getNotificationBuilder(context, message);
if (defaultNotificationIconResourceId == 0) {
notificationBuilder.setSmallIcon(context.getApplicationInfo().icon);
} else {
notificationBuilder.setSmallIcon(defaultNotificationIconResourceId);
}
notificationBuilder.setContentTitle(title)
.setContentText(messageText);
Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() {
@Override
protected RemoteViews getStandardView(int layoutId) {
RemoteViews remoteViews = super.getStandardView(layoutId);
// Modifications of stanxdard push RemoteView.
try {
int id = Resources.getSystem().getIdentifier("text", "id", "android");
remoteViews.setBoolean(id, "setSingleLine", false);
remoteViews.setInt(id, "setLines", 2);
if (Build.VERSION.SDK_INT < 23) {
// Make text smaller.
remoteViews.setViewPadding(id, 0, BIGPICTURE_TEXT_TOP_PADDING, 0, 0);
remoteViews.setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, BIGPICTURE_TEXT_SIZE);
}
} catch (Throwable throwable) {
Log.e("Cannot modify push notification layout.");
}
return remoteViews;
}
};
bigPictureStyle.bigPicture(bigPicture)
.setBigContentTitle(title)
.setSummaryText(message.getString(Constants.Keys.PUSH_MESSAGE_TEXT));
notificationBuilder.setStyle(bigPictureStyle);
if (Build.VERSION.SDK_INT >= 24) {
// By default we cannot reach getStandardView method on API>=24. I we call
// createBigContentView, Android will call getStandardView method and we can get
// modified RemoteView.
try {
RemoteViews remoteView = notificationBuilder.createBigContentView();
if (remoteView != null) {
// We need to set received RemoteView as a custom big content view.
notificationBuilder.setCustomBigContentView(remoteView);
}
} catch (Throwable t) {
Log.e("Cannot modify push notification layout.", t);
}
}
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(contentIntent);
return notificationBuilder;
}