Home > Java > javaTutorial > Android calls the default browser to open the method instance of the specified Url

Android calls the default browser to open the method instance of the specified Url

高洛峰
Release: 2017-01-17 14:38:41
Original
1748 people have browsed it

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~~~");  
        }  
}
Copy after login

onResume() works when there is no default browser. When there is no default browser, a prompt will pop up indicating which browser to open it with. If you click Cancel, a black background will appear. To prevent the black background from appearing, onsume() is called again to open the browser.

onStop() ends the process after selecting the browser.

For more Android method examples of calling the default browser to open the specified Url, please pay attention to PHP for related articles Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template