我正在开发一个基于通知的应用程序,我需要收听传入的通知.我已经能够收听来电,短信,邮件等.我不知道如何通过代码在Whatsapp上听朋友的ping或消息.这可以实际完成吗?如果是这样,怎么样?可以使用Accessibility Service,使用Package Name作为"com.whatsapp"吗?
android android-intent android-notifications android-notification-bar android-broadcast
我希望这不会违反任何规则,因为我已经尝试过按照"如何询问"指南.
我正在尝试使用NotificationListenerService读取传入的通知,它对我有用但只是部分.
第一个通知它的类型,让我们说 - whatsapp我可以得到自动收报机,文本和标题,但如果通知叠加我不再能读取消息的文本.
如何获取堆叠通知的文本?
这是我目前实现的代码:
public class NotificationService extends NotificationListenerService {
private Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
String pack = sbn.getPackageName();
String ticker = sbn.getNotification().tickerText.toString();
Bundle extras = sbn.getNotification().extras;
String title = "";
String text = "";
if (extras.containsKey("android.title")) {
title = extras.getString("android.title");
}
if (extras.containsKey("android.text")) {
if (extras.getCharSequence("android.text") != null) {
text = extras.getCharSequence("android.text").toString();
}
}
if (pack != null) {
Log.i("Package", pack); …Run Code Online (Sandbox Code Playgroud) android ×2