How to get the Android version number?

Asked

Viewed 486 times

1

I would like to know how to get the Android version number in which my application using Webview is running, to put in Useragent, as in the code below:

 mWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; App Mobile Android X.X.X; App v1.0)(KHTML, like Gecko)");

In which X.X.X would be the version of Android.

  • Your question is about how discover the version of Android?

  • Yes and put the user agent inside that function there.

  • Your edition invalidated my answer and made your question even wider. Reverti to the previous version.

  • 1

    Your reply helped, thank you!!!

1 answer

2


You can use the constant Build.VERSION.RELEASE.

An example of use for your case would be:

mWebView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; App Mobile Android " + Build.VERSION.RELEASE + "; App v1.0)(KHTML, like Gecko)");
  • I updated the question, can you edit the answer? I’m sorry I wasn’t clear before.

  • What do you mean by cell phone brand?

  • I wanted to discover the brand also and put together, as in the example of the user agent Google Crhome, appears cell phone model: Mozilla/5.0 (Linux; Android 6.0; Motog3 Build/MPI24.65-33.1-2) Applewebkit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.68 Mobile Safari/537.36

  • 1

    I will look for a solution, but if I do, I will ask you to create another question, since this one is the only one on the site on this subject that has an answer and can be used by other people. If it gets too generic, it’s harder to find in the future.

  • Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.