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


Java Notification.FLAG_ONGOING_EVENT屬性代碼示例

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


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

示例1: shouldBeFilteredOut

private boolean shouldBeFilteredOut(StatusBarNotification sbn) {
    Notification notification = sbn.getNotification();

    if (AndroidVersion.isAtLeastOreo()) {
        getCurrentRanking().getRanking(sbn.getKey(), mTempRanking);
        if (!mTempRanking.canShowBadge()) {
            return true;
        }
        if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
            // Special filtering for the default, legacy "Miscellaneous" channel.
            if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
                return true;
            }
        }
    }

    if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
        return true;
    }

    boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
    CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
    CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
    boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text);
    return (isGroupHeader || missingTitleAndText);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:26,代碼來源:NotificationListener.java

示例2: showGPSTrackNotification

public static Notification showGPSTrackNotification(Context context, int what) {
        GPSTrackNotificationBuilder notificationBuilder =
                new GPSTrackNotificationBuilder(context, what);
        // Gets an instance of the NotificationManager service
//        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // Builds the notification and issues it.
        Notification notification = notificationBuilder.build();

        if (what == AndiCarNotification.GPS_TRACKING_IN_PROGRESS_ID
                || what == AndiCarNotification.GPS_TRACKING_PAUSED_ID) {
            notification.flags |= Notification.FLAG_NO_CLEAR;
            notification.flags |= Notification.FLAG_ONGOING_EVENT;
        }

        return notification;
    }
 
開發者ID:mkeresztes,項目名稱:AndiCar,代碼行數:16,代碼來源:AndiCarNotification.java

示例3: showCzNotify

/**
     * 顯示常駐通知欄
     */
    public void showCzNotify(String title, String content, String ticker, int notifyId) {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
//		//PendingIntent 跳轉動作
//        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,Intent.getIntent(), 0);
        mBuilder.setSmallIcon(R.mipmap.ic_launcher)
                .setTicker(ticker)
                .setContentTitle(title)
                .setContentText(content);
//                .setContentIntent(pendingIntent);
        Notification mNotification = mBuilder.build();
        //設置通知  消息  圖標
        mNotification.icon = R.mipmap.ic_launcher;
        //在通知欄上點擊此通知後自動清除此通知
        mNotification.flags = Notification.FLAG_ONGOING_EVENT;//FLAG_ONGOING_EVENT 在頂部常駐,可以調用下麵的清除方法去除  FLAG_AUTO_CANCEL  點擊和清理可以去調
        //設置顯示通知時的默認的發聲、震動、Light效果
        mNotification.defaults = Notification.DEFAULT_VIBRATE;
        //設置發出消息的內容
//        mNotification.tickerText = "通知來了";
        //設置發出通知的時間
        mNotification.when = System.currentTimeMillis();
//		mNotification.flags = Notification.FLAG_AUTO_CANCEL; //在通知欄上點擊此通知後自動清除此通知
//		mNotification.setLatestEventInfo(this, "常駐測試", "使用cancel()方法才可以把我去掉哦", null); //設置詳細的信息  ,這個方法現在已經不用了
        mNotificationManager.notify(notifyId, mNotification);
    }
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:27,代碼來源:Notifications.java

示例4: onBackground

private void onBackground(boolean flag) {
    if (flag /*&& voiceMediator.isWakeUpMode()*/) {
        RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.wake_notification);
        Intent resultIntent = new Intent(AssistantService.this, MainActivity.class);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), ServiceCmd.PLAY_IN_BACKGROUND, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setContentIntent(resultPendingIntent);
        mBuilder.setAutoCancel(false);
        mBuilder.setSmallIcon(R.drawable.ic_launcher);
        mBuilder.setContent(remoteViews);
        Notification nf = mBuilder.build();
        nf.flags = Notification.FLAG_ONGOING_EVENT;
        startForeground(1, nf);
    } else {
        stopForeground(true);
    }
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:17,代碼來源:AssistantService.java

示例5: onStartCommand

