Clear another app's notification via the Accessibility API

纵然是瞬间 提交于 2019-12-12 01:36:33

问题


My app is using the Accessibility API to catch notifications generated by other apps and act on them. I'd like to add a feature where the original notification (generated by some other app) can be cancelled.

The usual method of using the notification manager won't work since you have to be the one who created the notification to be able to clear it. The accessibility API lets me read a different app's notification but does it allow you to clear it as well?

Thanks!


回答1:


No, you cannot clear other app's notifications (thankfully).




回答2:


public void onAccessibilityEvent(AccessibilityEvent event) {
        // TODO Auto-generated method stub
        if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
            //Do something, eg getting packagename
            final String packagename = String.valueOf(event.getPackageName());
            final String text = String.valueOf(event.getText());

            if(TARGET_PACKAGE.equals(packagename)){
                Notification n = (Notification) event.getParcelableData();

                try{
                        n.deleteIntent.send(this,0,new Intent());
                }catch(Exception e){e.printStackTrace();}
        }
} 

If deleteIntent of the notification was defined already, can cancel it.



来源:https://stackoverflow.com/questions/11661023/clear-another-apps-notification-via-the-accessibility-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!