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


Java Notification.FLAG_AUTO_CANCEL屬性代碼示例

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


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

示例1: showNotification

private void showNotification(long cancelTime, String text) {
	try {
		Context app = getContext().getApplicationContext();
		NotificationManager nm = (NotificationManager) app
				.getSystemService(Context.NOTIFICATION_SERVICE);
		final int id = Integer.MAX_VALUE / 13 + 1;
		nm.cancel(id);

		long when = System.currentTimeMillis();
		Notification notification = new Notification(notifyIcon, text, when);
		PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(), 0);
		notification.setLatestEventInfo(app, notifyTitle, text, pi);
		notification.flags = Notification.FLAG_AUTO_CANCEL;
		nm.notify(id, notification);

		if (cancelTime > 0) {
			Message msg = new Message();
			msg.what = MSG_CANCEL_NOTIFY;
			msg.obj = nm;
			msg.arg1 = id;
			UIHandler.sendMessageDelayed(msg, cancelTime, this);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:26,代碼來源:OnekeyShare.java

示例2: PlannedNotifyUser

private void PlannedNotifyUser(Context context, String title, String description) {


        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setContentTitle(title)
                        .setContentText(description);
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);


        Intent notificationIntent = new Intent(context, MainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        Notification notification = mBuilder.build();

        notification.contentIntent = intent; // .setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(nID, notification);

        nID++;
    }
 
開發者ID:alewin,項目名稱:moneytracking,代碼行數:24,代碼來源:MoneyReminder.java

示例3: showNotificationWithUrl

static protected void showNotificationWithUrl(Context context, String title, String notificationText, String url) {
    // TODO Auto-generated method stub
    NotificationCompat.Builder build = new NotificationCompat.Builder(
            context);
    build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
    build.setContentTitle(title);
    build.setContentText(notificationText);
    build.setTicker(notificationText);
    build.setWhen(System.currentTimeMillis());
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent intent = PendingIntent.getActivity(context, 0,
            notificationIntent, 0);
    build.setContentIntent(intent);
    Notification notification = build.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_ALL;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(2, notification);
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:21,代碼來源:PushMessagesReceiver.java

示例4: showNotification

private void showNotification(Context context) {
    Notification.Builder builder = new Notification.Builder(context);
    builder.setContentTitle(context.getString(R.string.notification_title));
    builder.setContentText(context.getString(R.string.notification_message));
    builder.setSmallIcon(R.drawable.ic_notification_slimota);
    builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_slimota));

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

    NotificationManager notificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(1000001, notification);
}
 
開發者ID:DroidThug,項目名稱:VulcanOTA,代碼行數:19,代碼來源:CheckUpdateTask.java

示例5: showNotification

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,代碼行數:25,代碼來源:MessagingService.java

示例6: createNotification

private Notification createNotification(TransactionInfo t) {
	long when = System.currentTimeMillis();
	Notification notification = new Notification(t.getNotificationIcon(), t.getNotificationTickerText(this), when);
	notification.flags |= Notification.FLAG_AUTO_CANCEL;
	applyNotificationOptions(notification, t.notificationOptions);
	Context context = getApplicationContext();
	Intent notificationIntent = new Intent(this, t.getActivity());
	notificationIntent.putExtra(AbstractTransactionActivity.TRAN_ID_EXTRA, t.id);
	PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
	//notification.setLatestEventInfo(context, t.getNotificationContentTitle(this), t.getNotificationContentText(this), contentIntent);
	return notification;
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:12,代碼來源:FinancistoService.java

示例7: notifyDownloadCompleted

/**
 * 下載完成, 發送下載完成的廣播
 */
private void notifyDownloadCompleted(final Context context, final Request request, final File file)
{
	// 取消舊上一個通知
	int preNotificationId = request.mNotificationId;
	mNotificationManager.cancel(preNotificationId);

	RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.api_download_notification_ok);
	remoteViews.setImageViewResource(R.id.noti_icon, R.drawable.notification_icon);
	remoteViews.setTextViewText(R.id.noti_file_name, request.mTitle);
	remoteViews.setTextViewText(R.id.noti_progressBarLeft, context.getString(R.string.cdk_download_ok));
	remoteViews.setTextViewText(R.id.noti_progressBarRight, PROGRESSBAR_MAX + "%");
	remoteViews.setProgressBar(R.id.noti_progressBar, PROGRESSBAR_MAX, PROGRESSBAR_MAX, false);

	// 消息信息設置
	Notification notification = new Notification();
	notification.tickerText = request.mTitle;
	notification.icon = R.drawable.notification_icon;
	notification.contentView = remoteViews;
	notification.flags = Notification.FLAG_AUTO_CANCEL;

	// 點擊通知欄
	String extName = FileUtils.getFileExtension(file.getName());
	Intent intent = new Intent();
	if ("apk".equalsIgnoreCase(extName))
	{
		intent.setAction(Intent.ACTION_VIEW);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
	}
	else
	{
		intent.setAction("com.wo2b.download.AActivity");
	}
	notification.contentIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);

	mNotificationManager.notify(preNotificationId, notification);
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:40,代碼來源:DownloadService.java

示例8: showNotification

public static void showNotification(Context context, Intent intent, String title, String body, int drawableId)
 {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(drawableId, body, System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_SOUND;
if (intent == null)
{
  // FIXEME: category tab is disabled
  //要是  intent = new Intent(context, FileViewActivity.class);
}
//  PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
//  notification.setLatestEventInfo(context, title, body, contentIntent);
manager.notify(drawableId, notification);
 }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:15,代碼來源:Util.java

示例9: showMessage

/**
 * 通知欄提醒
 * @param messageItem 消息信息
 */
@SuppressWarnings("deprecation")
private void showMessage(ChatMessageItem messageItem) {
	SettingSPUtil setSP = MyApp.getInstance().getSettingSPUtil();
	if (!setSP.isChatNotiOnBar()){
		return;
	}
	String messageContent = messageItem.getNickName()+":"+messageItem.getMessage();
	MyApp.getInstance().setNewMsgCount(MyApp.getInstance().getNewMsgCount()+1); //數目+1
	Notification notification = new Notification(R.drawable.ic_launcher,messageContent, System.currentTimeMillis());
	notification.flags = Notification.FLAG_AUTO_CANCEL;
	if (setSP.isChatRing()){
		// 設置默認聲音
		notification.defaults |= Notification.DEFAULT_SOUND;
	}
	if (setSP.isChatVibrate()){
		// 設定震動(需加VIBRATE權限)
		notification.defaults |= Notification.DEFAULT_VIBRATE;
	}
	Intent intent = new Intent(MyApp.getInstance(),ChatRoomAty.class);
	intent.putExtra("TrainId", messageItem.getTrainId());
	PendingIntent contentIntent = PendingIntent.getActivity(MyApp.getInstance(), 0, intent, 0);
	String contentText = null;
	if(MyApp.getInstance().getNewMsgCount()==1){
		contentText = messageContent;
	}else{
		contentText = MyApp.getInstance().getNewMsgCount()+"條未讀消息";
	}
	
	notification.setLatestEventInfo(MyApp.getInstance(), "車友聊天室", contentText, contentIntent);
	NotificationManager manage = (NotificationManager) MyApp.getInstance().getSystemService(Context.NOTIFICATION_SERVICE);
	manage.notify(NOTIFICATION_ID, notification);
}
 
開發者ID:SShineTeam,項目名稱:Huochexing12306,代碼行數:36,代碼來源:PushMessageReceiver.java

示例10: createRestoredNotification

private Notification createRestoredNotification(int count) {
	long when = System.currentTimeMillis();
	String text = getString(R.string.scheduled_transactions_have_been_restored, count);
	Notification notification = new Notification(R.drawable.notification_icon_transaction, text, when);
	notification.flags |= Notification.FLAG_AUTO_CANCEL;
	notification.defaults = Notification.DEFAULT_ALL;
	Intent notificationIntent = new Intent(this, MassOpActivity.class);
	WhereFilter filter = new WhereFilter("");
	filter.eq(BlotterFilter.STATUS, TransactionStatus.RS.name());
	filter.toIntent(notificationIntent);
	PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
	//notification.setLatestEventInfo(this, getString(R.string.scheduled_transactions_restored), text, contentIntent);
	return notification;
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:14,代碼來源:FinancistoService.java

示例11: handleMessage

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case 0:
            mNotificationManager.cancel(0);
            installApk();
            break;
        case 1:
            int rate = msg.arg1;
            if (rate < 100) {
                RemoteViews views = mNotification.contentView;
                views.setTextViewText(R.id.tv_download_progress, mTitle + "(" + rate
                        + "%" + ")");
                //views.setTextColor(R.id.tv_download_progress,getColor(R.color.text_title_color));
                views.setProgressBar(R.id.pb_progress, 100, rate,
                        false);
            } else {
                // 下載完畢後變換通知形式
                mNotification.flags = Notification.FLAG_AUTO_CANCEL;
                mNotification.contentView = null;
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);

                intent.putExtra("completed", "yes");

                PendingIntent contentIntent = PendingIntent.getActivity(
                        getApplicationContext(), 0, intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
            }
            mNotificationManager.notify(0, mNotification);
            break;
    }

}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:33,代碼來源:DownloadService.java

示例12: setStyleBasic

/**
 * 設置通知提示方式 - 基礎屬性
 */
private void setStyleBasic() {
	BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(PushSetActivity.this);
	builder.statusBarDrawable = R.drawable.ic_launcher;
	builder.notificationFlags = Notification.FLAG_AUTO_CANCEL;  //設置為點擊後自動消失
	builder.notificationDefaults = Notification.DEFAULT_SOUND;  //設置為鈴聲( Notification.DEFAULT_SOUND)或者震動( Notification.DEFAULT_VIBRATE)
	JPushInterface.setPushNotificationBuilder(1, builder);
	Toast.makeText(PushSetActivity.this, "Basic Builder - 1", Toast.LENGTH_SHORT).show();
}
 
開發者ID:LuoLuo0101,項目名稱:JPush,代碼行數:11,代碼來源:PushSetActivity.java

示例13: showNotification

protected void showNotification(String notificationText) {
    // TODO Auto-generated method stub
    NotificationCompat.Builder build = new NotificationCompat.Builder(
            activity);
    build.setSmallIcon(OneSheeldApplication.getNotificationIcon());
    build.setContentTitle(activity.getString(R.string.mic_shield_name)+" Shield");
    build.setContentText(notificationText);
    build.setTicker(notificationText);
    build.setWhen(System.currentTimeMillis());
    build.setAutoCancel(true);
    Toast.makeText(activity, notificationText, Toast.LENGTH_SHORT).show();
    Vibrator v = (Vibrator) activity
            .getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
    Log.d("Mic",fileName+".mp3");
    if(Build.VERSION.SDK_INT>=24) {
        Uri fileURI = FileProvider.getUriForFile(activity,
                BuildConfig.APPLICATION_ID + ".provider",
                new File(Environment.getExternalStorageDirectory() + "/OneSheeld/Mic/" + fileName + ".mp3"));
        notificationIntent.setDataAndType(fileURI, "audio/*");
    }else{
        notificationIntent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/OneSheeld/Mic/"+ fileName + ".mp3")), "audio/*");
    }
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    PendingIntent intent = PendingIntent.getActivity(activity, 0,
            notificationIntent, 0);
    build.setContentIntent(intent);
    Notification notification = build.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) activity
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify((int) new Date().getTime(), notification);
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:35,代碼來源:MicShield.java

示例14: createNotification

public void createNotification(String content) {
    Notification noti = new Notification.Builder(this)
            .setContentTitle(content)
            .setContentText("Subject").setSmallIcon(R.mipmap.ic_launcher).build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(1, noti);

}
 
開發者ID:safaricom,項目名稱:LNMOnlineAndroidSample,代碼行數:11,代碼來源:MainActivity.java

示例15: sendProgressNoti

private void sendProgressNoti() {
        progress = 1;
        builder = new NotificationCompat.Builder(this);

        notification = builder.setContentTitle("恭喜您中獎了")
                .setContentIntent(pendingIntent)
                .setContentText("您有一條消息")
                .setTicker("新的消息來了!")
                .setWhen(System.currentTimeMillis())
                .setLargeIcon(bitmap)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setProgress(100, 0, false)
//                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
                .build();
        notification.flags = Notification.FLAG_AUTO_CANCEL;
//        notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;
        manager.notify(1, notification);

//        new Thread() {
//            @Override
//            public void run() {
//                super.run();
//                handler.sendEmptyMessage(0);
//            }
//        }.start();
    }
 
開發者ID:BittleDragon,項目名稱:MyRepository,代碼行數:27,代碼來源:MainActivity.java


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