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


Java NotificationCompat.Builder方法代码示例

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


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

示例1: buildNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
private void buildNotification() {


        boolean isLollipop = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
        int smallIcon = getResources().getIdentifier("notification_small_icon", "drawable", getPackageName());

        if (smallIcon <= 0 || !isLollipop) {
            smallIcon = getApplicationInfo().icon;
        }

        manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(getString(R.string.update_app_model_prepare))
                .setWhen(System.currentTimeMillis())
                .setProgress(100, 1, false)
        .setSmallIcon(smallIcon)
        .setLargeIcon(BitmapFactory.decodeResource(
                          getResources(), icoResId))
        .setDefaults(downloadNotificationFlag);

        manager.notify(notifyId, builder.build());
    }
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:23,代码来源:UpdateService.java

示例2: initializeBackgroundNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
private NotificationCompat.Builder initializeBackgroundNotification() {
  NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon_notification));
  builder.setContentTitle(getString(R.string.ApplicationMigrationService_importing_text_messages));
  builder.setContentText(getString(R.string.ApplicationMigrationService_import_in_progress));
  builder.setOngoing(true);
  builder.setProgress(100, 0, false);
  builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ConversationListActivity.class), 0));

  stopForeground(true);
  startForeground(4242, builder.build());

  return builder;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:ApplicationMigrationService.java

示例3: setNotificationText

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
private void setNotificationText(NotificationCompat.Builder builder)
{
    final Resources res = getResources();
    
    final long now = SystemClock.elapsedRealtime();
    final long lastTestDelta = loopModeResults.getLastTestTime() == 0 ? 0 : now - loopModeResults.getLastTestTime();
    
    final String elapsedTimeString = LoopModeTriggerItem.formatSeconds(Math.round(lastTestDelta / 1000), 1);
    
    final CharSequence textTemplate = res.getText(R.string.loop_notification_text_without_stop);
    final CharSequence text = MessageFormat.format(textTemplate.toString(), 
    		loopModeResults.getNumberOfTests(), elapsedTimeString, Math.round(loopModeResults.getLastDistance()));
    builder.setContentText(text);
    
    if (bigTextStyle == null)
    {
        bigTextStyle = (new NotificationCompat.BigTextStyle());
        builder.setStyle(bigTextStyle);
    }
    
    bigTextStyle.bigText(text);
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:23,代码来源:RMBTLoopService.java

示例4: DownloadNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
/**
 * Constructor
 *
 * @param ctx The context to use to obtain access to the Notification
 *            Service
 */
DownloadNotification(Context ctx, CharSequence applicationLabel) {
    mState = -1;
    mContext = ctx;
    mLabel = applicationLabel;
    mNotificationManager = (NotificationManager)
            mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mActiveDownloadBuilder = new V4CustomNotificationBuilder(ctx);
    } else {
        mActiveDownloadBuilder = new NotificationCompat.Builder(ctx);
    }
    mBuilder = new NotificationCompat.Builder(ctx);

    // Set Notification category and priorities to something that makes sense for a long
    // lived background task.
    mActiveDownloadBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
    mActiveDownloadBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS);

    mBuilder.setPriority(NotificationCompat.PRIORITY_LOW);
    mBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS);

    mCurrentBuilder = mBuilder;
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:30,代码来源:DownloadNotification.java

示例5: onMessageReceived

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSmallIcon(R.drawable.logo);
    mBuilder.setContentTitle(remoteMessage.getNotification().getTitle());
    mBuilder.setContentText(remoteMessage.getNotification().getBody());
    Intent i = new Intent(this,MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.putExtra("from","iside");
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(79, mBuilder.build());

}
 
开发者ID:picopalette,项目名称:event-me,代码行数:19,代码来源:MyFirebaseMessagingService.java

