當前位置: 首頁>>代碼示例>>Java>>正文


Java NotificationManagerCompat.from方法代碼示例

本文整理匯總了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();
}
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:26,代碼來源:WaterReminderReceiver.java

示例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);
}
 
開發者ID:stephenmcgruer,項目名稱:three-things-today,代碼行數:21,代碼來源:NotificationIntentService.java

示例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);
}
 
開發者ID:jamesddube,項目名稱:LaravelNewsApp,代碼行數:35,代碼來源:Notify.java

示例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);
}
 
開發者ID:gregoreesmaa,項目名稱:minu-poska-android,代碼行數:40,代碼來源:NotificationService.java

示例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());
}
 
開發者ID:sciage,項目名稱:FinalProject,代碼行數:42,代碼來源:FCMReceiver.java

示例7: QHBNotificationManager

import android.support.v4.app.NotificationManagerCompat; //導入方法依賴的package包/類
public QHBNotificationManager(QHBService service) {
    mService = service;
    mNotificationManager = NotificationManagerCompat.from(service);

    //取消所有通知服務被殺和處理情況
    //重新啟動係統。
    mNotificationManager.cancel(NOTIFICATION_ID);
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:9,代碼來源:QHBNotificationManager.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:9,代碼來源:UpdateService.java

示例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();
  }
}
 
開發者ID:mapbox,項目名稱:mapbox-plugins-android,代碼行數:9,代碼來源:OfflineDownloadService.java

示例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);
    }
}
 
開發者ID:PacktPublishing,項目名稱:Android-Wear-Projects,代碼行數:41,代碼來源:MobileListener.java

示例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;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:16,代碼來源:MediaNotificationManager.java

示例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);
}
 
開發者ID:xiaofei-dev,項目名稱:Vibrator,代碼行數:32,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:gregoreesmaa,項目名稱:minu-poska-android,代碼行數:36,代碼來源:NotificationService.java

示例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);
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:6,代碼來源:NotificationController.java

示例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());
}
 
開發者ID:boybeak,項目名稱:NotificationStyles,代碼行數:5,代碼來源:MainActivity.java


注:本文中的android.support.v4.app.NotificationManagerCompat.from方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。