当前位置: 首页>>代码示例>>Java>>正文


Java NotificationManagerCompat.notify方法代码示例

本文整理汇总了Java中android.support.v4.app.NotificationManagerCompat.notify方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationManagerCompat.notify方法的具体用法?Java NotificationManagerCompat.notify怎么用?Java NotificationManagerCompat.notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.NotificationManagerCompat的用法示例。


在下文中一共展示了NotificationManagerCompat.notify方法的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: sendNotification

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
private void sendNotification(String title, String content) {

        // this intent will open the activity when the user taps the "open" action on the notification
        Intent viewIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingViewIntent = PendingIntent.getActivity(this, 0, viewIntent, 0);

        // this intent will be sent when the user swipes the notification to dismiss it
        Intent dismissIntent = new Intent(ZabbkitConstants.NOTIFICATION_DISMISS);
        PendingIntent pendingDeleteIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(title)
                .setContentText(content)
                .setGroup(GROUP_KEY)
                .setDeleteIntent(pendingDeleteIntent)
                .setContentIntent(pendingViewIntent);

        Notification notification = builder.build();

        NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
        notificationManagerCompat.notify(notificationId++, notification);
    }
 
开发者ID:CactusSoft,项目名称:zabbkit-android,代码行数:24,代码来源:NotificationUpdateService.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: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context c, Intent i) {
    Log.i(TAG, "received result: " + getResultCode());
    if (getResultCode() != Activity.RESULT_OK) {
        // A foreground activity cancelled the broadcast
        return;
    }

    int requestCode = i.getIntExtra(PollService.REQUEST_CODE, 0);
    Notification notification = (Notification)
            i.getParcelableExtra(PollService.NOTIFICATION);

    NotificationManagerCompat notificationManager = 
            NotificationManagerCompat.from(c);
    notificationManager.notify(requestCode, notification);
}
 
开发者ID:rsippl,项目名称:AndroidProgramming3e,代码行数:17,代码来源:NotificationReceiver.java

示例5: 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

示例6: 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

示例7: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (getResultCode() != Activity.RESULT_OK) {
        return;
    }

    int requestCode = intent.getIntExtra(PollService.REQUEST_CODE, 0);
    Notification notification = intent.getParcelableExtra(PollService.NOTIFICATION);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(requestCode, notification);
}
 
开发者ID:ivicel,项目名称:Android-Programming-BigNerd,代码行数:12,代码来源:NotificationReceiver.java

示例8: CreateCameraNotification

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public void CreateCameraNotification(
        int notificationId,
        @NonNull Class<?> receiverActivity) {

    if (!_settingsController.IsCameraNotificationEnabled()) {
        Logger.getInstance().Warning(TAG, "Not allowed to display camera notification!");
        return;
    }

    Bitmap bitmap = BitmapFactory.decodeResource(_context.getResources(), R.drawable.camera);
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().setHintHideIcon(true).setBackground(bitmap);
    RemoteViews remoteViews = new RemoteViews(_context.getPackageName(), R.layout.notification_camera);

    // Action for button show camera
    Intent goToSecurityIntent = new Intent(_context, receiverActivity);
    PendingIntent goToSecurityPendingIntent = PendingIntent.getActivity(_context, 34678743, goToSecurityIntent, 0);
    NotificationCompat.Action goToSecurityWearAction = new NotificationCompat.Action.Builder(R.drawable.camera, "Go to security", goToSecurityPendingIntent).build();

    remoteViews.setOnClickPendingIntent(R.id.goToSecurity, goToSecurityPendingIntent);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(_context);
    builder.setSmallIcon(R.drawable.camera)
            .setContentTitle("Camera is active!")
            .setContentText("Go to security!")
            .setTicker("")
            .extend(wearableExtender)
            .addAction(goToSecurityWearAction);

    Notification notification = builder.build();
    notification.contentView = remoteViews;
    notification.bigContentView = remoteViews;

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(_context);
    notificationManager.notify(notificationId, notification);
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:36,代码来源:NotificationController.java

示例9: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (getResultCode() != Activity.RESULT_OK) {
        return;
    }

    int requestCode = intent.getIntExtra(UpdateService.CODE_REQUEST, 0);
    Notification notification = (Notification) intent.getParcelableExtra(UpdateService.NOTIFICATION);

    NotificationManagerCompat nmc = NotificationManagerCompat.from(context);
    nmc.notify(requestCode, notification);
}
 
