Building a browser for android. We are writing a full-fledged browser for Android. Optional web browser installation for following internal links

Honey, I am a bca student. I have to do one project in the last semester. So I decided to create a web that runs on Android OS, but I am completely for this application. So, can anyone help me on this. I have already installed all the necessary tools like jdk, android sdk 3.0, eclipse. But now I have no idea where I should start developing the browser from. So please help me ... I only have 2 months for this project. So is it possible in 2 months or not?

It depends on what you mean when developing your browser ...

Developing a browser + rendering engine from scratch is a lot of work, but you can easily create a browser based on Androids WebView using the WebViewClient and create a new UI by changing the way the user interacts with the browser.

Webview has all kinds of interceptors to intercept browser interaction, so you can easily extend it. For example, you can let the user flip through pages (like google fastflip), experiment with 3D, mapping the rendered web page in OpenGL space (like in a sphere browser), etc.

For a starting point, take a look at Alexander Kmetek's blog and his Mosambro project, which extends the Android browser with microformat support.

Sounds like a really big project and so you can't just start from scratch and record it. You should make a plan for how you want to implement all the parts, write class diagrams, etc. If you are studying computer science, you should have heard about this in previous semesters.

First you have to ask yourself if this project is possible as you can see from the comments, most people agree that you shouldn't underestimate this challenge!

I really suggest you understand the scope of this task, here source Androids browser, giving you an idea of ​​its complexity.

Creation base browser could be done in a day or two for those with Android development experience, just as others have stated that WebView provides pretty much everything you need to display a web page. There are a few tweaks for JavaScript and other functionality to validate and then after marking the main textbox for the url and go button, which is pretty much the main web browser.

The real work comes in all advanced settings. Making a browser that competes with the big guys might be a little tricky for one person in a couple of months, but making your own that works is very possible. Try!

To create a complete web browser in Android, you use a WebView.

Simple code binding:

WebView wv = (WebView) findViewById (R.id.webview1); wv = (WebView) findViewById (R.id.webView1); wv.loadUrl ("http://www.apsmind.com");

When buying a smartphone based on Android, at least one browser will be installed by default. It could be Google chrome or some other web browser designed by the manufacturer. But, if the already installed browser does not suit you, you can download any other from Play Market. If your device has several similar applications, it becomes necessary to select one of them, which will be used by default. The rest of the article will describe options for how you can accomplish this.

Default browser for Android

Today, there are quite a few web browsers designed for Android devices. They all have their own advantages and disadvantages. But, despite their differences, you can set any of them by default with three different methods... Each of them will be described in detail later in the article.

Method 1: setting OS parameters

The most popular and easiest method to install the default browser is to configure the OS. To install the main web browser, follow these steps:

    1. Go to the settings of your smartphone from the home screen or application menu.


    1. Open the item "Apps and notifications".

    1. Scroll to the bottom of the list to find the line "Additional settings"... Sometimes, in the list you may not see this section, since it is hidden in the graph "Yet".

    1. Next, select an option "Default Applications".

    1. Choose a section "Browser" to set the default web browser. Also you can set the settings for messages, phone, voice input and much more.

    1. When a window appears listing all installed browsers, check the box next to the one you want to set as default.


  1. You can now use your web browser. All links, instant messengers, will continue to open in the installed browser.

This method is really very simple, moreover, you can configure additional settings for your smartphone.

Method 2: configure web browsers

Using the settings, you can set any browser as default, except for the standard Google Chrome. You can complete this procedure in a few simple steps. Further in the article, using the mobile version of Yandex Browser and Mozilla Firefox as an example, all the steps that must be performed to install the main web browser will be described in more detail. For other browsers, the procedure will be similar.

    1. Open up mobile version browser, in the upper right or lower right corner, click on the three vertical dots to open the menu.


    1. Find the Count "Settings" or "Options" and tap it to open it.

    1. In the proposed list, find the item Set as default browser and click on it. If you use Yandex Browser, you can find this section on the home page in the search bar menu.

    1. Next, a tab will appear on the screen in which you need to click "Settings".

    1. You will be taken to the settings page "Default Application"... Now follow the same steps as described in paragraphs 5, 6 and 7 of the previous method.


