我已经实现了NotificationListenerService,但它无法正常工作.这是服务:
public class NotificationListener extends NotificationListenerService {
@Override
public void onCreate() {
Log.d("MYAPP", "Created");
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.d("MYAPP", "Notification");
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的清单文件中实现了这个:
<service android:name="com.rodrigopontes.whatsappbubbles.NotificationListener"
android:label="Test"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" >
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)
这是我从MainActivity初始化它的方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
startService(new Intent(this, NotificationListener.class));
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!