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


Java Notification.Builder方法代碼示例

本文整理匯總了Java中android.app.Notification.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java Notification.Builder方法的具體用法?Java Notification.Builder怎麽用?Java Notification.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Notification的用法示例。


在下文中一共展示了Notification.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: notification

import android.app.Notification; //導入方法依賴的package包/類
public void notification(Context context) {

        notif = new Notification.Builder(context);
        notif.setSmallIcon(R.mipmap.ic_launcher);
        int notificationId = new Random().nextInt();
        notif.setContentTitle("Do you want to send battery level msg to others?");
        Uri path = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        notif.setSound(path);
        nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);

        Intent yesReceive = new Intent();
        yesReceive.putExtra("notificationId",notificationId);
        yesReceive.setAction(AppConstant.YES_ACTION);
        PendingIntent pendingIntentYes = PendingIntent.getBroadcast(context, 12345, yesReceive, PendingIntent.FLAG_UPDATE_CURRENT);
        notif.addAction(R.drawable.ic_notifications, "Yes", pendingIntentYes);


        Intent yesReceive2 = new Intent();
        yesReceive.putExtra("notificationId",notificationId);
        yesReceive2.setAction(AppConstant.STOP_ACTION);
        PendingIntent pendingIntentYes2 = PendingIntent.getBroadcast(context, 12345, yesReceive2, PendingIntent.FLAG_UPDATE_CURRENT);
        notif.addAction(R.drawable.ic_notifications, "No", pendingIntentYes2);


        nm.notify(10, notif.getNotification());
    }
 
開發者ID:spritlesoftware,項目名稱:low-battery-alert,代碼行數:27,代碼來源:BatteryLevelReceiver.java

示例2: showNotification

import android.app.Notification; //導入方法依賴的package包/類
/**
 * Displays a notification with the location results.
 */
void showNotification() {
    Intent notificationIntent = new Intent(mContext, MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification.Builder notificationBuilder = new Notification.Builder(mContext)
            .setContentTitle(getLocationResultTitle())
            .setContentText(getLocationResultText())
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true)
            .setContentIntent(notificationPendingIntent);

    getNotificationManager().notify(0, notificationBuilder.build());
}
 
開發者ID:googlecodelabs,項目名稱:background-location-updates-android-o,代碼行數:29,代碼來源:LocationResultHelper.java

示例3: onCreate

import android.app.Notification; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    //添加下列代碼將後台Service變成前台Service
    //構建"點擊通知後打開MainActivity"的Intent對象
    Intent notificationIntent = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
    //新建Builer對象
    Notification.Builder builer = new Notification.Builder(this);
    builer.setContentTitle("前台服務通知的標題");//設置通知的標題
    builer.setContentText("前台服務通知的內容");//設置通知的內容
    builer.setSmallIcon(R.mipmap.ic_launcher);//設置通知的圖標
    builer.setContentIntent(pendingIntent);//設置點擊通知後的操作
    Notification notification = builer.getNotification();//將Builder對象轉變成普通的notification
    startForeground(1, notification);//讓Service變成前台Service,並在係統的狀態欄顯示出來
}
 
開發者ID:ZhongXiaoHong,項目名稱:AIDLExample,代碼行數:17,代碼來源:LibraryServer.java

示例4: selectNotofovatiomLevel

import android.app.Notification; //導入方法依賴的package包/類
private void selectNotofovatiomLevel(Notification.Builder builder) {
    switch (radioGroup.getCheckedRadioButtonId()) {
        case R.id.rb_public:
            builder.setVisibility(Notification.VISIBILITY_PUBLIC);
            builder.setContentText("public");
            break;
        case R.id.rb_private:
            builder.setVisibility(Notification.VISIBILITY_PRIVATE);
            builder.setContentText("private");
            break;
        case R.id.rb_secret:
            builder.setVisibility(Notification.VISIBILITY_SECRET);
            builder.setContentText("secret");
            break;
        default:
            builder.setVisibility(Notification.VISIBILITY_PUBLIC);
            builder.setContentText("public");
            break;

    }
}
 
開發者ID:henrymorgen,項目名稱:android-advanced-light,代碼行數:22,代碼來源:MyNotificationActivity.java

示例5: onReceive

import android.app.Notification; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {

    Notification.Builder notificationBuilder = new Notification.Builder(
            context)
            .setSmallIcon(android.R.drawable.alert_light_frame)
            .setAutoCancel(true)
                .setContentTitle("NOTÍCIAS NOVAS!")
            .setContentText("Clique aqui para ver...")
            .setVibrate(longVibracao);

    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1,notificationBuilder.build());

}
 
開發者ID:if1001,項目名稱:tarefa01-blaandrade,代碼行數:16,代碼來源:DownloadRssCompleto.java

示例6: fixNotificationRemoteViews