开发者ID:KnowledgeBegger,项目名称:MyEyepetizer,代码行数:13,代码来源:ShowNotification.java

示例10: onReceive

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "Receive result with code - " + getResultCode());
    if (getResultCode() != Activity.RESULT_OK){
        return;
    }

    int reqCode = intent.getIntExtra(IndividualService.REQ_CODE, 0);
    Notification notification = intent.getParcelableExtra(IndividualService.NOTIFICATION);

    NotificationManagerCompat compat = NotificationManagerCompat.from(context);
    compat.notify(reqCode, notification);
}
 
开发者ID:aumarbello,项目名称:Tasks,代码行数:14,代码来源:IndividualReceiver.java

示例11: 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

示例12: 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

示例13: 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

示例14: generateNotification

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public void generateNotification()
{
    int notificationId = 001;

    Intent notificationIntent=new Intent(context,NotificationActivity.class);
    notificationIntent.putExtra("", "");
    PendingIntent viewPendingIntent =
            PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.notification_warning)
                    .setContentTitle(title)
                    .setContentText(content)
                    .setContentIntent(viewPendingIntent)
                    .setDefaults(Notification.DEFAULT_ALL)
            ;

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(context);

    // Issue the notification with notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
}
 
开发者ID:kflauri2312lffds,项目名称:Android_watch_magpie,代码行数:26,代码来源:NotificationGenerator.java

示例15: sendReminderNotification

import android.support.v4.app.NotificationManagerCompat; //导入方法依赖的package包/类
public void sendReminderNotification(String label) {
        String notificationTitle = label + " " + "\u23f0";
        String[] arrayString = context.getResources().getStringArray(R.array.reminder_title_array);
        String notificationText = arrayString[generateRandomNumber(0, 1)];
        //String NOTIFICATION_ACTION = context.getString(R.string.reminders_notification_action);

        Intent intent = new Intent(context, AddGlucoseActivity.class);
        intent.putExtra("glucose_reminder_notification", true);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        Notification.Builder notificationBuilder;
/*
        // ADD LATER TO SUPPORT NOUGAT DIRECT REPLY
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            RemoteInput remoteInput = new RemoteInput.Builder(REMOTE_INPUT_KEY)
                    .setLabel(NOTIFICATION_ACTION)
                    .build();

            Notification.Action actionNotification = new Notification.Action.Builder(
                    R.drawable.ic_stat_glucosio,
                    NOTIFICATION_ACTION, pendingIntent)
                    .addRemoteInput(remoteInput)
                    .build();

            notification = new Notification.Builder(context)
                    .setContentTitle("\u23f0")
                    .setContentText(NOTIFICATION_TEXT)
                    .setSmallIcon(R.drawable.ic_stat_glucfosio)
                    .setColor(context.getColor(R.color.glucosio_pink))
                    .setActions(actionNotification)
                    .build();
        } else {*/
        notificationBuilder = new Notification.Builder(context)
                .setContentTitle(notificationTitle)
                .setContentText(notificationText)
                .setAutoCancel(true)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setVibrate(new long[]{1000, 1000})
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.drawable.ic_stat_glucosio);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            notificationBuilder.setColor(context.getColor(R.color.glucosio_pink));
        }

        Notification notification = notificationBuilder.build();
        NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
        notificationManagerCompat.notify(NOTIFICATION_ID, notification);
    }
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:50,代码来源:GlucosioNotificationManager.java


注:本文中的android.support.v4.app.NotificationManagerCompat.notify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。