未在“设置-Android Studio-Java”中为应用启用显示NotificationListenerService >> [

问题描述 投票:0回答:1
我对android开发有点陌生,并试图制作一个可以监听设备上出现的新通知的应用程序,但是当我使用以下语句启用设置时,我在设置中没有得到我的应用程序名称。我已经通过Android developers NotificationListenerService并添加了服务AndroidMainfest。我通过此意图打开设置活动:

Intent intent = new Intent("android.settings.NOTIFICATION_LISTENER_SETTINGS");

以下是我的NotificationListener class

public class NotificationListener extends NotificationListenerService { private final String TAG = this.getClass().getSimpleName(); private final String Notification_Settings = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"; @Override public void onCreate() { super.onCreate(); startActivity(new Intent(Notification_Settings)); } @Override public void onNotificationPosted(StatusBarNotification sbn) { Bundle extras = sbn.getNotification().extras; String title = extras.getString("android.title"); String text = extras.getCharSequence("android.text").toString(); Log.i(TAG, title + " " + text); } @Override public IBinder onBind(Intent i) { return super.onBind(i); } }

最后,我在主要活动中调用该服务

Intent i = new Intent(getApplicationContext(), NotificationListener.class); startService(i);

我不知道我错过了什么。请帮我。谢谢!

编辑:

[C0中的服务:

AndroidManifest

我对android开发有点陌生,正在尝试制作一个监听我设备上出现的新通知的应用程序,但是当我使用以下语句启用设置时,...
java android android-studio android-service notification-listener
1个回答
0
投票
[中的'L'>

<service android:name=".NotificationListener" android:label="@string/app_name" android:permission="android.permission.BIND_NOTIFICATION_lISTENER_SERVICE"> <intent-filter> <action android:name="android.service.notification.NotificationListenerService" /> </intent-filter> </service>

© www.soinside.com 2019 - 2024. All rights reserved.