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


Java NotificationCompat类代码示例

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


NotificationCompat类属于android.support.v4.app包,在下文中一共展示了NotificationCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showCertificateErrorNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
public void showCertificateErrorNotification(Account account, boolean incoming) {
    int notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming);
    Context context = controller.getContext();

    PendingIntent editServerSettingsPendingIntent = createContentIntent(context, account, incoming);
    String title = context.getString(R.string.notification_certificate_error_title, account.getDescription());
    String text = context.getString(R.string.notification_certificate_error_text);

    NotificationCompat.Builder builder = controller.createNotificationBuilder()
            .setSmallIcon(getCertificateErrorNotificationIcon())
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setTicker(title)
            .setContentTitle(title)
            .setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_ERROR);

    controller.configureNotification(builder, null, null,
            NOTIFICATION_LED_FAILURE_COLOR,
            NOTIFICATION_LED_BLINK_FAST, true);

    getNotificationManager().notify(notificationId, builder.build());
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:26,代码来源:CertificateErrorNotifications.java

示例2: backupFound

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void backupFound(){
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    if(jbBackupM.toString().trim().length()>0){
        Intent dialogIntent = new Intent(this, AddToContactList.class);
        dialogIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        dialogIntent.putExtra("data", jbBackupM.toString());
        PendingIntent intent = PendingIntent.getActivity(this, 0, dialogIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(intent);
    }
    mBuilder.setSmallIcon(R.drawable.ic_custom_notification);
    mBuilder.setAutoCancel(true);
    mBuilder.setContentTitle("Contact Sync!!");
    mBuilder.setContentText("You have lost some contact, we have backup");
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // notificationID allows you to update the notification later on.
    mNotificationManager.notify(notificaitonId, mBuilder.build());
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:19,代码来源:ContactSync.java

示例3: sendNotification

import android.support.v4.app.NotificationCompat; //导入依赖的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());
}
 
开发者ID:rahul051296,项目名称:quake-alert-android-app,代码行数:26,代码来源:MyFirebaseMessagingService.java

示例4: notificationMethod

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private Notification notificationMethod() {
    Notification notification;

    PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SHOW), 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getClass().getSimpleName())
            .setContentTitle("当前应用包名,点击查看详细")
            .setContentText(currentActivity.getCurrentActivity())
            .setContentIntent(pendingIntent)
            .setSmallIcon(R.mipmap.ic_launcher);

    Intent exitIntent = new Intent(this, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SERVICE_STOP);
    builder.addAction(R.drawable.ic_action_exit, getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));

    notification = builder.build();
    notification.flags |= Notification.FLAG_NO_CLEAR;

    return notification;
}
 
开发者ID:Omico,项目名称:CurrentActivity,代码行数:20,代码来源:FloatViewService.java

示例5: showIncognitoNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
/**
 * Shows the close all incognito notification.
 */
public static void showIncognitoNotification() {
    Context context = ContextUtils.getApplicationContext();
    String actionMessage =
            context.getResources().getString(R.string.close_all_incognito_notification);
    String title = context.getResources().getString(R.string.app_name);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setContentIntent(
                    IncognitoNotificationService.getRemoveAllIncognitoTabsIntent(context))
            .setContentText(actionMessage)
            .setOngoing(true)
            .setVisibility(Notification.VISIBILITY_SECRET)
            .setSmallIcon(R.drawable.incognito_statusbar)
            .setShowWhen(false)
            .setLocalOnly(true);
    NotificationManager nm =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID, builder.build());
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:24,代码来源:IncognitoNotificationManager.java

示例6: sendEvaluationNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void sendEvaluationNotification(){
    NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.trezentos_icon)
                    .setContentTitle("Avaliação")
                    .setContentText("Você tem avaliações à serem feitas!")
                    .setLargeIcon(BitmapFactory.decodeResource(getResources()
                            , R.drawable.trezentos_icon));

    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
}
 
开发者ID:fga-gpp-mds,项目名称:2017.1-Trezentos,代码行数:25,代码来源:ExamActivity.java

示例7: updateNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void updateNotification() {
    // Create a notification builder that's compatible with platforms >= version 4
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(getApplicationContext());

    // Set the title, text, and icon
    builder.setContentTitle(getString(R.string.app_name))
            .setSmallIcon(R.drawable.ic_step_icon);

    builder.setContentText("steps: " + StepsTaken.getSteps());

    // Get an instance of the Notification Manager
    NotificationManager notifyManager = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);

    // Build the notification and post it
    notifyManager.notify(0, builder.build());
}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:19,代码来源:WearStepService.java

