WebView显示VR或者显示H5的VR链接

效果图镇楼 

                       在学会怎么去用WebView 显示VR效果并适配个个手机都能出来的效果后加急写了这篇博客,本尝试了很多方法拿WebView去直接.loadUr 的时候发现在百分之 60 的手机能上能显示出VR效果那百分之40其实显示了我们H5提供的App下载网页,所以一看就知道那百分之40的手机不能不管只能领找方案。

          所以 我简单说一下我最新的处理方案    1  用腾讯的 X5 SDK 进行对Web的显示

                                                                       2  使用Google  的VR处理

       步骤1    导依赖  和架包 

                 

 implementation 'com.tencent.mars:mars-core:1.2.1'
    implementation 'com.just.agentwebX5:agentwebX5:2.0.0'

X5 SDK的下载地址

           将上方的So库全部导入之后进行查看  在build.gradle  是否有

implementation files('libs/tbs_sdk_thirdapp_v3.6.0.1234_43608_80510.jar')

这行代码 如果没有那么进行添加

       MainAcivity  

            

public class MainActivity extends AppCompatActivity {

    //private VrPanoramaView mVrPanoramaView;
    AgentWebX5 mAgentWeb;
    private View top_view;
    private LinearLayout layout_root;
    private RelativeLayout rl_fu;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        initView();

//传过来的 URL  地址    这边给一个 URLVR的地址方便大家测试


//public static final String BIGURL = "http://newqj.homehawkeye.com//1531471969865_o_1ci9ddq1l8c49lu8f9c1t7t1236//html/index.html?pano_id=CQVHSWRqQICcBKYW";


    String vrurl = getIntent().getStringExtra("url");
        String name = getIntent().getStringExtra("name");

        long l = System.currentTimeMillis();
        String  s="And"+l+"XZ_PQ";
//我们公司使用的加密工具如   读者在用的时候可以进行删除从而直接加载URL
       String d = DesUtil.encryptThreeDESECB_VR(s);
       String url = vrurl +"&d="+d;
//  一下是核心代码
        mAgentWeb = AgentWebX5.with(this)
                .setAgentWebParent(layout_root, new LinearLayout.LayoutParams(-1, -1))//
                .useDefaultIndicator()
                .defaultProgressBarColor()
                .setWebChromeClient(new SubWebChromeClient())
                .setWebViewClient(new SubWebViewClient())
                .setSecutityType(AgentWebX5.SecurityType.strict)
                .createAgentWeb()
                .ready()
                .go(url);
//  go方法中填写 我们 的URL 地址   如果没有加密可以直接写入

    }

    private void initView() {
        top_view = (View) findViewById(R.id.top_view);
        layout_root = (LinearLayout) findViewById(R.id.layout_root);
        rl_fu = (RelativeLayout) findViewById(R.id.rl_fu);
    }

    private class SubWebChromeClient extends WebChromeClient {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress == 100) {
                rl_fu.setVisibility(View.VISIBLE);
            }
        }
    }

    private class SubWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }
    }
}

      既然  代码有那么布局我也要分享出来   这是MainActivity的 布局

         

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/top_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/white" />

    <LinearLayout
        android:id="@+id/layout_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/top_view"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/layout_title_bar"
            android:layout_width="match_parent"
            android:layout_height="44dp"
           >


            <RelativeLayout
                android:id="@+id/rl_back"
                android:layout_width="48dp"
                android:layout_height="match_parent">



            </RelativeLayout>




            <RelativeLayout
                android:id="@+id/rl_share"
                android:layout_width="48dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true">


            </RelativeLayout>



        </RelativeLayout>
    </LinearLayout>


    <RelativeLayout
        android:id="@+id/rl_fu"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/top_view"
        android:layout_marginTop="44dp"
        android:visibility="gone">

        <LinearLayout
            android:id="@+id/ll_property_detail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="57dp"
            android:orientation="vertical">


        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_check_report"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="93dp"
            android:orientation="vertical">



        </LinearLayout>


        <RelativeLayout
            android:id="@+id/rl_guide1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/ll_menu_shou"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:orientation="vertical">


            </LinearLayout>


        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rl_guide2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:visibility="gone">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="65dp">


                <LinearLayout
                    android:id="@+id/ll_menu_shou2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:orientation="vertical">


                </LinearLayout>


                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="13dp"
                    android:layout_toRightOf="@+id/ll_menu_shou2"
                    android:text="点击查看该楼盘报告"
                  />
            </RelativeLayout>


        </RelativeLayout>

    </RelativeLayout>


</RelativeLayout>

   我们用的X5 需要去初始化所一我们去APP 中进行初始化   , App继承    Application

ublic class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        initX5WebView();
    }

    private void initX5WebView() {
        //搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
            @Override
            public void onViewInitFinished(boolean arg0) {
                //x5內核初始化完成的回调,为true表示x5内核加载成功,否则表示x5内核加载失败,会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
            }
        };
        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);
    }


}

还有就是 去 把  App在清单文件进行添加

效果图

猜你喜欢

转载自blog.csdn.net/qq_42046338/article/details/82147139