@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    int result = super.onStartCommand(intent, flags, startId);
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (intent != null && intent.getAction() != null && intent.getAction().equals("stop")) {
        // User clicked the notification. Need to stop the service.
        nm.cancel(0);
        stopSelf();
    } else {
        // Service starting. Create a notification.
        Notification notification =
        new Notification.Builder(getApplicationContext())
                .setContentTitle("CommunicationService")
                .setContentText("Connected! click to stop.")
                .build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        nm.notify(0, notification);
        //showToast(notification.category);
    }
    return result;
}
 
開發者ID:mike168m,項目名稱:USLI2018,代碼行數:22,代碼來源:CommuncationService.java

示例6: initNotification

/**
  * 初始化Notification,此處做Notification的基本設置
  */
 private void initNotification(){
 	try{//解決崩潰問題
      PendingIntent contentPendingIntent = createPendingIntent(mContext,
		SettingActivity.class);
      //獲取notification管理的實例
      notificationManager = (NotificationManager) this.mContext.getSystemService(Context.NOTIFICATION_SERVICE);
      createNotification();
notification.flags = Notification.FLAG_ONGOING_EVENT;
      notification.contentIntent = contentPendingIntent;
 	}catch(Exception ex){
 		ex.printStackTrace();
 	}catch(Throwable e){
 		e.printStackTrace();
 	}
 }
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:18,代碼來源:BigbangNotification.java

示例7: Notify

public void Notify() {
	if(checkNotify()) {
		Date date = new Date();
		String time = String.format("%tY%tm%td", date, date, date);
		Cursor cursor_total = dbmanager.openDatabase().rawQuery("select sum(heat) as total from diet where time=?", new String[] { time });
	    cursor_total.moveToFirst();
	    String total = String.format("%.0f", cursor_total.getDouble(0)) + "��";
	    
	    //����֪ͨ��չ�ֵ�������Ϣ
	    Notification notification = new Notification(R.drawable.ic_launcher, "��������������:" + total, System.currentTimeMillis());
	    notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
	    
	    Intent notificationIntent = new Intent(this, MainActivity.class);
	    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
	    
	    int i = (int)(Math.random()*5);
	    notification.setLatestEventInfo(this, "��������������:" + total, tips[i], contentIntent);
	    mNotificationManager.notify(1, notification);
	}
}
 
開發者ID:ghsxl,項目名稱:Android-Fitness,代碼行數:20,代碼來源:MainActivity.java

示例8: notifyDownloadStart

/**
 * 開始下載
 * 
 * @param context
 * @param title
 * @param icon
 */
private void notifyDownloadStart(Context context, Request request)
{
	RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.api_download_notification);
	remoteViews.setProgressBar(R.id.noti_progressBar, PROGRESSBAR_MAX, 0, false);
	remoteViews.setImageViewResource(R.id.noti_icon, R.drawable.notification_remote_icon);
	remoteViews.setTextViewText(R.id.noti_file_name, request.mTitle);
	
	String host = CommonUtils.getHost(request.mDownloadUrl);
	if (CommonUtils.isWo2bHost(request.mDownloadUrl))
	{
		remoteViews.setTextViewText(R.id.noti_progressBarLeft, "www.wo2b.com");
	}
	else
	{
		remoteViews.setTextViewText(R.id.noti_progressBarLeft, host);
	}
	
	
	// 執行取消操作的PendingIntent, 向DownloadService發起取消下載的命令
	Intent cancelIntent = new Intent();
	cancelIntent.setClass(context, DownloadService.class);
	cancelIntent.putExtra(DownloadService.EXTRA_EVENT_TYPE, DownloadService.EVENT_CANCEL);
	cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, request.mDownloadUrl);

	PendingIntent cancelPendingIntent = PendingIntent.getService(context, 100, cancelIntent,
			PendingIntent.FLAG_CANCEL_CURRENT);
	remoteViews.setOnClickPendingIntent(R.id.noti_cancel, cancelPendingIntent);
	
	// 消息信息設置
	Notification notification = new Notification();
	notification.tickerText = request.mTitle;
	notification.icon = R.drawable.notification_icon;
	notification.contentView = remoteViews;
	// notification.flags = Notification.FLAG_AUTO_CANCEL;
	notification.flags = Notification.FLAG_ONGOING_EVENT;

	// 點擊通知欄
	Intent intent = new Intent();
	intent.setAction("com.wo2b.download.AActivity");
	// intent.setClass(context, Download.class);

	notification.contentIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
	
	// 生成通知ID
	int notificationId = new Random().nextInt(10000);

	mNotificationManager.notify(notificationId, notification);
	
	request.mNotification = notification;
	request.mNotificationId = notificationId;

}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:59,代碼來源:DownloadService.java

