本文整理汇总了Java中android.support.v4.app.NotificationManagerCompat.from方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationManagerCompat.from方法的具体用法?Java NotificationManagerCompat.from怎么用?Java NotificationManagerCompat.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.NotificationManagerCompat
的用法示例。
在下文中一共展示了NotificationManagerCompat.from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Intent intent2 = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setAutoCancel(true) //Automatically delete the notification
.setSmallIcon(R.drawable.water_bottle_flat) //Notification icon
.setContentIntent(pendingIntent)
.setContentTitle("Time to hydrate")
.setContentText("Drink a glass of water now")
.setCategory(Notification.CATEGORY_REMINDER)
.setPriority(Notification.PRIORITY_HIGH)
.setSound(defaultSoundUri);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(0, notificationBuilder.build());
Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show();
}
示例2: MediaNotificationManager
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public MediaNotificationManager(AudioPlayerService service) throws RemoteException {
mService = service;
updateSessionToken();
mNotificationManager = NotificationManagerCompat.from(service);
String pkg = mService.getPackageName();
mPauseIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
new Intent(ACTION_PAUSE).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
mPlayIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
new Intent(ACTION_PLAY).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
mPreviousIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
new Intent(ACTION_PREV).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
mNextIntent = PendingIntent.getBroadcast(mService, REQUEST_CODE,
new Intent(ACTION_NEXT).setPackage(pkg), PendingIntent.FLAG_CANCEL_CURRENT);
// Cancel all notifications to handle the case where the Service was killed and
// restarted by the system.
mNotificationManager.cancelAll();
}
开发者ID:AllThatSeries,项目名称:react-native-streaming-audio-player,代码行数:21,代码来源:MediaNotificationManager.java
示例3: onHandleIntent
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
// TODO(smcgruer): Skip if today is already done.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("Three Things Today")
.setContentText("Record what happened today!")
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setSmallIcon(R.drawable.ic_stat_name);
Intent notifyIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
Notification notificationCompat = builder.build();
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
managerCompat.notify(NOTIFICATION_ID, notificationCompat);
}
示例4: showNewPostNotifications
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public static void showNewPostNotifications(){
if (!Prefs.NotificationsEnabled()){
return;
}
notificationPosts = PostRepository.getUnSeen();
android.support.v4.app.NotificationCompat.InboxStyle inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle();
for(Post post : notificationPosts){
inboxStyle.addLine(post.getTitle());
}
//Notification sound
SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(App.getAppContext());
String strRingtonePreference = preference.getString("notifications_new_message_ringtone", "DEFAULT_SOUND");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(App.getAppContext());
mBuilder.setSmallIcon(R.drawable.ic_notifications)
.setColor(App.getAppContext().getResources().getColor(R.color.brandColor))
.setSound(Uri.parse(strRingtonePreference))
.setAutoCancel(true)
.setContentTitle("Laravel News")
.setContentText(getSummaryMessage())
.setContentIntent(getNotificationIntent())
.setStyle(inboxStyle)
.setGroup("LNA_NOTIFICATIONS_GROUP");
//Check the vibrate
if(Prefs.NotificationVibrateEnabled()){
mBuilder.setVibrate(new long[] {1000,1000});
}
Notification notification = mBuilder.build();
// Issue the group notification
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(App.getAppContext());
notificationManager.notify(1, notification);
}
示例5: handleShowHomework
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
/**
* Handle action to show homework notification in the provided background thread with the provided
* parameters.
*/
private void handleShowHomework(String[] subjects) {
if (subjects == null)
return;
// This can be changed to show detailed homework, if needed
// Prepare target activity
Intent intent = new Intent(this, DataUtils.isTablet(this) ? EventsAndAssignmentsActivity.class : AssignmentsActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
String subjectsstr = "";
for (String subject : subjects) {
if (!subjectsstr.isEmpty())
subjectsstr += ", ";
subjectsstr += subject;
}
Log.d(TAG, "Showing homework notification: " + subjectsstr);
// Prepare lesson notification text
String homeworkcontent;
if (subjects.length == 1)
homeworkcontent = getString(R.string.homework_notification_1, subjectsstr);
else homeworkcontent = getString(R.string.homework_notification_n, subjectsstr);
Notification n = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.homework_notification_title))
.setContentText(homeworkcontent)
.setSmallIcon(R.drawable.ic_assignment_black_24dp)
.setContentIntent(pIntent)
.setOngoing(true)
.setAutoCancel(false)
.setGroupSummary(false)
.setShowWhen(false)
.setGroup(NOTIFICATION_SCHOOLINFO)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify("homework", 1, n);
}
示例6: showChatNotification
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void showChatNotification(String messageBody, RemoteMessage remoteMessage) {
/*
Creates pending intent
*/
Intent intent = new Intent();
intent.setAction("in.voiceme.app.voiceme.CHAT");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("fromNotification", true);
PendingIntent pendingIntent =
PendingIntent.getActivity(
this, 1 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// builder.setGroup(remoteNotification.getUserNotificationGroup());
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(messageBody)
.setContentText("View the message inside Voiceme")
.setAutoCancel(true)
.setGroup(remoteMessage.getNotification().getTag())
.setSound(defaultSoundUri)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentIntent(pendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
long time = System.currentTimeMillis();
String tmpStr = String.valueOf(time);
String last4Str = tmpStr.substring(tmpStr.length() - 5);
int notificationId = Integer.valueOf(last4Str);
notificationManager.notify(notificationId /* ID of notification */,
notificationBuilder.build());
}
示例7: QHBNotificationManager
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public QHBNotificationManager(QHBService service) {
mService = service;
mNotificationManager = NotificationManagerCompat.from(service);
//取消所有通知服务被杀和处理情况
//重新启动系统。
mNotificationManager.cancel(NOTIFICATION_ID);
}
示例8: UpdateDownloadCallback
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public UpdateDownloadCallback(Service context, File file, UpdateInfo info, Builder
builder) {
this.context = context;
this.downloadFile = file;
this.info = info;
this.mNotificationManager = NotificationManagerCompat.from(context);
this.mBuilder = builder;
}
示例9: onCreate
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
notificationManager = NotificationManagerCompat.from(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setupNotificationChannel();
}
}
示例10: onMessageReceived
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals("/heart")) {
final String message = new String(messageEvent.getData());
Log.v("myTag", "Message path received on watch is: " + messageEvent.getPath());
Log.v("myTag", "Message received on watch is: " + message);
// Broadcast message to wearable activity for display
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
messageIntent.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
Intent intent2 = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent2,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
.setAutoCancel(true) //Automatically delete the notification
.setSmallIcon(R.drawable.ic_heart_icon) //Notification icon
.setContentIntent(pendingIntent)
.setContentTitle("Open upbeat")
.setContentText("UpBeat to check the pulse")
.setCategory(Notification.CATEGORY_REMINDER)
.setPriority(Notification.PRIORITY_HIGH)
.setSound(defaultSoundUri);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());
notificationManager.notify(0, notificationBuilder.build());
}
else {
super.onMessageReceived(messageEvent);
}
}
示例11: clearNotification
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
private void clearNotification() {
if (mMediaNotificationInfo == null) return;
NotificationManagerCompat manager = NotificationManagerCompat.from(mContext);
manager.cancel(mMediaNotificationInfo.id);
if (mMediaSession != null) {
mMediaSession.setCallback(null);
mMediaSession.setActive(false);
mMediaSession.release();
mMediaSession = null;
}
mContext.stopService(createIntent(mContext));
mMediaNotificationInfo = null;
}
示例12: sendNotification
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
private void sendNotification(){
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Intent i = new Intent(this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(this, 0, i,
PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews = new RemoteViews(getPackageName(), R.layout.notification);
PendingIntent contral = PendingIntent.getBroadcast(this, 0,
new Intent("com.github.xiaofei_dev.vibrator.action"),
PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews.setOnClickPendingIntent(R.id.action,contral);
PendingIntent close = PendingIntent.getBroadcast(this,1,
new Intent("com.github.xiaofei_dev.vibrator.close"),
PendingIntent.FLAG_UPDATE_CURRENT);
mRemoteViews.setOnClickPendingIntent(R.id.close,close);
builder.setContentIntent(intent)
.setSmallIcon(R.drawable.ic_vibration)
.setOngoing(true)
.setContent(mRemoteViews)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX);
nm = NotificationManagerCompat.from(this);
notification = builder.build();
nm.notify(0, notification);
}
示例13: handleNotifyGrade
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
/**
* Handle action to notify about a new grade in the provided background thread with the provided
* parameters.
*/
private void handleNotifyGrade(String value, String comment, String subject, String description, int id) {
Log.d(TAG, "Notifying of grade: " + value + " in " + subject);
// Prepare target activity
Intent intent = new Intent(this, DataUtils.isTablet(this) ? EventsAndAssignmentsActivity.class : EventsActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// Prepare event notification text
String eventtitle;
String eventcontent;
if (value != null) {
if (comment != null) eventtitle = value + " / " + comment + " [" + subject + "]";
else eventtitle = value + " [" + subject + "]";
} else if (comment != null) eventtitle = comment + " [" + subject + "]";
else eventtitle = getString(R.string.app_name);
if (description != null) eventcontent = description;
else eventcontent = null;
Notification n = new NotificationCompat.Builder(this)
.setContentTitle(eventtitle)
.setContentText(eventcontent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(description))
.setSmallIcon(R.drawable.ic_assessment_black_24dp)
.setContentIntent(pIntent)
.setAutoCancel(true)
//.setGroupSummary(true)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify("event", id, n);
}
示例14: newInstance
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public static NotificationController newInstance(Context context) {
Context appContext = context.getApplicationContext();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(appContext);
return new NotificationController(appContext, notificationManager);
}
示例15: showNotificationCompat
import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
private void showNotificationCompat (NotificationCompat.Builder builder) {
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(1, builder.build());
}