import android.app.Notification; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void fixNotificationRemoteViews(Context pluginContext, Notification notification) {
    Notification.Builder rebuild = null;
    try {
        rebuild = Reflect.on(Notification.Builder.class).create(pluginContext, notification).get();
    } catch (Exception e) {
        // ignore
    }
    if (rebuild != null) {
        Notification renotification = rebuild.build();
        if (notification.tickerView == null) {
            notification.tickerView = renotification.tickerView;
        }
        if (notification.contentView == null) {
            notification.contentView = renotification.contentView;
        }
        if (notification.bigContentView == null) {
            notification.bigContentView = renotification.bigContentView;
        }
        if (notification.headsUpContentView == null) {
            notification.headsUpContentView = renotification.headsUpContentView;
        }
    }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:25,代碼來源:NotificationFixer.java

示例7: makeNotification

import android.app.Notification; //導入方法依賴的package包/類
/**
 * Create a notification as the visible part to be able to put the service
 * in a foreground state.
 *
 * @param settings The config settings
 */
private Notification makeNotification(JSONObject settings) {
    String title    = settings.optString("title", NOTIFICATION_TITLE);
    String text     = settings.optString("text", NOTIFICATION_TEXT);
    boolean bigText = settings.optBoolean("bigText", false);

    Context context = getApplicationContext();
    String pkgName  = context.getPackageName();
    Intent intent   = context.getPackageManager()
            .getLaunchIntentForPackage(pkgName);

    Notification.Builder notification = new Notification.Builder(context)
            .setContentTitle(title)
            .setContentText(text)
            .setOngoing(true)
            .setSmallIcon(getIconResId(settings));

    if (settings.optBoolean("hidden", true)) {
        notification.setPriority(Notification.PRIORITY_MIN);
    }

    if (bigText || text.contains("\n")) {
        notification.setStyle(
                new Notification.BigTextStyle().bigText(text));
    }

    setColor(notification, settings);

    if (intent != null && settings.optBoolean("resume")) {
        PendingIntent contentIntent = PendingIntent.getActivity(
                context, NOTIFICATION_ID, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setContentIntent(contentIntent);
    }

    return notification.build();
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:44,代碼來源:ForegroundService.java

示例8: createNotificationBuilder

import android.app.Notification; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private Notification.Builder createNotificationBuilder() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        return new Notification.Builder(context, CHANNEL_ID);
    }
    return new Notification.Builder(context);
}
 
開發者ID:Genymobile,項目名稱:gnirehtet,代碼行數:8,代碼來源:Notifier.java

示例9: sendNotification

import android.app.Notification; //導入方法依賴的package包/類
public static void sendNotification(final Context context,final String postfix,final String message){
	final Notification.Builder mBuilder =
	        new Notification.Builder(context)
	        .setSmallIcon(R.drawable.ic_launcher)
	        .setContentTitle(context.getText(R.string.app_name)+" "+postfix)
	        .setContentText(message);
	// Creates an explicit intent for an Activity in your app
	final Intent resultIntent = new Intent(context, MainActivity.class);

	// The stack builder object will contain an artificial back stack for the
	// started Activity.
	// This ensures that navigating backward from the Activity leads out of
	// your application to the Home screen.
	final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
	// Adds the back stack for the Intent (but not the Intent itself)
	stackBuilder.addParentStack(MainActivity.class);
	// Adds the Intent that starts the Activity to the top of the stack
	stackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
	mBuilder.setContentIntent(resultPendingIntent);
	final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	if (mNotificationManager!=null) {
           // mId allows you to update the notification later on.
           int mId = 0;
           mNotificationManager.notify(mId, mBuilder.build());

           Analytics.getInstance().logEvent(TAG, "sendNotification", "message");
       }
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:30,代碼來源:Utils.java

示例10: build

import android.app.Notification; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static Notification build(final Notification.Builder builder) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // #build was added in API level 16, JELLY_BEAN
        return (Notification) CompatUtils.invoke(builder, null, METHOD_build);
    }
    // #getNotification was deprecated in API level 16, JELLY_BEAN
    return builder.getNotification();
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:10,代碼來源:NotificationCompatUtils.java

示例11: NotifyUser

import android.app.Notification; //導入方法依賴的package包/類
public void NotifyUser(Bill bill, String title, String details) {
    // TODO: make the builder member, built once only
    Notification.Builder builder = new Notification.Builder(mContext);
    builder.setContentTitle(title);
    builder.setContentText(details);
    builder.setSmallIcon(mContext.getApplicationInfo().icon);

    Intent intent = new Intent(mActivity, BillActivity.class);
    Bundle bundle = new Bundle();
    bundle.putString("wallet_address", bill.getWalletID());
    intent.putExtras(bundle);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(PayActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);

    Notification n = builder.build();

    mNotificationManager.notify(++mLastNotificationID, n);
}
 
開發者ID:gbizzotto,項目名稱:dapay,代碼行數:29,代碼來源:Notifier.java

示例12: showAlarmNotification

import android.app.Notification; //導入方法依賴的package包/類
private void showAlarmNotification() {
    Notification.Builder builder = new Notification.Builder(this);

    builder.setPriority(Notification.PRIORITY_MAX).
            setCategory(Notification.CATEGORY_ALARM).
            setContentTitle(getString(R.string.app_name)).
            setSmallIcon(R.drawable.ic_crockpod_mascot).
            setStyle(new Notification.BigTextStyle().bigText(getString(R.string.alarm_notification_text)));

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(ALARM_NOTIFICATION_ID, builder.build());
}
 
開發者ID:KevinLiddle,項目名稱:crockpod,代碼行數:13,代碼來源:AlarmRingingActivity.java

示例13: updateNotification

import android.app.Notification; //導入方法依賴的package包/類
public static void updateNotification(Context context) {

        ConnectionStatus status = connectionEngine.getConnectionStatus();

        Notification.Builder builder = new Notification.Builder(context);

        Intent intent = new Intent(context, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        builder.setContentIntent(pendingIntent);

        int iconId = R.drawable.ic_stat_discon;
        String msg = "RepWifi";
        if (status != null) {
            if (status.isConnected()) {
                iconId = R.drawable.ic_stat_repwifi;
                msg += " - " + status.SSID;
            } else {
                msg += " - " + status.status;
            }

        }

        builder.setSmallIcon(iconId);

        builder.setContentTitle(msg);
        builder.setContentText("Touch to open.");

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

        NotificationManager notificationManager = (NotificationManager) context
                        .getSystemService(Service.NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, n);

    }
 
開發者ID:vaginessa,項目名稱:RepWifiApp,代碼行數:36,代碼來源:Commons.java

示例14: sendNomalNotification

import android.app.Notification; //導入方法依賴的package包/類
private void sendNomalNotification() {
    Notification.Builder builder = new Notification.Builder(this);
    Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://blog.csdn.net/itachi85/"));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mIntent, 0);
    builder.setContentIntent(pendingIntent);
    builder.setSmallIcon(R.drawable.lanucher);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.lanucher));
    builder.setAutoCancel(true);
    builder.setContentTitle("普通通知");
    selectNotofovatiomLevel(builder);
    notificationManager.notify(0, builder.build());

}
 
