当前位置: 首页 > 新闻动态 > 软件编程

Android调用默认浏览器打开指定Url的方法实例

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:业务员有需求要将一个wap站在手机上以App的形式打开,还不要嵌套WebView,只能以浏览器打开.查了点资料,就有了下面这代码

复制代码 代码如下:
package com.gzz.whyinzi;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {
    private static final String TAG = "ActivityDemo";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       
        Intent intent = new Intent();       
        intent.setAction("android.intent.action.VIEW");   
        Uri content_url = Uri.parse(https://www.);  
        intent.setData(content_url); 
        startActivity(intent);

       
    }

        @Override 
        protected void onResume() { 
            super.onResume();
            Intent intent = new Intent();       
            intent.setAction("android.intent.action.VIEW");   
            Uri content_url = Uri.parse("http://play.");  
            intent.setData(content_url); 
            startActivity(intent);
            Log.e(TAG, "start onResume~~~"); 
        } 

        @Override 
        protected void onStop() { 
            super.onStop(); 
            this.finish();
            Log.e(TAG, "start onStop~~~"); 
        } 
}

onResume()在没有默认浏览器的时候就起作用了,当没有默认浏览器的时候会弹出提示以哪个浏览器打开,如果点击取消就会出现黑色背景,为防止出现黑色背景,onsume()重新调用打开浏览器.

onStop()在选择浏览器后结束进程.

免责声明:转载请注明出处:http://m.jing-feng.com.cn/news/204101.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!