I am working with NotificationListnerService
it is working fine after some time it can not work and specially after device is boot it is not starting i have given all permissions which are required for listner here is my code.
public class Whatsapp_listner extends NotificationListenerService
{
private static final String TAG = "NotificationListener";
private static final String WA_PACKAGE = "com.whatsapp";
@Override
public void onListenerConnected() {
super.onListenerConnected();
Log.i("tag","Listner conneted");
}
@Override
public void onCreate() {
super.onCreate();
}
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
if (!sbn.getPackageName().equals(WA_PACKAGE)) return;
long yourmilliseconds = sbn.getPostTime();
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
Date resultdate = new Date(yourmilliseconds);
String date = sdf.format(resultdate);
SimpleDateFormat my_time=new SimpleDateFormat("hh:mm aa");
Date timer=new Date(yourmilliseconds);
String time=my_time.format(timer);
String modifiyedUniq = sbn.getUid() + sbn.getId() + sbn.getTag();
Log.e(TAG, "Notification Key :: " + sbn.getKey());
Log.e(TAG, "Notification Id :: " + sbn.getId());
Log.e(TAG, "Notification postTime :: " + time);
Log.e(TAG, "Notification From :: " + sbn.getPackageName());
Log.e(TAG, "Notification TikerText :: " + sbn.getNotification().tickerText);
Log.e(TAG, "Notification Title :: " + from);
Log.e(TAG, "Notification Text :: " + message);
}
@RequiresApi(api = Build.VERSION_CODES.P)
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
if (sbn.getPackageName().equals(WA_PACKAGE)){
Log.i("notifyier", String.valueOf(sbn.getNotification().getSmallIcon().getResId()));
Log.i("notifyier", String.valueOf(sbn.getNotification().extras.get("android.text")));
int id=sbn.getNotification().getSmallIcon().getResId();
}
}
This is working fine but after some time and after boot completes is does not work and i using broadcast receiver
to start ListnerService
but still it is not working
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…