示例8: sendNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
/**
 * Display the notification
 * @param body
 */
public void sendNotification(String body) {

	Intent intent = new Intent(this, MainActivity.class);
	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

	PendingIntent pendingIntent = PendingIntent.getActivity(this, 0/*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT);
	//Set sound of notification
	Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

	NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
		.setSmallIcon(R.mipmap.ic_bloeddonatie_logo_notification)
		.setContentTitle("Bloeddonatie")
		.setContentText(body)
		.setAutoCancel(true)
		.setSound(notificationSound)
		.setContentIntent(pendingIntent);

	NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
	notificationManager.notify(0 /*ID of notification*/, notifiBuilder.build());
}
 
开发者ID:team-htbr,项目名称:1617PROJ1Bloeddonatie-app,代码行数:25,代码来源:MyFirebaseMessagingService.java

示例9: sendNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, Main.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(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Automata")
                    .setContentText(messageBody)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
 
开发者ID:anonymous-ME,项目名称:Automata,代码行数:22,代码来源:FCM.java

示例10: showNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void showNotification() {
    NotificationManager mNotifyMgr =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    PendingIntent contentIntent = PendingIntent.getActivity(
            this, 1, new Intent(this, DrcomActivity.class), 0);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Dr.com正常运行中")
                    .setContentText("能看到我就说明有网络")
                    .setTicker("Dr.com运行中")
                    .setWhen(System.currentTimeMillis())
                    .setOngoing(false)      //用户无法滑动删除通知栏
                    .setContentIntent(contentIntent);
    Notification notification = mBuilder.build();
    startForeground(FOREGROUND_ID,notification);    //前台,防止被系统kill
    mNotifyMgr.notify(FOREGROUND_ID, notification);
}
 
开发者ID:WeGdufe,项目名称:MovingGdufe-Android,代码行数:19,代码来源:DrcomService.java

示例11: onHandleIntent

import android.support.v4.app.NotificationCompat; //导入依赖的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

示例12: sendMultilineNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void sendMultilineNotification(String title, String messageBody) {
    //Log.e("DADA", "ADAD---"+title+"---message---"+messageBody);
    int notificationId = 0;
    Intent intent = new Intent(this, MainDashboard.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_custom_notification)
            .setLargeIcon(largeIcon)
            .setContentTitle(title/*"Firebase Push Notification"*/)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(messageBody))
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationId, notificationBuilder.build());
}
 
开发者ID:mityung,项目名称:XERUNG,代码行数:24,代码来源:MyFirebaseMessagingService.java

示例13: showNotificationMessage

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
public void showNotificationMessage(String title, String message,
                                    String timeStamp, Intent intent) {
    if (TextUtils.isEmpty(message)) {
        return;
    }

    if (!CurrentUser.getInstance().isNotificationsOn()) {
        return;
    }

    int icon = R.mipmap.ic_launcher;
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(
                    context,
                    0,
                    intent,
                    PendingIntent.FLAG_CANCEL_CURRENT
            );
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context);
    showSmallNotification(notifBuilder, icon, title, message, timeStamp, resultPendingIntent);
}
 
开发者ID:ukevgen,项目名称:BizareChat,代码行数:23,代码来源:NotificationUtils.java

示例14: getServiceNotificationAction

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private static NotificationCompat.Action getServiceNotificationAction(Context context, String action, int iconResId, int titleResId) {
  Intent intent = new Intent(context, WebRtcCallService.class);
  intent.setAction(action);

  PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);

  return new NotificationCompat.Action(iconResId, context.getString(titleResId), pendingIntent);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:9,代码来源:CallNotificationBuilder.java

示例15: showNotification

import android.support.v4.app.NotificationCompat; //导入依赖的package包/类
private void showNotification(String title, String description, Intent intent) {
    String channelID = getNotificationChannelID();

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap largeNotificationImage = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelID)
            .setContentIntent(pendingIntent)
            .setContentTitle(title)
            .setContentText(description)
            .setDefaults(Notification.DEFAULT_ALL)
            .setLargeIcon(largeNotificationImage)
            .setSmallIcon(R.drawable.ic_logo);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        builder.setColor(ContextCompat.getColor(this, R.color.colorPrimary));

    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // Get the notification manager & publish the notification
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Constants.ID_NOTIFICATION_BROADCAST, notification);
}
 
开发者ID:Q115,项目名称:Goalie_Android,代码行数:26,代码来源:MessagingService.java


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