示例9: onCreateMusicNotification

/**
     * 初始化自定義通知
     */
    public void onCreateMusicNotification(){
        Log.e(TAG,"初始化MusicNotification對象");
        //注冊點擊事件
        //1.播放事件
        playIntent.putExtra("type",MUSIC_NOTIFICATION_VALUE_PLAY);
        PendingIntent pendingPlayIntent = PendingIntent.getBroadcast(context,REQUEST_CODE,playIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.img_play,pendingPlayIntent);
        //2.下一首事件
        nextIntent.putExtra("type",MUSIC_NOTIFICATION_VALUE_NEXT);
        PendingIntent pendingNextIntent = PendingIntent.getBroadcast(context,REQUEST_CODE,nextIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.img_next,pendingNextIntent);
        //3.關閉通知事件
        closeIntent.putExtra("type",MUSIC_NOTIFICATION_VALUE_CLOSE);
        PendingIntent pendingCloseIntent = PendingIntent.getBroadcast(context,REQUEST_CODE,closeIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.img_close,pendingCloseIntent);
        //4.點擊通知返回App
        PendingIntent pendingBackIntent = PendingIntent.getActivity(MyApplication.mContext,REQUEST_CODE,backIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setOnClickPendingIntent(R.id.notification_contanier,pendingBackIntent);

        builder.setContent(remoteViews)
                .setOngoing(true)//表示正在運行的通知,常用於音樂播放或者文件下載
                .setSmallIcon(R.mipmap.notification_img_holder);

        notification = builder.build();
        notification.flags = Notification.FLAG_ONGOING_EVENT;//將此通知放到通知欄的"Ongoing",“正在運行”組中
//        notificationManager.notify(NOTIFICATION_ID,notification);//彈出通知
        mService.startForeground(NOTIFICATION_ID,notification);

    }
 
開發者ID:popo1379,項目名稱:popomusic,代碼行數:32,代碼來源:MusicNotification.java

示例10: createInCallNotification

public static Notification createInCallNotification(Context context,
		String title, String msg, int iconID, Bitmap contactIcon,
		String contactName, PendingIntent intent) {

	Notification notif = new Notification.Builder(context).setContentTitle(contactName)
					.setContentText(msg).setSmallIcon(iconID)
					.setAutoCancel(false)
					.setContentIntent(intent)
					.setWhen(System.currentTimeMillis())
					.setLargeIcon(contactIcon).build();
	notif.flags |= Notification.FLAG_ONGOING_EVENT;
	
	return notif;
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:14,代碼來源:ApiSixteenPlus.java

示例11: createNotification

public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
	Notification notif;
	
	if (largeIcon != null) {
		notif = new Notification.Builder(context)
        .setContentTitle(title)
        .setContentText(message)
        .setSmallIcon(icon, level)
        .setLargeIcon(largeIcon)
        .setContentIntent(intent)
        .setWhen(System.currentTimeMillis())
        .setPriority(priority)
        .build();
	} else {
		notif = new Notification.Builder(context)
        .setContentTitle(title)
        .setContentText(message)
        .setSmallIcon(icon, level)
        .setContentIntent(intent)
        .setWhen(System.currentTimeMillis())
        .setPriority(priority)
        .build();
	}
	if (isOngoingEvent) {
		notif.flags |= Notification.FLAG_ONGOING_EVENT;
	}
	
	return notif;
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:29,代碼來源:ApiSixteenPlus.java

示例12: createInCallNotification

@SuppressWarnings("deprecation")
public static Notification createInCallNotification(Context context,
		String title, String msg, int iconID, Bitmap contactIcon,
		String contactName, PendingIntent intent) {

	Notification notif = new Notification.Builder(context).setContentTitle(contactName)
					.setContentText(msg).setSmallIcon(iconID)
					.setAutoCancel(false)
					.setContentIntent(intent)
					.setWhen(System.currentTimeMillis())
					.setLargeIcon(contactIcon).getNotification();
	notif.flags |= Notification.FLAG_ONGOING_EVENT;
	
	return notif;
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:15,代碼來源:ApiElevenPlus.java

示例13: createNotification

@SuppressWarnings("deprecation")
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
	Notification notif;
	
	if (largeIcon != null) {
		notif = new Notification.Builder(context)
        .setContentTitle(title)
        .setContentText(message)
        .setSmallIcon(icon, level)
        .setLargeIcon(largeIcon)
        .setContentIntent(intent)
        .setWhen(System.currentTimeMillis())
        .getNotification();
	} else {
		notif = new Notification.Builder(context)
        .setContentTitle(title)
        .setContentText(message)
        .setSmallIcon(icon, level)
        .setContentIntent(intent)
        .setWhen(System.currentTimeMillis())
        .getNotification();
	}
	if (isOngoingEvent) {
		notif.flags |= Notification.FLAG_ONGOING_EVENT;
	}
	
	return notif;
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:28,代碼來源:ApiElevenPlus.java

示例14: initNotification

@Override
public void initNotification(Context context) {
    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    remoteViews = new RemoteViews(context.getPackageName(), R.layout.music_notification);
    Intent intent1 = new Intent(context.getApplicationContext(), AssistantService.class);
    intent1.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.TOGGLE_PLAY);
    PendingIntent pi1 = PendingIntent.getService(context.getApplicationContext(), AssistantService.ServiceCmd.TOGGLE_PLAY, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.notice_switch, pi1);
    Intent intent2 = new Intent(context.getApplicationContext(), AssistantService.class);
    intent2.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.NEXT_MUSIC);
    PendingIntent pi2 = PendingIntent.getService(context.getApplicationContext(), AssistantService.ServiceCmd.NEXT_MUSIC, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.notice_next, pi2);
    Intent intent3 = new Intent(context.getApplicationContext(), AssistantService.class);
    intent3.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.CLOSE_PLAY_NOTIFICATION);
    PendingIntent pi3 = PendingIntent.getService(context.getApplicationContext(), AssistantService.ServiceCmd.CLOSE_PLAY_NOTIFICATION, intent3, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.notice_close, pi3);
    /* 點擊通知欄進入主界麵 */
    Intent intent4 = new Intent(context.getApplicationContext(), MainActivity.class);
    PendingIntent pi4 = PendingIntent.getActivity(context.getApplicationContext(), 0, intent4, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setAutoCancel(false);

    mBuilder.setSmallIcon(R.drawable.ic_launcher);
    mBuilder.setContent(remoteViews);
    notification = mBuilder.build();
    notification.contentIntent = pi4;
    // notification.flags = Notification.FLAG_NO_CLEAR; // 點擊清除按鈕時就會清除消息通知,但是點擊通知欄的通知時不會消失
    notification.flags = Notification.FLAG_ONGOING_EVENT; // 點擊清除按鈕不會清除消息通知,可以用來表示在正在運行
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:30,代碼來源:PlayerHeaderFragment.java

示例15: lavNotification

@SuppressLint("NewApi")
public static Notification lavNotification(Context ctx) {
  String kanalNavn = App.afspiller.getLydkilde().getKanal().navn;

  NotificationCompat.Builder b = new NotificationCompat.Builder(ctx)
      .setSmallIcon(R.drawable.dr_notifikation)
      .setContentTitle(ctx.getString(R.string.appnavn))
      .setContentText(kanalNavn)
      .setOngoing(true)
      .setAutoCancel(false)
      .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
      .setPriority(1001) // holder den øverst
      .setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, Hovedaktivitet.class), 0));
  // PendingIntent er til at pege på aktiviteten der skal startes hvis
  // brugeren vælger notifikationen


  b.setContent(AfspillerIkonOgNotifikation.lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_lille));
  Notification notification = b.build();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    // A notification's big view appears only when the notification is expanded,
    // which happens when the notification is at the top of the notification drawer,
    // or when the user expands the notification with a gesture.
    // Expanded notifications are available starting with Android 4.1.
    notification.bigContentView = AfspillerIkonOgNotifikation.lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_stor);
  }

  notification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.PRIORITY_HIGH | Notification.FLAG_FOREGROUND_SERVICE);
  return notification;
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:31,代碼來源:AfspillerIkonOgNotifikation.java


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