This option is very similar to the method described above. After completing certain actions, you will still be taken to the "Default Applications" section. But giving preference this way, you will be able to configure the settings without leaving your web browser.

Method 3: active link

This option has the same advantages as the first method described. You can set any browser as the main one on your smartphone, if it provides such an opportunity.

This method is relevant only when you downloaded a new browser from the Play Store, or the main web browser was not previously installed on your phone.

  1. Go to the application that contains active link, click on it to go. In case a window pops up with a list of actions, select "Open".
  2. You will see a tab in which you need to select a web browser in order to open the link. This should be the browser that you want to see as the main one on your smartphone, and then check the button "Is always".
  3. The selected link will open in the selected browser, which will be installed by default.

Unfortunately, this method not relevant for applications such as Telegram, VKontakte and the like. It cannot be used in all situations. However, if you recently installed a web browser, or the defaults have been removed, this option is the perfect solution for you.

Optional web browser installation for following internal links

Certain applications have a built-in link reading system called WebView. For these programs, GoogleChrome is used as the main browser, or the WebView tool already mentioned above. If the need arises, you can change this parameter.
All well-known web browsers do not have this function, so you will have to search among the less popular browsers. You can stop at viewers different manufacturers already installed in the proprietary shell of the Android OS. Before proceeding with the steps below, make sure your smartphone has an active menu. "For developers".

To replace the WebView viewer, follow these steps:

    1. Go to the settings and find the item "System" which is at the bottom of the list.

    1. Next, open the section "For developers"... You can also find it in the main settings menu at the end of the list of actions.

    1. Now find the graph "WebView Service" and run it.

    1. If you are offered several options for viewing services, select the one that suits you best by checking the box in the checkbox area.

  1. All links will now open in the browser of your choice.

Link viewer, very rarely replaced. But you can use this option if your smartphone provides the above described option.

This article has described all possible methods of setting the browser as the main one for a smartphone based on Android. Depending on the situation, you can always find the method that suits you.

I started learning programming for Android not so long ago. After Eclips issued my first Hello Word, I immediately wanted more: there were many plans and grandiose ideas. One such idea was to write your own Browser. I think many novice programmers had this desire. These are the requirements I set and what happened in the end.

  • The program should open links global network, freely navigate the pages forward and backward;
  • Be able to download files and upload back to the network;
  • Create bookmarks and save them;
  • Be able to download links sent from other applications;
  • There should be a button home page, menus with various settings, etc.

In general, a full-fledged browser with your own hands. Let's put this into code.

The program is written based on the standard webview included in Android. As start page I use Yandex, it's a matter of taste. MainActivity will be the main Activity.

First of all, we set the markup xml file-activity_main.xml. We use LinearLayout as the main container - we wrap the ProgressBar in it to display the loading process. Next, we create another LinearLayout container - we wrap our Webview and FrameLayout in it (we use it to stretch the playing video to full screen).

View Code

LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical" tools: context = ". MainActivity">

Let's start writing code in MainActivity

Full code of MainActivity.

View full code

