Redirect chrome programmatically

女生的网名这么多〃 提交于 2019-12-21 22:03:32

问题


I have been able to read the chrome content using accessibility service using the below code

<accessibility-service   xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityFlags="flagDefault"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="0"
android:canRetrieveWindowContent="true"
android:packageNames="com.android.chrome"
android:description="@string/accessibility_description"
/>

And I listen to window changed event using

public void onAccessibilityEvent(AccessibilityEvent event) {
if(AccessibilityEvent.eventTypeToString(event.getEventType()).contains("WINDOW")){
     AccessibilityNodeInfo nodeInfo = event.getSource();
     dfs(nodeInfo);
}
}

public void dfs(AccessibilityNodeInfo info){
if(info == null)
    return;
if(info.getText() != null && info.getText().length() > 0)
    System.out.println(info.getText() + " class: "+info.getClassName());
for(int i=0;i<info.getChildCount();i++){
   AccessibilityNodeInfo child = info.getChild(i);
   dfs(child);
   child.recycle();
}
}

Now based on URL content , I want to open a redirect chrome to a different page or load a static page after fetching it from the device storage. I tried to achieve it but have been unsuccessful till now. Any help would be appreciated. Thanks in advance.


回答1:


Try this code

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constant.URL_REPLACE));
        intent.setPackage("com.android.chrome");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Browser.EXTRA_APPLICATION_ID,"com.android.chrome");
        try {
            mContext.startActivity(intent);
        } catch (ActivityNotFoundException ex) {
            Log.e(TAG, "Exception = " + ex.toString());
        }


来源:https://stackoverflow.com/questions/42731897/redirect-chrome-programmatically

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