- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试实现在 android 4.3 中添加的 NotificationListnerService,但我无法获取通知详细信息。
我的代码如下
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setContentTitle("notification test");
mBuilder.setContentText("Notification text");
mBuilder.setAutoCancel(true);
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(1, mBuilder.build());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
public class NotificationListenerTesting extends NotificationListenerService{
public static String TAG = "NotificationListenerTesting";
//private StatusBarNotification[] mStatusBarNotification;
@Override
public void onCreate(){
super.onCreate();
Log.d(TAG, "Inside on create");
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
TAG = "onNotificationPosted";
Log.d(TAG, "id = " + sbn.getId() + "Package Name" + sbn.getPackageName() +
"Post time = " + sbn.getPostTime() + "Tag = " + sbn.getTag());
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
TAG = "onNotificationRemoved";
Log.d(TAG, "id = " + sbn.getId() + "Package Name" + sbn.getPackageName() +
"Post time = " + sbn.getPostTime() + "Tag = " + sbn.getTag());
}
}
Android list 文件是
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notificationtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.notificationtest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.notificationtest.ResultActivity"></activity>
<service android:name="com.example.notificationtest.NotificationListenerTesting"
android:label="notification"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>
</application>
</manifest>
但是在通知点击或通知后 NotificationListenerService 没有被调用后,这有什么问题还是我错过了什么?如何实现?
最佳答案
您需要授予对应用的访问权限才能阅读通知: “设置 > 安全 > 通知访问”并检查您的应用。
关于android - NotificationListenerService 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17926236/
我有一个 NotificationListenerService 和一个: @Override public void onNotificationPosted(StatusBarNotificati
NotificationListenerService可以用在android wear上吗? orb 是否有某种监听器可以监听可穿戴设备中的调用或通知? 最佳答案 通常我会做的是有一个电话和一个可穿戴
在扩展新的(SDK18,JB-4.3)NotificationListenerService 的服务中,我想获取通知的状态栏图标。 mStatusBarNotification.getNotifica
我在创建扩展 android.service.notification.NotificationListenerService 的服务时遇到问题 根据 https://developer.androi
在 android 4.4 中,我发现一些用户使用我实现的 notificationListenerService 将停止工作。我自己也亲眼见过。 我从来没有设法在它发生时捕捉到任何 logcat,但
我希望这不会违反任何规则,因为我已尝试遵循如何提问指南。 我正在尝试使用 NotificationListenerService 读取传入的通知,它对我有用,但只是部分有用。 它的第一个通知类型,比方
应用程序第一次因为一些错误而崩溃后,再次创建并绑定(bind)了 NLService,但是在第 2 次或第 3 次之后......,不再创建和绑定(bind) NLService,即使是复选框 设置
我正在尝试实现在 android 4.3 中添加的 NotificationListnerService,但我无法获取通知详细信息。 我的代码如下 public class MainActivity
随着 Android M 中 Doze 的引入,Android 在 Doze 期间对后台执行的限制越来越多。有人可以详细说明在扩展 Android 自己的服务时是否同样适用。比如Notificatio
我有一个派生自 NotificationListenerService 的类,它会在应用程序启动时自动为我创建和启动。但是,我想稍后从 Activity 中懒惰地启动该服务,而不是在应用程序启动时自动
我在我的 android 应用程序中从 Intentservice 启动前台服务,服务开始通知。这就是我开始服务的方式: Intent intent = new Intent(this, Naviga
我现在已经尝试了 10 多个小时,但我似乎无法考虑任何其他事情。我尝试了互联网上所有可能的示例,但没有成功。 我有扩展NotificationListenerService的NotificationM
我有一个 app还有一个 NotificationListenerService。当我在该 NotificationListenerService 中添加断点时,断点似乎停止了执行,但调试器无法识别它
我已经实现了 NotificationListenerService,但它不工作。这是服务: public class NotificationListener extends Notificatio
是否可以阅读在用户移动时定期显示的 Google map 导航通知? 例如,距离下一回合的剩余距离会定期更新。为此,我尝试使用 NotificationListenerService,但当我尝试使用
我会收听 WhatsApp 消息等通知。 但每次通知进入 NotificationListenerService 时都会触发两次。 有人知道这个问题吗?? 这是 AndroidManifest.xml
我在写 NotificationListenerService , 我想在其中获取发送到状态栏的通知的详细信息。 但我们唯一得到的是 Ticket text ,在某些情况下它是 null。 最佳答案
下面是我捕获通知的代码。我不明白为什么 onNotificationPosted 没有被解雇。 我正在通过“设置”>“安全”授予我的应用通知访问权限,MyNotifService 中的 onCreat
我有一个简单的 NotificationListenerService 实现来测试新的 4.3 API。该服务本身曾经工作过。之后,我添加了在添加特定包的通知时发送广播。现在,只要我启动该服务,它就会
我在对抗 NotificationListenerService 时运气不佳。我尝试了很多在这里和那里找到的食谱,尤其是关于……但它的效果很不一致。 先看代码: list :
我是一名优秀的程序员,十分优秀!