public class NotificationUtils {    private static NotificationManager mNotificationManager;    private static Notification notification;    /**     * 创建通知,  * 请在调用此方法时开启子线程     *     * @param context    上下文     * @param icon       通知图片     * @param tickerText 通知未拉开的内容     * @param title      通知标题     * @param content    通知主内容     * @param intent     意图     * @param id     * @param time       控制线程睡眠时间     */    public static void createNotif(Context context, int icon, String tickerText, String title, String content, Intent intent, int id, long time) {        intent.addCategory(Intent.CATEGORY_LAUNCHER);        intent.setAction(Intent.ACTION_MAIN);        //intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);        PendingIntent pendingIntent = PendingIntent.getActivity(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);        mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);        mBuilder.setContentTitle(title)                .setContentText(content)                .setContentIntent(pendingIntent)                .setTicker(tickerText)                .setWhen(System.currentTimeMillis())                .setPriority(Notification.PRIORITY_DEFAULT)                .setOngoing(false)                .setAutoCancel(true)                .setDefaults(Notification.DEFAULT_SOUND)                .setSmallIcon(icon);        notification = mBuilder.build();        notification.flags = Notification.FLAG_ONGOING_EVENT;        notification.flags = Notification.FLAG_AUTO_CANCEL;        mNotificationManager.notify(id, notification);        try {            Thread.sleep(time);        } catch (InterruptedException e) {            e.printStackTrace();        }    }}

更多相关文章

  1. android把字符串内容保存到指定路径
  2. Android 一个下载任务分为多个线程下载
  3. Android中内容提供者ContentProvider实现数据库增删改查
  4. Android判断当前应用通知是否打开,跳转到打开通知界面
  5. Android 多线程1
  6. Android 8.0 通知显示
  7. Android 判断应用是否开启了通知权限
  8. Android 处理多线程 UserTask
  9. Android 里子线程真的不能刷新UI吗?

随机推荐

  1. Android第一行代码学习笔记三----广播
  2. Android布局之LinearLayout weight属性的
  3. Android学习系列(29)--App调试的几个命令
  4. Android Zipalign工具优化Android APK应
  5. Android实现宫格图片连续滑动效果
  6. Android(安卓)Geofence的学习(三)总结、Dem
  7. 移动Android开发-规范文档
  8. android 关于appcompat v7出错问题与解决
  9. Android中的AIDL
  10. Android自动解除系统锁屏