開發者ID:henrymorgen,項目名稱:android-advanced-light,代碼行數:14,代碼來源:MyNotificationActivity.java

示例15: getNotificationBuilder

import android.app.Notification; //導入方法依賴的package包/類
/**
 * Gets Notification.Builder with 2 lines at BigPictureStyle notification text.
 *
 * @param context The application context.
 * @param message Push notification Bundle.
 * @param contentIntent PendingIntent.
 * @param title String with title for push notification.
 * @param messageText String with text for push notification.
 * @param bigPicture Bitmap for BigPictureStyle notification.
 * @param defaultNotificationIconResourceId int Resource id for default push notification icon.
 * @return Notification.Builder or null.
 */
static Notification.Builder getNotificationBuilder(Context context, Bundle message,
    PendingIntent contentIntent, String title, final String messageText, Bitmap bigPicture,
    int defaultNotificationIconResourceId) {
  if (Build.VERSION.SDK_INT < 16) {
    return null;
  }
  Notification.Builder notificationBuilder =
      getNotificationBuilder(context, message);
  if (defaultNotificationIconResourceId == 0) {
    notificationBuilder.setSmallIcon(context.getApplicationInfo().icon);
  } else {
    notificationBuilder.setSmallIcon(defaultNotificationIconResourceId);
  }
  notificationBuilder.setContentTitle(title)
      .setContentText(messageText);
  Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() {
    @Override
    protected RemoteViews getStandardView(int layoutId) {
      RemoteViews remoteViews = super.getStandardView(layoutId);
      // Modifications of stanxdard push RemoteView.
      try {
        int id = Resources.getSystem().getIdentifier("text", "id", "android");
        remoteViews.setBoolean(id, "setSingleLine", false);
        remoteViews.setInt(id, "setLines", 2);
        if (Build.VERSION.SDK_INT < 23) {
          // Make text smaller.
          remoteViews.setViewPadding(id, 0, BIGPICTURE_TEXT_TOP_PADDING, 0, 0);
          remoteViews.setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, BIGPICTURE_TEXT_SIZE);
        }
      } catch (Throwable throwable) {
        Log.e("Cannot modify push notification layout.");
      }
      return remoteViews;
    }
  };

  bigPictureStyle.bigPicture(bigPicture)
      .setBigContentTitle(title)
      .setSummaryText(message.getString(Constants.Keys.PUSH_MESSAGE_TEXT));
  notificationBuilder.setStyle(bigPictureStyle);

  if (Build.VERSION.SDK_INT >= 24) {
    // By default we cannot reach getStandardView method on API>=24. I we call
    // createBigContentView, Android will call getStandardView method and we can get
    // modified RemoteView.
    try {
      RemoteViews remoteView = notificationBuilder.createBigContentView();
      if (remoteView != null) {
        // We need to set received RemoteView as a custom big content view.
        notificationBuilder.setCustomBigContentView(remoteView);
      }
    } catch (Throwable t) {
      Log.e("Cannot modify push notification layout.", t);
    }
  }

  notificationBuilder.setAutoCancel(true);
  notificationBuilder.setContentIntent(contentIntent);
  return notificationBuilder;
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:73,代碼來源:LeanplumNotificationHelper.java


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