如何从android中的Accessibility服务中的packageNames中删除包?

时间:2017-04-25 14:39:51

标签: android service accessibility

我有Accessibiltiy服务,可在特定应用启动时打开我的活动。

    public class Accessibility extends AccessibilityService{
  private AccessibilityServiceInfo info;
        @Override
        protected void onServiceConnected() {

            super.onServiceConnected();
            info = new AccessibilityServiceInfo();
            info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_VIEW_CLICKED;

            info.packageNames = null;
            DatabaseHandler db = new DatabaseHandler(this);
            List<AppData> blackList = db.getAllApps();

            info.packageNames = new String[blackList.size()];
            int k = 0;
            for (AppData app : blackList) {
                if(app.isBlocked() == 1) {
                    info.packageNames[k] = app.getPackageName();
                    k++;
                }
            }
            for(int i = 0; i < info.packageNames.length; i++) {
                Log.d(myTag, "BLOCKED APP = " +   info.packageNames[i]);
            }
            info.feedbackType = AccessibilityServiceInfo.FEEDBACK_SPOKEN;
            info.notificationTimeout = 100;
            this.setServiceInfo(info);

            //register Broadcastreceiver
            registerReceiver(receiver, new IntentFilter("UPDATE_BLACKLIST"));   
        }

        //Receives notification when blacklist was updated
        private final BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onServiceConnected();
            }
        };
    }

当辅助服务获得广播接收器时,它调用方法onServiceConnected(),它必须用packageNames更新列表并且它成功更新但是,如果我再次使用新的包名更新列表,我的accessibiltiy服务在我打开应用程序时仍然可以继续工作现在不在列表中。 我在日志中显示了完整列表 - 没有旧的软件包名称,但是当我打开这些应用程序时,accessibiltiy服务仍然有效。 如何在我的服务中完全更新软件包名称?

0 个答案:

没有答案