Android panel status notification: make it unclean and return it to the application (do not start a new instance)

I am developing an Android application and I want the status bar notification not to be cleared by the user. Does anyone know how to do this? I saw them with applications like Skimble, where an incomprehensible notification appears when using the application.

In addition, when the user presses / presses the notification, I want him to return to the application instance that is already running. Now he is launching a new instance. Again, as a Skimble application, I just want to return to an already running instance of the application.

Thank.

+5
source share
3

. FLAG_ONGOING_EVENT, . :

  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);
+4

NotificationCompat.Builder

NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("MyApp") .setContentText("MyMsg") .setOngoing(true);

Google.

+3

notification.setLatestEventInfo , Notification.builder, 2.X API, NotificationComacpt.Builder, , . setDeleteIntent , , . , .

0

All Articles