我正在开发一个基于通知的应用程序,我需要收听传入的通知.我已经能够收听来电,短信,邮件等.我不知道如何通过代码在Whatsapp上听朋友的ping或消息.这可以实际完成吗?如果是这样,怎么样?可以使用Accessibility Service,使用Package Name作为"com.whatsapp"吗?
android android-intent android-notifications android-notification-bar android-broadcast
我的应用程序使用a NotificationListener来读取来自各种第三方应用程序的消息,例如WhatsApp.
到目前为止,如果只有一个聊天未读,我能够发送回复,代码如下.
但是,在WhatsApp的情况下,getNotification().actions当未读取两个以上的聊天时返回一个空对象,因为消息被捆绑在一起.正如您在下面的图片中看到的,如果通知被扩展,还有一个选项可以发送直接回复,因此我确信可以利用它,我认为像PushBullet这样的应用程序正在使用此方法.
我怎样才能访问该通知的RemoteInput?
public static ReplyIntentSender sendReply(StatusBarNotification statusBarNotification, String name) {
Notification.Action actions[] = statusBarNotification.getNotification().actions;
for (Notification.Action act : actions) {
if (act != null && act.getRemoteInputs() != null) {
if (act.title.toString().contains(name)) {
if (act.getRemoteInputs() != null)
return new ReplyIntentSender(act);
}
}
}
return null;
}
public static class ReplyIntentSender {
[...]
public final Notification.Action action;
public ReplyIntentSender(Notification.Action extractedAction) {
action = extractedAction;
[...]
}
private boolean sendNativeIntent(Context context, String message) {
for (android.app.RemoteInput rem …Run Code Online (Sandbox Code Playgroud) android notification-listener android-7.0-nougat remote-input
我只是签出Application,正在后台自动回复WhatsApp消息。我也尝试这样做,但无法成功。我试过了
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)
但是它打开WhatsApp应用程序:(,不发送消息。
我浏览了几个链接:Question1,Question2也对此发表了文章,但没有得到满意的答案。
该应用程序正在访问的通知来获得消息,并回答了,我也尝试过使用阅读通知NotificationListenerService,并获得成功读取消息:),但不能发送回复它,我想知道他们是如何发送消息在后台而不打开应用程序。
使用辅助功能服务我能够阅读通知栏标题和消息,我面临的问题是当第一次通知出现时我正在完美地阅读所有这些但是在第一次通知后,我只获得标题和文本"你有2条消息"等等,而不是整个消息.等待你的专家意见.
代码:
@Override
protected void onServiceConnected()
{
Log.d("AccessibilityServiceNotification", "ServiceConnected");
try
{
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.notificationTimeout = 100;
setServiceInfo(info);
}
catch(Exception e)
{
Log.d("ERROR onServiceConnected", e.toString());
}
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event)
{
try
{
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Parcelable data = event.getParcelableData();
if(data !=null)
{
Notification notification = (Notification) data;
RemoteViews remoteView = notification.bigContentView;
ViewGroup localView = (ViewGroup) inflater.inflate(remoteView.getLayoutId(), null);
remoteView.reapply(getApplicationContext(), localView);
Resources resources = null;
PackageManager pkm = getPackageManager(); …Run Code Online (Sandbox Code Playgroud)