首页 > Java > java教程 > 正文

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

高洛峰
发布: 2017-01-17 14:38:41
原创
1686 人浏览过

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(http://www.jb51.net);   
        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.jb51.net");   
            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()在选择浏览器后结束进程.

更多Android调用默认浏览器打开指定Url的方法实例相关文章请关注PHP中文网!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!