Import java.io.File; import android.R.menu; import android.annotation.SuppressLint; import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; import android.app.DownloadManager; import android.app.DownloadManager.Request; import android.app.KeyguardManager; import android.app.SearchManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Parcelable; import android.os.PowerManager; import android.preference.PreferenceManager; import android.provider.MediaStore; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.webkit.ConsoleMessage; import android.webkit.DownloadListener; import android.webkit.ValueCallback; import android.webkit.WebBackForwardList; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; import android.widget.SearchView; import android.widget.Toast; import android.graphics.Bitmap; import android.webkit.URLUtil; public class MainActivity extends Activity (// Boolean variable for connection status Boolean isInternetPresent = false; ConnectionDetector cd; private WebChromeClient.CustomViewCallback mFullscreenViewCallback; private FrameLayout mFullScreenContainer; private View mFullScreenView; private WebView mWebresent = 1 String urload; int final Activity activity = this; public Uri imageUri; private static final int FILECHOOSER_RESULTCODE = 2888; private ValueCallback mUploadMessage; private Uri mCapturedImageURI = null; private DownloadManager downloadManager; @Override protected void onCreate (Bundle savedInstanceState) (super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); // Create an example connection detector class: cd = new ConnectionDetector (getApplicationContext ()); // create home button final ActionBar actionBar = getActionBar (); actionBar.setHomeButtonEnabled (true); actionBar.setDisplayHomeAsUpEnabled (true); // catch intent that the file has been loaded and notify BroadcastReceiver receiver = new BroadcastReceiver () (intent @Override public void onReceive (Context, Intent context (String action = intent.getAction (); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals (action)) (loadEnd ();))); // catch intent that the file is loaded registerReceiver (receiver, new IntentFilter (DownloadManager.ACTION_DOWNLOAD_COMPLETE)); mWebView = (WebView) findViewById (R.id.web_view); mFullScreenContainer = (FrameLayout) findViewById (R.id.fullscreen_container); mWebView.setWebChromeClient (mWebChromeClient); mWebView. loadUrl ("http://yandex.ru"); handleIntent (getIntent ()); class HelloWebViewClient extends WebViewClient (@Override public void onPageStarted (WebView view, String url, Bitmap favicon) (super.onPageStarted (view, url, favicon); findViewById (R.id.progress1) .setVisibility (View.VISIBLE); setTitle ( url); urload = mWebView.getUrl (); ConnectingToInternet ();) @Override public boolean shouldOverrideUrlLoading (WebView view, String url) (view.loadUrl (url); // launch links to the market Uri uri = Uri.parse (url); if (uri.getScheme (). equals ("market")) (Intent i = new Intent (android.content.Intent.ACTION_VIEW); i.setData (uri); i.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); startActivity (i ); mWebView.canGoBack (); (mWebView.goBack ();)) // run email if (uri.getScheme (). equals ("mailto")) (Intent i = new Intent (android.content.Intent.ACTION_SEND ); i.setType ("text / html"); i.putExtra (Intent.EXTRA_SUBJECT, "Enter subject"); i.putExtra (Intent.EXTRA_TEXT, "Enter text"); i.putExtra (Intent.EXTRA_EMAIL, new String (url)); startActivity (i); mWebView.canGoBack (); (mWebView.goBack ();)) // start the call if (uri.getScheme (). Equals ("tel")) (Intent i = new Intent (android.content.Intent.ACTION_DIAL); i.setData (uri); startActivity (i); mWebView.canGoBack (); (mWebView.goBack ();)) // start the section if (uri.getScheme (). equals ("geo")) (Intent i = new Intent (android.content.Intent.ACTION_VIEW); i.setData (uri); startActivity (i); mWebView.canGoBack (); (mWebView.g oBack (); )) return true; ) @Override public void onPageFinished (WebView view, String url) (findViewById (R.id.progress1) .setVisibility (View.GONE);) @Override public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) ( ConnectingToInternet (); mWebView.loadUrl ("file: ///android_asset/error.png");)) mWebView.setWebViewClient (new HelloWebViewClient ()); // download files to the device mWebView.setDownloadListener (new DownloadListener () (@Override public void onDownloadStart (final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) (final String fileName = URLUtil.guessFileName (url, contentDisposition, mimetype); final AlertDialog.Builder downloadDialog = new AlertDialog.Builder (MainActivity.this); downloadDialog.setTitle ("Download Manager"); downloadDialog.setMessage ("Download this file to Donwload folder?" + "n" + mimetype + " n "+ url); downloadDialog.setPositiveButton (" Yes ", new DialogInterface.OnClickListener () (public void onClick (DialogInterface dialogInterface, int i) (doDownload (url, fileName); dialogInterface.dismiss ();))); downloadDialog .setNegativeButton ("No", new DialogInterface.OnClickListener () (public void onClick (DialogInterface dialogInterface, int i) ())); downloadDialog.show ();))); ) // *************************************** // ***** *********************************** // ************ ****************************** public void ConnectingToInternet () (// Get the status of the Internet connection isInternetPresent = cd. ConnectingToInternet (); // Check the Internet status: if (isInternetPresent) (// There is an Internet connection // do HTTP requests :) else (// No Internet connection Toast.makeText (this, "The Internet has fallen off !!!", Toast.LENGTH_SHORT) .show ();)) @SuppressLint ("SetJavaScriptEnabled") @Override // settings public void onResume ( ) (super.onResume (); SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences (this); if (sPref.getBoolean ("img", false)) (mWebView.getSettings (). setLoadsImagesAutomatically (false);) else (mWebView.gettings ) .setLoadsImagesAutomatically (true);) if (sPref.getBoolean ("js", false)) (mWebView.getSettings (). setJavaScriptEnabled (false);) else (mWebView.getSettings (). setJavaScriptEnabled (true);) if ( sPref.getBoolean ("cache", false)) (cache = 2;) else (cache = 1;)) // write a bookmark public void saveBm (String urlPage1, String urlTitle1) (Intent intent = new Intent (this, SaveBmActivity. class); intent.putExtra ("urlTitle", urlTitle1); intent.putExtra ("urlPage", urlPage1); startActivity (intent);) public void pref () (// Intent settings intent = new Intent (this, PreferencesActivity.class); startActivity (intent); ) // clear cache and history private void clCache () (clearCache (activity); mWebView.clearCache (true); mWebView.clearHistory (); Toast.makeText (this, "Cache and History cleared", Toast.LENGTH_SHORT) .show ();) @Override protected void onUserLeaveHint () (super.onUserLeaveHint ();) @Override public boolean onKeyDown (int keyCode, KeyEvent event) (// back button if ((keyCode == KeyEvent.KEYCODE_BACK)) (mWebView. canGoBack (); (mWebView.goBack ();) return true;) return super.onKeyDown (keyCode, event);) // catch the url of the running program private boolean handleIntent (Intent intent) (String action = intent.getAction (); if (Intent.ACTION_VIEW.equals (action)) (String url = intent.getDataString (); Toast.makeText (this, url, Toast.LENGTH_SHORT) .show (); mWebView.loadUrl (url); // load the page return true;) return false;) // download manager private void doDownload (String url, String fileName) (Uri uriOriginal = Uri.parse (url); try (Toast.makeText (MainActivity.th is, "Downloading" + fileName, Toast.LENGTH_LONG) .show (); Request request = new DownloadManager.Request (Uri.parse (url)); request.setDestinationInExternalPublicDir (Environment.DIRECTORY_DOWNLOADS, fileName); final DownloadManager dm = (DownloadManager) getSystemService (Context.DOWNLOAD_SERVICE); dm.enqueue (request); ) catch (Exception e) (Toast.makeText (this, "Error", Toast.LENGTH_SHORT) .show (); Log.e ("", "Problem downloading:" + uriOriginal, e);)) // pull the video full screen private final WebChromeClient mWebChromeClient = new WebChromeClient () (@Override @SuppressWarnings ("deprecation") public void onShowCustomView (View view, int requestedOrientation, CustomViewCallback callback) (onShowCustomView (viewOver callback public);) View view, CustomViewCallback callback) (if (mFullScreenView! = null) (callback.onCustomViewHidden (); return;) mFullScreenView = view; mWebView.setVisibility (View.GONE); mFullScreenContainer.setVisibility (View.VISIBLE); mFullScreenContainer.addView (view); mFullscreenViewCallback = callback; ) @Override public void onHideCustomView () (super.onHideCustomView (); if (mFullScreenView == null) (return;) mWebView.setVisibility (View.VISIBLE); mFullScreenView.setVisibility (View.GONE); mFullScreenContainer.setVisibility (View. GONE); mFullScreenContainer.removeView (mFullScreenView); mFullscreenViewCallback.onCustomViewHidden (); mFullScreenView = null;) // *************************** ******************* upload files to the network // openFileChooser for Android 3.0+ public void openFileChooser (ValueCallback uploadMsg, String acceptType) (// Update message mUploadMessage = uploadMsg; try (// Create AndroidExampleFolder in the sdcard File imageStorageDir = new File (Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES), "AndroidExampleFolder"); if (! imageextension )) (// Create AndroidExampleFolder in sdcard imageStorageDir.mkdirs ();) // Create camera captured image file path and name File file= new File (imageStorageDir + File.separator + "IMG_" + String.valueOf (System.currentTimeMillis ()) + ".jpg"); mCapturedImageURI = Uri.fromFile (file); // Image capture camera intent final Intent captureIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE); captureIntent.putExtra (MediaStore.EXTRA_OUTPUT, mCapturedImageURI); Intent i = new Intent (Intent.ACTION_GET_CONTENT); i.addCategory (Intent.CATEGORY_OPENABLE); i.setType ("image / *"); // Create selector file intent Intent chooserIntent = Intent.createChooser (i, "Image Chooser"); // Set cameras to file selection intent chooserIntent.putExtra (Intent.EXTRA_INITIAL_INTENTS, new Parcelable (captureIntent)); // On the choice of the image bypassing the onactivityresult method, calling the activity method startActivityForResult (chooserIntent, FILECHOOSER_RESULTCODE); ) catch (Exception e) (Toast.makeText (getBaseContext (), "Exception:" + e, Toast.LENGTH_LONG) .show ();)) // openFileChooser for Android< 3.0 @SuppressWarnings("unused") public void openFileChooser(ValueCallbackuploadMsg) (openFileChooser (uploadMsg, "");) // @SuppressWarnings ("unused") public void openFileChooser (ValueCallback uploadMsg, String acceptType, String capture) (openFileChooser (uploadMsg, acceptType);) public boolean onConsoleMessage (ConsoleMessage cm) (onConsoleMessage (cm.message (), cm.lineNumber (), cm.sourceId ()); return true;) public void onConsoleMessage (String message, int lineNumber, String sourceID) (//Log.d("androidruntime "," Show console messages, Used for debugging: "+ message);); ); // End setWebChromeClient // Get the result @SuppressWarnings ("unused") private Object data; @Override protected void onActivityResult (int requestCode, int resultCode, Intent data) (if (data == null) (return;) String urlPage2 = data.getStringExtra ("urlPage2"); mWebView.loadUrl (urlPage2); if (requestCode = = FILECHOOSER_RESULTCODE) (if (null == this.mUploadMessage) (return;) Uri result = null; try (if (resultCode! = RESULT_OK) (result = null;) else (// extract from own variable if the intent is null result = data == null? mCapturedImageURI: data.getData ();)) catch (Exception e) (Toast.makeText (getApplicationContext (), "activity:" + e, Toast.LENGTH_LONG) .show ();) mUploadMessage .onReceiveValue (result); mUploadMessage = null;)) // ***************************** public void loadEnd () (Toast .makeText (this, "File Uploaded to Donwload Folder", Toast.LENGTH_SHORT) .show ();) // @Override menu public boolean onCreateOptionsMenu (Menu menu) (// Inflate the menu; this adds items to the action bar if it is present.getMenuIn flater (). inflate (R.menu.main, menu); return true; ) // ********************************************** ******** @Override public boolean onOptionsItemSelected (MenuItem item) (switch (item.getItemId ()) (case android.R.id.home: // home button mWebView.loadUrl ("http: // yandex .ru "); return true; case R.id.item1: // back mWebView.canGoBack (); (mWebView.goBack ();) return true; case R.id.item2: // forward mWebView.canGoForward () ; (mWebView.goForward ();) return true; case R.id.item3: // reload mWebView.reload (); (mWebView.reload ();) return true; case R.id.item4: // clear the cache mWebView.clearCache (true); clearCache (activity); Toast.makeText (this, "Clear cache", Toast.LENGTH_SHORT) .show (); return true; case R.id.item5: mWebView.clearHistory (); / / clean the history Toast.makeText (this, "The history is clean.", Toast.LENGTH_SHORT) .show (); return true; case R.id.item6: saveBm (mWebView.getUrl (), mWebView.getTitle ()); / / write a bookmark return true; case R.id.item7: // bookmark bar Intent intent1 = new Intent (this , SaveBmActivity.class); startActivityForResult (intent1, 1); return true; case R.id.item8: // stop loading mWebView.stopLoading (); return true; case R.id.item9: pref (); // settings return true; case R.id.item10: // empty for now return true; case R.id.item11: // exit if (cache == 2) (clCache ();) finish (); return true; default: return super.onOptionsItemSelected (item); )) @SuppressWarnings ("deprecation") @Override public void onDestroy () (super.onDestroy (); mWebView.stopLoading (); mWebView.clearCache (true); mWebView.clearView (); mWebView.freeMemory (); mWebView. destroy (); mWebView = null;) // clear the cache void clearCache (Context context) (clearCacheFolder (context.getCacheDir ());) void clearCacheFolder (final File dir) (if (dir! = null && dir.isDirectory ()) (try (for (File child: dir.listFiles ()) (// recursively clean the directories first if (child.isDirectory ()) clearCacheFolder (child); else // then the actual child files .delete ();)) catch (Exception e) ())))

The project can be downloaded

Android allows you to create your own web browser or even create your own browser clone using the. The element itself uses the WebKit engine and has many properties and methods. We will restrict ourselves to a basic example of creating an application with which we will be able to view pages on the Internet. The latest versions use the engine from Chromium, but there is not much difference in this for simple tasks.

Let's create a new project MyBrowser and immediately replace the code in the markup file res / layout / activity_main.xml:

Now let's open the activity file MainActivity.java and declare the component, as well as initialize it - enable JavaScript support and specify the download page.

Private WebView webView; public void onCreate (Bundle savedInstanceState) (super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); webView = findViewById (R.id.webView); // enable JavaScript support webView.getSettings (). setJavaScriptEnabled (true) ; // specify the loading page webView.loadUrl ("http: // site / android");)

Since the application will use the Internet, you need to set the Internet access permission in the manifest file.

In the same place in the manifest, we modify the line for the screen by removing the title from our application (in bold):

android: theme = "@ style / Theme.AppCompat.NoActionBar">

Let's start the application. We have at our disposal the simplest web page viewer, but with one drawback. If you click on any link, then your default browser will automatically start and new page will be displayed already there. More precisely, it was like this before. On new devices, launching the application immediately opens the browser.

To solve this problem and to open links in your program, you need to override the class WebViewClient and let our application handle links. Let's add a nested class in the code:

Private class MyWebViewClient extends WebViewClient (@TargetApi (Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading (WebView view, WebResourceRequest request) (view.loadUrl (request.getUrl (). ToString ()); return true;) // For old devices @Override public boolean shouldOverrideUrlLoading (WebView view, String url) (view.loadUrl (url); return true;))

Then in the method onCreate () define an instance MyWebViewClient... It can be anywhere after the object is initialized:

WebView.setWebViewClient (new MyWebViewClient ());

Now our application has created WebViewClient which allows any specified URL selected in to be loaded into the container itself, rather than launching the browser. The method is responsible for this functionality, in which we indicate the current and required URL. Return value true says that we do not need a launch third party browser, and independently download the content from the link. In API version 24 we added an overloaded version of the method, keep this in mind.

Re-run the program and make sure the links are loaded now in the application itself. But now another problem arose. We cannot go back to the previous page. If we press the BACK button on our device, we will simply close our application. To solve the new problem, we need to handle the press of the BACK button. Add new method:

@Override public void onBackPressed () (if (webView.canGoBack ()) (webView.goBack ();) else (super.onBackPressed ();))

We have to check what supports navigation to the previous page. If the condition is true, then the method is called goBack () which takes us one step back to the previous page. If there are several such pages, then we can consistently return to the very first page. In this case, the method will always return the value true... When we return to the very first page from which we began our journey on the Internet, the value will return false and the processing of pressing the BACK button will be taken over by the system itself, which will close the application screen.

Run the application again. You now have your own web browser that allows you to follow links and return to the previous page. After reviewing the documentation, you can equip the application with other tasty goodies for your browser.

If you need to open some of the links leading to your site in the browser, and open local links in the application, then use the condition with different return values.

Public class MyWebViewClient extends WebViewClient (@Override public boolean shouldOverrideUrlLoading (WebView view, String url) (if (Uri.parse (url) .getHost () .. ACTION_VIEW, Uri.parse (url)); view.getContext (). StartActivity (intent); return true;))

A universal method that will open all local links in the application, the rest in the browser (change one line):

Public class MyAppWebViewClient extends WebViewClient (@Override public boolean shouldOverrideUrlLoading (WebView view, String url) ( if (Uri.parse (url) .getHost (). length () == 0)(return false;) Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse (url)); view.getContext (). startActivity (intent); return true; ))

Now let's complicate the example a little so that the user has an alternative to standard browsers.

To make it clearer, let's remake the example as follows. Create two activities. Place the button on the first activity to switch to the second activity, and place the component on the second activity.

In the manifest, we prescribe a filter for the second activity.

Code for the button to go to the second activity.

Public void onClick (View view) (Intent intent = new Intent ("ru.alexanderklimov.Browser"); intent.setData (Uri.parse ("http: // site / android /")); startActivity (intent);)

We created our own intent indicating the filter and provided the data - the site address.

The second activity should receive data:

Package ru.alexanderklimov.testapplication; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class SecondActivity extends AppCompatActivity (@Override protected void onCreate (Bundle savedInstanceState) (super.onCreate (savedInstanceState); setContentView (R.layout.activity_second); Uri url = getIntent (). GetData (); WebView webView = findViewById (R.id.webView); webView.setWebViewClient (new Callback ()); webView.loadUrl (url.toString ()); ) private class Callback extends WebViewClient (@Override public boolean shouldOverrideUrlLoading (WebView view, String url) (return (false);)))

In the filter for the second activity, we specified two actions.

This means that any activity (read, applications) can trigger your activity with a mini-browser in the same way. Run any old project in a separate window in the studio, or create a new one and add a button to it and write the same code that we used to click the button.

Launch the second application (the first application can be closed) and press the button. Your first application will not start with home screen, and immediately the second activity with a mini-browser. Thus, any application can launch the browser without knowing the class name of your activity, but using only the string "ru.alexanderklimov.Browser" transmitted to Intent... That being said, your activity with the browser should have a default category and data. Let me remind you:

You can represent your string as a string constant and tell all potential users of your browser how they can run it on their own. But Android already has such a ready-made constant ACTION_VIEW which according to the help documentation is the following:

Public static final java.lang.String ACTION_VIEW = "android.intent.action.VIEW";

Let's rewrite the code for the button in the second application

Intent (android.content.Intent.ACTION_VIEW, Uri.parse ("http: // site / android /")); startActivity (intent);

What will happen this time? We remember that we have two actions, including and android.intent.action.VIEW... This means that our first application with a browser must also recognize this command when some application on the user uses this code. The emulator has at least one such "Browser" program, and now our second activity from the first application has been added to it. A choice of two applications will appear on the screen.

And if you remove all alternative browsers and leave only your program, then there will be no choice. Your browser will become the main browser. And if some application wants to launch a web page in the specified way, then your program will open.

A small note. If you replace last line to this one:

StartActivity (Intent.createChooser (intent, "Meow ..."));

Then in the program selection window, instead of the top line "Open with" or its local translation, your line will appear. But this is not the main thing. If, for some reason, there is not a single browser on the device, then this version of the code will not cause the application to crash, unlike the original version. Therefore, use the proposed option for the sake of reliability.

Standard browsers in devices on Android base often do not meet the daily needs of demanding users. In this operating system there are many high-quality and functional Internet browsers. We have collected the best browsers for Android in this article.

Firefox rightfully bears the title of one of the best mobile browsers on Android. Over the years of its presence on this operating system, Mozilla development has acquired a mass of functions and received a refined modern interface... Firefox for Android is a balance of functionality, usability and speed of use. Mobile Browser from Mozilla loses in speed to the same Google Chrome, but many of Firefox's features are made much more pleasant and convenient.

The proprietary Gecko engine that Firefox uses supports almost all modern web standards, and there are also extensions for it with additional functionality, just like in the desktop version of the browser. Among the main functions of Fiefox: synchronization of all data between browsers using a special account, safe surfing, a convenient start panel, a lot of extensions, a reading mode.



The most popular browser not only on computers, but also on mobile devices ah is Google Chrome. Not surprisingly, it almost always comes pre-installed on the most popular mobile OS. Chrome has gained its popularity quite deservedly - it is fast, relatively functional, simple and convenient, and it is also well integrated with Google services and the desktop version of the browser (there is a complete synchronization of data and tabs). Integration with Google services can sometimes be useful, for example - translating text on pages with using google Translator or voice search.

Chrome also takes care of user safety - the browser has a built-in special filter for sites that can be dangerous for Android devices. There is some semblance of data compression technology. It is not as perfect as Opera, but it still saves data transmitted over Wi-Fi and mobile Internet quite well. There is an incognito mode for anonymous visits to sites. Perhaps the only one Chrome flaw at the moment - no support for extensions. For those looking to try all the new features first, there is Chrome Beta and Dev. These browser versions are updated faster and more often - all innovations are tested in them.



Mobile browsers from the Norwegian company Opera are also one of the most popular, functional and fast-growing ones on the Android platform. These guys, over the years of their work, have definitely been able to derive the formula for an almost ideal Internet browser for smartphones and tablets. Opera has almost everything you need ordinary user: fast surfing, convenient classic express panel, data synchronization with the desktop version, anonymous mode, convenient search with hints from the address bar, as well as one of the main features - traffic compression.

The guys from Opera ate the dog on technologies to save traffic. Mobile Opera with activated Turbo mode can cut costs mobile internet two or even three times. For those who are especially interested in traffic consumption, there is Opera Mini - it has savings on by default, but sometimes the appearance of sites suffers from this. Also, the mini version is much lighter and faster than regular Opera. Another one strong point eponymous browser - beautiful and pleasant appearance. Opera has always been famous for one of the most stylish interfaces in browsers. If you want to compress all traffic on your device, then pay attention to the application.



Dolphin is an alternative browser for Android with tons of extra features and functions out of the box. Among these, it is worth noting the support Adobe flash, from which almost everyone has abandoned, but it is still used a lot where, the use of various themes to change the interface, support for unique add-ons and control of convenient and simple gestures. All this is available at once - no additional settings... And Dolphin is fast, secure, free and always up-to-date - the developers release browser updates almost every week.


Puffin is a mobile web browser similar in concept to Dolphin. Here, too, there is a beautiful and convenient interface, there are many possibilities, and also Puffin is as fast as the "dolphin". Basically, the Puffin browser is suitable for weak devices, since it provides for a special technology of "lightweight" web surfing - the pages are first loaded on cloud service Puffin, they are optimized there and come to the device screen in a light form. At the same time, the quality and appearance of the pages practically do not suffer from a broken layout or a decrease in quality.

Also in Puffin it is worth noting a number of additional features:

  • full support for Adobe Flash for games (virtual joystick on the screen);
  • encryption of traffic through a cloud service;
  • mouse emulation;
  • the ability to upload files first to the cloud, and then to the device;
  • installing extensions;
  • interface themes.
The Puffin browser is an excellent choice for weak devices, but at the same time, the functionality in this Internet browser is not occupied.



The Russian company Yandex has succeeded in creating its own browser for Android mobile devices. Yandex Browser for this platform is an excellent solution for users from the CIS. This Internet browser is directly saturated with integration with the services of Yandex itself and other local social networks/ portals. For example, the search bar in the browser suggests the necessary sites and understands queries at a glance, and inside the application you can also view information about the weather and traffic jams.