以编程方式重定向Chrome [英] Redirect chrome programmatically

查看:112
本文介绍了以编程方式重定向Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够使用以下代码使用辅助功能读取chrome内容

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();
}
}

现在基于URL内容,我想在从设备存储中提取重定向镶边后将其打开到其他页面或加载静态页面.我试图实现它,但直到现在仍未成功.任何帮助,将不胜感激.预先感谢.

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.

推荐答案

尝试此代码

 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());
        }

这篇关于以编程方式重定向Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