示例6: showNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
protected void showNotification(String notificationText) {
    // TODO Auto-generated method stub
    NotificationCompat.Builder build = new NotificationCompat.Builder(
            activity);
    build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
    build.setContentTitle(notificationText);
    build.setContentText(activity.getString(R.string.notifications_notification_received_from_1sheeld));
    build.setTicker(notificationText);
    build.setWhen(System.currentTimeMillis());
    Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show();
    Vibrator v = (Vibrator) activity
            .getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);
    Intent notificationIntent = new Intent(activity, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(activity, 0,
            notificationIntent, 0);
    build.setContentIntent(intent);
    Notification notification = build.build();
    NotificationManager notificationManager = (NotificationManager) activity
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(2, notification);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:25,代码来源:NotificationShield.java

示例7: getNotificationBuilder

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
public NotificationCompat.Builder getNotificationBuilder(String title, String content) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            getApplicationContext());
    builder.setContentText(content);
    builder.setContentTitle(title);
    builder.setSmallIcon(R.drawable.ic_stat_kangaroo);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    builder.setAutoCancel(true);
    return builder;
}
 
开发者ID:838030195,项目名称:DaiGo,代码行数:11,代码来源:NotificationUtil.java

示例8: makeActivityBuilder

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
public static NotificationCompat.Builder makeActivityBuilder(int iconRes, CharSequence title,
                                                             CharSequence text,
                                                             Class<?> activityClass,
                                                             Context context) {
    return makeActivityBuilder(iconRes, title, text, new Intent(context, activityClass),
            context);
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:8,代码来源:NotificationUtils.java

示例9: createIdentificationNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
/**
 * Show an emotion analysis notification.
 *
 * @param ctx the application context
 */
public static void createIdentificationNotification(@NonNull final Context ctx, final int condition,
                                                    final boolean success, @Nullable final Speaker.Confidence confidence) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "createIdentificationNotification");
    }

    try {

        final Intent actionIntent = new Intent(NotificationService.INTENT_CLICK);
        actionIntent.setPackage(ctx.getPackageName());
        actionIntent.putExtra(NotificationService.CLICK_ACTION,
                NotificationService.NOTIFICATION_IDENTIFICATION);
        actionIntent.putExtra(LocalRequest.EXTRA_CONDITION, condition);

        switch (condition) {

            case Condition.CONDITION_IDENTIFY:
                actionIntent.putExtra(Speaker.EXTRA_IDENTIFY_OUTCOME, confidence);
                break;
            case Condition.CONDITION_IDENTITY:
                actionIntent.putExtra(Speaker.EXTRA_IDENTITY_OUTCOME, success);
                break;
        }

        final PendingIntent pendingIntent = PendingIntent.getService(ctx,
                NotificationService.NOTIFICATION_IDENTIFICATION,
                actionIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, NOTIFICATION_CHANNEL_INFORMATION);

        builder.setContentIntent(pendingIntent).setSmallIcon(android.R.drawable.ic_menu_info_details)
                .setTicker(ctx.getString(R.string.vocal_notification_ticker)).setWhen(System.currentTimeMillis())
                .setContentTitle(ctx.getString(ai.saiy.android.R.string.app_name))
                .setContentText(ctx.getString(R.string.vocal_notification_text))
                .setAutoCancel(true);

        final Notification not = builder.build();
        final NotificationManager notificationManager = (NotificationManager)
                ctx.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NotificationService.NOTIFICATION_IDENTIFICATION, not);

    } catch (final Exception e) {
        if (DEBUG) {
            MyLog.e(CLS_NAME, "createIdentificationNotification failure");
            e.printStackTrace();
        }
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:54,代码来源:NotificationHelper.java

示例10: onReceive

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
  NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setContentTitle(intent.getStringExtra(RegistrationService.NOTIFICATION_TITLE));
  builder.setContentText(intent.getStringExtra(RegistrationService.NOTIFICATION_TEXT));
  builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
  builder.setWhen(System.currentTimeMillis());
  builder.setDefaults(Notification.DEFAULT_VIBRATE);
  builder.setAutoCancel(true);

  Notification notification = builder.build();
  ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(31337, notification);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:15,代码来源:RegistrationNotifier.java

示例11: sendNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
private void sendNotification(String address, String amount) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setLargeIcon(Blockies.createIcon(address.toLowerCase()))
            .setColor(0x2d435c)
            .setTicker(getString(R.string.notification_ticker))
            .setLights(Color.CYAN, 3000, 3000)
            .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
            .setContentTitle(this.getResources().getString(R.string.notification_title))
            .setAutoCancel(true)
            .setContentText(amount + " ETH");

    if (android.os.Build.VERSION.SDK_INT >= 18) // Android bug in 4.2, just disable it for everyone then...
        builder.setVibrate(new long[]{1000, 1000});

    final NotificationManager mNotifyMgr =
            (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent main = new Intent(this, MainActivity.class);
    main.putExtra("STARTAT", 2);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            main, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(contentIntent);

    final int mNotificationId = (int) (Math.random() * 150);
    mNotifyMgr.notify(mNotificationId, builder.build());
}
 
开发者ID:manuelsc,项目名称:Lunary-Ethereum-Wallet,代码行数:30,代码来源:NotificationService.java

示例12: show

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
public void show(Class<?> cls, int icon, String text, String title, int actionIcon) {
    CharSequence tickerText = "MWM";
    mIsShowing = true;

    long when = System.currentTimeMillis();

    Intent notificationIntent = new Intent(c, cls);
    PendingIntent contentIntent = PendingIntent.getActivity(c, 0, notificationIntent, 0);

    Intent stopServerIntent = new Intent();
    stopServerIntent.setAction("com.makewithmoto.intent.action.STOP_SERVER");
    PendingIntent stopServerPendingIntent = PendingIntent.getBroadcast(c, 0, stopServerIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder = new NotificationCompat.Builder(c);
    mBuilder.setContentTitle(title).setContentText(text).setSmallIcon(icon).setOngoing(true)
            .setProgress(0, 0, true).setContentIntent(contentIntent)
            // .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .addAction(actionIcon, "Stop server", stopServerPendingIntent);

    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    // notification.ledARGB = Color.RED;
    // notification.ledOffMS = 300;
    // notification.ledOnMS = 300;

    // notification.defaults |= Notification.DEFAULT_SOUND;

    mNotificationManager.notify(NOTIFICATION_APP_RUNNING, mBuilder.build());

}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:31,代码来源:BaseNotification.java

示例13: createNotification

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
/**
 * 通知を表示します。
 * クリック時のアクションはありません。
 */
private Notification createNotification() {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setWhen(System.currentTimeMillis());
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setContentTitle(getString(R.string.chathead_content_title));
    builder.setContentText(getString(R.string.content_text));
    builder.setOngoing(true);
    builder.setPriority(NotificationCompat.PRIORITY_MIN);
    builder.setCategory(NotificationCompat.CATEGORY_SERVICE);

    return builder.build();
}
 
开发者ID:cheenid,项目名称:FLFloatingButton,代码行数:17,代码来源:ChatHeadService.java

示例14: notify

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
protected void notify(Intent proxy) {
    Message msg = proxy.getParcelableExtra(CountlyMessaging.EXTRA_MESSAGE);

    if (isAppInForeground(this)) {
        // Go with dialog
        proxy.putExtra(CountlyMessaging.NOTIFICATION_SHOW_DIALOG, true);
        proxy.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(proxy);
    } else {
        // Notification case
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, proxy, PendingIntent.FLAG_UPDATE_CURRENT);

        // Get icon from application or use default one
        int icon;
        try {
            icon = getPackageManager().getApplicationInfo(getPackageName(), 0).icon;
        } catch (PackageManager.NameNotFoundException e) {
            icon = android.R.drawable.ic_dialog_email;
        }

        NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
                .setAutoCancel(true)
                .setSmallIcon(icon)
                .setTicker(msg.getNotificationMessage())
                .setContentTitle(msg.getNotificationTitle(getApplicationContext()))
                .setContentText(msg.getNotificationMessage())
                .setContentIntent(contentIntent);

        if (msg.hasSoundDefault()) {
            builder.setDefaults(Notification.DEFAULT_SOUND);
        } else if (msg.hasSoundUri()) {
            builder.setSound(Uri.parse(msg.getSoundUri()));
        }

        manager.notify(NOTIFICATION_ID, builder.build());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:39,代码来源:CountlyMessagingService.java

示例15: createForegroundNotifications

import android.support.v4.app.NotificationCompat; //导入方法依赖的package包/类
public static Notification createForegroundNotifications(Context context) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(FocusTaskChangedEvent.currentFocusTask.getToDoName());

    Intent resultIntent = new Intent(context, MainActivity.class);
    PendingIntent resultPendingIntent =
            PendingIntent.getActivity(context, 0, resultIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    return mBuilder.build();
}
 
开发者ID:swapyx,项目名称:Channelize,代码行数:15,代码来源:AppNotifications.java


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