当前位置: 首页>>代码示例>>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;未经允许,请勿转载。