我正在开发一个android应用程序,我想要一个用户无法清除的状态栏通知。有人知道怎么做吗?我见过他们使用类似skipble的应用程序,在使用应用程序时出现不可清除的通知。
另外,当用户单击/按下通知时,我希望它返回到已经运行的应用程序实例。现在它启动了一个新实例。就像skimple应用一样,我只想返回已经运行的应用实例。
谢谢。

最佳答案

我找到了解决这个问题的办法。我使用flag_continuous_事件使通知持续。代码如下:

  String ns = Context.NOTIFICATION_SERVICE;
  NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.mypic;
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, tickerText, when);
    notification.flags = Notification.FLAG_ONGOING_EVENT;

    Context context = getApplicationContext();
    CharSequence contentTitle = "Title Text";
    CharSequence contentText = "Content text.";

    Intent intent = new Intent(this, MyClass.class);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    final int HELLO_ID = 1;
    mNotificationManager.notify(HELLO_ID, notification);

关于android - Android状态栏通知:使其无法清除并让它返回应用程序(不启动新实例),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6866265/

10-11 22:40
查看更多