检测敬酒消息消息

2023-09-05 11:03:32 作者:我很怪但我不坏

我不认为这是可能的,因为我还没有发现的SDK文档(但)在任何事情。

I don't think this is possible, as I haven't found anything in the SDK documentation (yet).

不过,我可以做的知道,如果它可以写入其中记录吐司消息的应用程序。登录该应用程序显示了它和什么包含显示的消息。

But I could do with knowing if its possible to write an application which logs Toast messages. Logging which application showed it and what the message displayed contained.

这是一个完全个人的努力来创建一个应用程序,它可以检测到敬酒的消息。因为东西在我的手机正在创造举杯说:送......大约每天一次,对我的生活,我不能追查问题的应用程序(服务类)。我想这可能是Gmail或Evernote的,但发送有敬酒的消息略有不同。我要为建立一个应用程序,因为1)我不知道,如果LogCat中会显示任何东西,和2)我不想让我的个人/ dev的手机插在电脑所有的时间(如送...消息出现如此罕见)。

This is an entirely personal endeavour to create an app which can detect the toast messages. Because something on my phone is creating a toast saying "Sending..." about once per day, and for the life of me I can't track down the offending application (Service class). I thought it might be GMail or Evernote, but there toast messages for sending are slightly different. I'm going for building an app because 1) I don't know if LogCat would show anything, and 2) I don't want to keep my personal/dev phone plugged in to a PC all the time (as the "Sending..." message occurs so infrequently).

推荐答案

有可能追上消息/通知用的辅助服务,看看这个。

It's possible to catch Messages/Notifications with an Accessibility Service, have a look at this.

您可以扩展类AccessibilityService并重写方法 onAccessibilityEvent()来实现这样的:

You can extend the class AccessibilityService and override the method onAccessibilityEvent() to implement something like this:

public void onAccessibilityEvent(AccessibilityEvent event) {
    if(event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
        return; // event is not a notification

    String sourcePackageName = (String)event.getPackageName();

    Parcelable parcelable = event.getParcelableData();
    if(parcelable instanceof Notification){
        // Statusbar Notification
    }
    else{
        // something else, e.g. a Toast message
        String log = "Message: "+event.getText().get(0)+" [Source: "+sourcePackageName+"]";
        // write `log` to file...
    }
}

注:我在Android 2.2这没有工作(它似乎并没有赶上祝酒词),但它的工作在Android 4.0

Note: This didn't work for me on Android 2.2 (it doesn't seem to catch Toasts), but it worked on Android 4.0.