我需要从NLService线程调用延迟方法(runnable)。但是这个方法永远不会被调用。我将不胜感激任何帮助。Android - 从Worker线程(NotificationListenerService线程)运行延迟任务
public class NLService extends NotificationListenerService {
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
if(sbn.getPackageName().contains("mv.purple.aa")){
AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
//This is the code I am having issues with.
//I used this code to call the method. However it is not working.
private Handler handler = new Handler();
handler.postDelayed(runnable, 100);
}
}
//I want to call the following method
private Runnable runnable = new Runnable() {
@Override
public void run() {
foobar();
}
};
}
是 'onNotificationPosted(...)' 叫什么名字?你的包名是否正确? –
请更具体:哪个不叫?方法,if块等 – cbrulak
是@PhilippJahoda,'onNotificationPosted(...)'被调用。 – Shaamil