Android getActiveNotifications返回null
我正在尝试读取所有当前通知。 这是我的服务:Android getActiveNotifications返回null,android,Android,我正在尝试读取所有当前通知。 这是我的服务: public class MyService extends NotificationListenerService{ @Override public int onStartCommand(Intent intent, int flags, int startId) { StatusBarNotification[] notifications = getActiveNotifications();
public class MyService extends NotificationListenerService{
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
StatusBarNotification[] notifications = getActiveNotifications();
return super.onStartCommand(intent, flags, startId);
}
}
我的主要活动是:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startService(new Intent(this, MyService.class));
}
}
当然还有我的舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ginso.stepwatcher">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MyService"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
</application>
</manifest>
但是当我调试服务时,getActiveNotifications()
返回null
。
我做错了什么?我是否错过了任何权限?我在安卓8.0上运行它