Persistent service icon in notification bar

前端 未结 2 1370
醉话见心
醉话见心 2020-12-13 20:02

I am trying to figure out how to show that my service is running with a persistent notification icon. Many examples I\'ve found only send a dismissable message to the notifi

2条回答
  •  一个人的身影
    2020-12-13 20:36

    it should be the same as a dismissable message except you change the Flag.

    Notification.FLAG_ONGOING_EVENT

    instead of

    Notification.FLAG_AUTO_CANCEL

    When a notification is clicked the intent you send is run, so you make sure that Activity does whatever task you want.

    private void showRecordingNotification(){
        Notification not = new Notification(R.drawable.icon, "Application started", System.currentTimeMillis());
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, main.class), Notification.FLAG_ONGOING_EVENT);        
        not.flags = Notification.FLAG_ONGOING_EVENT;
        not.setLatestEventInfo(this, "Application Name", "Application Description", contentIntent);
        mNotificationManager.notify(1, not);
    }
    

提交回复
热议问题