本文整理汇总了Java中android.app.NotificationManager.notify方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationManager.notify方法的具体用法?Java NotificationManager.notify怎么用?Java NotificationManager.notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.NotificationManager
的用法示例。
在下文中一共展示了NotificationManager.notify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
private void showNotification(long cancelTime, String text) {
try {
Context app = getContext().getApplicationContext();
NotificationManager nm = (NotificationManager) app
.getSystemService(Context.NOTIFICATION_SERVICE);
final int id = Integer.MAX_VALUE / 13 + 1;
nm.cancel(id);
long when = System.currentTimeMillis();
Notification notification = new Notification(notifyIcon, text, when);
PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(), 0);
notification.setLatestEventInfo(app, notifyTitle, text, pi);
notification.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify(id, notification);
if (cancelTime > 0) {
Message msg = new Message();
msg.what = MSG_CANCEL_NOTIFY;
msg.obj = nm;
msg.arg1 = id;
UIHandler.sendMessageDelayed(msg, cancelTime, this);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: sendNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, QuakeActivity.class);//**The activity that you want to open when the notification is clicked
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_error_outline_white_24dp)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
示例3: sendNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int requestCode = 0;
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_action_name)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = 0;
notificationManager.notify(notificationId, notificationBuilder.build());
}
示例4: sendNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
private void sendNotification(String title, String messageBody, int notificationId) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo_white)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notificationBuilder.build());
}
示例5: reminder
import android.app.NotificationManager; //导入方法依赖的package包/类
void reminder()
{
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.sos);
mBuilder.setContentTitle("Reminder !");
mBuilder.setContentText(reminder_text);
Intent resultIntent = new Intent(this, Location_event.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(Location_event.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);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(0, mBuilder.build());
}
示例6: onMessageReceived
import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
Intent intent = new Intent(this , MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this , 0 , intent , PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_action_notification)
.setContentTitle("Cü Yemek")
.setContentText("Yemek Listesi Yayımlandı.")
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
vib.vibrate(500);
}
示例7: showNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
public void showNotification(){
NotificationCompat.Builder mBuilder;
NotificationManager mNotifyMgr =(NotificationManager) contexto.getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
int icono = R.mipmap.ic_launcher;
Intent intent = new Intent(contexto, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(contexto, 0,intent, 0);
mBuilder =new NotificationCompat.Builder(contexto.getApplicationContext())
.setContentIntent(pendingIntent)
.setSmallIcon(icono)
.setContentTitle("Warning!")
.setContentText("Eres parte de una BOTNET!")
.setVibrate(new long[] {100, 250, 100, 500})
.setAutoCancel(true);
mNotifyMgr.notify(1, mBuilder.build());
}
示例8: create
import android.app.NotificationManager; //导入方法依赖的package包/类
public static Drive create(Context context) throws IOException, GoogleAuthException, ImportExportException {
String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
if (googleDriveAccount == null) {
throw new ImportExportException(R.string.google_drive_account_required);
}
try {
List<String> scope = new ArrayList<String>();
scope.add(DriveScopes.DRIVE_FILE);
if (MyPreferences.isGoogleDriveFullReadonly(context)) {
scope.add(DriveScopes.DRIVE_READONLY);
}
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
credential.setSelectedAccountName(googleDriveAccount);
credential.getToken();
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
} catch (UserRecoverableAuthException e) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent authorizationIntent = e.getIntent();
authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
authorizationIntent, 0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setTicker(context.getString(R.string.google_drive_permission_requested))
.setContentTitle(context.getString(R.string.google_drive_permission_requested))
.setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
.setContentIntent(pendingIntent).setAutoCancel(true).build();
notificationManager.notify(0, notification);
throw new ImportExportException(R.string.google_drive_permission_required);
}
}
示例9: showUpdateNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
private void showUpdateNotification() {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = MainActivity.createIntent(this, false);
PendingIntent intent = PendingIntent.getActivity(this, 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notBuilder = getBasetNotification();
notBuilder.setContentTitle(getString(R.string.newUpdateNotificationText))
.setContentText(getString(R.string.newUpdateNotificationContentText))
.setContentIntent(intent);
nm.notify(NOTID, notBuilder.build());
}
示例10: updateBlogPostNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
@UiThread
private void updateBlogPostNotification() {
if (blogTotal == 0) {
clearBlogPostNotification();
} else if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) {
NotificationCompat.Builder b =
new NotificationCompat.Builder(appContext);
b.setSmallIcon(R.drawable.notification_blog);
b.setColor(ContextCompat.getColor(appContext,
R.color.briar_primary));
b.setContentTitle(appContext.getText(R.string.app_name));
b.setContentText(appContext.getResources().getQuantityString(
R.plurals.blog_post_notification_text, blogTotal,
blogTotal));
String ringtoneUri = settings.get(PREF_NOTIFY_RINGTONE_URI);
if (!StringUtils.isNullOrEmpty(ringtoneUri))
b.setSound(Uri.parse(ringtoneUri));
b.setDefaults(getDefaults());
b.setOnlyAlertOnce(true);
b.setAutoCancel(true);
// Touching the notification shows the combined blog feed
Intent i = new Intent(appContext, NavDrawerActivity.class);
i.putExtra(INTENT_BLOGS, true);
i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
i.setData(Uri.parse(BLOG_URI));
TaskStackBuilder t = TaskStackBuilder.create(appContext);
t.addParentStack(NavDrawerActivity.class);
t.addNextIntent(i);
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
if (Build.VERSION.SDK_INT >= 21) {
b.setCategory(CATEGORY_SOCIAL);
b.setVisibility(VISIBILITY_SECRET);
}
Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o;
nm.notify(BLOG_POST_NOTIFICATION_ID, b.build());
}
}
示例11: createNotification
import android.app.NotificationManager; //导入方法依赖的package包/类
/**
* Cancels the notification.
* @param outdir name of the output dir
*/
private void createNotification(String outdir) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
upnpClient.getContext()).setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Yaacc file download")
.setContentText("download to: " + outdir );
NotificationManager mNotificationManager = (NotificationManager) upnpClient.getContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(NotificationId.FILE_DOWNLOADER.getId(), mBuilder.build());
}
示例12: remindUserBecauseCharging
import android.app.NotificationManager; //导入方法依赖的package包/类
public static void remindUserBecauseCharging(Context context) {
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
WATER_REMINDER_NOTIFICATION_CHANNEL_ID,
context.getString(R.string.main_notification_channel_name),
NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,WATER_REMINDER_NOTIFICATION_CHANNEL_ID)
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
.setSmallIcon(R.drawable.ic_drink_notification)
.setLargeIcon(largeIcon(context))
.setContentTitle(context.getString(R.string.charging_reminder_notification_title))
.setContentText(context.getString(R.string.charging_reminder_notification_body))
.setStyle(new NotificationCompat.BigTextStyle().bigText(
context.getString(R.string.charging_reminder_notification_body)))
.setDefaults(Notification.DEFAULT_VIBRATE)
.setContentIntent(contentIntent(context))
.addAction(drinkWaterAction(context))
.addAction(ignoreReminderAction(context))
.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
}
notificationManager.notify(WATER_REMINDER_NOTIFICATION_ID, notificationBuilder.build());
}
示例13: onReceive
import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String title = intent.getStringExtra(TITLE);
int id = intent.getIntExtra(ID, 0);
int color = R.color.colorPrimary;
int largeIcon = R.mipmap.ic_launcher;
switch (intent.getIntExtra(PRIORITY, 0)) {
case Task.PRIORITY_LOW:
color = R.color.colorGreen;
largeIcon = R.mipmap.ic_active_low;
break;
case Task.PRIORITY_NORMAL:
color = R.color.colorYellow;
largeIcon = R.mipmap.ic_active;
break;
case Task.PRIORITY_HIGH:
color = R.color.colorRed;
largeIcon = R.mipmap.ic_active_high;
break;
}
Intent service = new Intent(context, UnforgetItActivity.class);
if (UnforgetItActivity.sActivityVisible) {
service = intent;
}
service.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, id, service, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.notification_title))
.setContentText(title)
.setColor(ContextCompat.getColor(context, color))
.setSmallIcon(R.drawable.ic_access_alarm_white_24dp)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(title))
.build();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Log.d(this.getClass().getName(), "Send " + notification.toString());
notificationManager.notify(id, notification);
}
示例14: onBlocksDownloaded
import android.app.NotificationManager; //导入方法依赖的package包/类
/**
*
* @param coin
* @param pct
* @param blocksSoFar
* @param date
*/
@Override
public void onBlocksDownloaded(CurrencyCoin coin, double pct, int blocksSoFar, Date date) {
String text = "Syncing : " + pct + " %";
Notification notification = getServiceNotification(text);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_SYNC_ID, notification);
BlockDownloaded blockDownloaded = new BlockDownloaded(coin, pct, blocksSoFar, date);
Message toReply = Message.obtain(null, IPC_MSG_WALLET_BLOCK_DOWNLOADED);
toReply.getData().putString(IPC_BUNDLE_DATA_KEY, _gson.toJson(blockDownloaded));
replyMessage(toReply);
}
示例15: sendAlert
import android.app.NotificationManager; //导入方法依赖的package包/类
private static void sendAlert(int stringResId, int _id, String name, Context context) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
int notificationid = _id + stringResId;
boolean isShowing = isNotificationVisible(context, notificationid);
NotificationCompat.Builder notification;
if (!isShowing) {
notification
= new NotificationCompat.Builder(context)
.setContentTitle(name)
.setSmallIcon(R.mipmap.ic_launcher_small)
.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_DEFAULT)
.setLargeIcon(bitmap);
NotificationManager NotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
NotifyMgr.notify(notificationid, notification.build());
}
}