Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old May 7th, 2010, 06:57 PM   #1 (permalink)
New Member
 
Join Date: Apr 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default User-Agent string in Activity

I have an activity inside which I want to get the User-Agent string which is available to WebKit. I need to transmit the user-agent to the server on every server request. I don't want to hard code any fixed user agent string in my application because we want to track which devices are being used with our application and the best way to do that would be to use what comes built in with the device (inside WebKit).

Is there any way I can get that user agent that WebKit uses inside my activity? Just FYI...I don't have any WebView. I just have a normal activity with some layouts and buttons. I couldn't find any documentation. Any ideas? Thanks in advance.

satb is offline  
Reply With Quote
Sponsors
Old May 10th, 2010, 09:49 AM   #2 (permalink)
New Member
 
Join Date: Apr 2010
Posts: 4
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Noone knows the answer?

Quote:
Originally Posted by satb View Post
I have an activity inside which I want to get the User-Agent string which is available to WebKit. I need to transmit the user-agent to the server on every server request. I don't want to hard code any fixed user agent string in my application because we want to track which devices are being used with our application and the best way to do that would be to use what comes built in with the device (inside WebKit).

Is there any way I can get that user agent that WebKit uses inside my activity? Just FYI...I don't have any WebView. I just have a normal activity with some layouts and buttons. I couldn't find any documentation. Any ideas? Thanks in advance.
satb is offline  
Reply With Quote
Old May 11th, 2010, 04:41 PM   #3 (permalink)
Member
 
Join Date: Sep 2009
Location: Birmingham, UK
Posts: 148
 
Device(s): G1 (Developer model), HTC Tattoo, Nexus One.
Thanks: 1
Thanked 26 Times in 22 Posts
Default

The information you're after is easy to get if you have a WebView object.
I'm not aware of any other way to get it. Although to be honest I only spent 2 minutes looking. (I stopped when I found the WebView solution.)

The code below is from one of my apps where I use a WebView to show an about/help page. I added the last 2 lines to get the User Agent string.

Code:
public class AboutActivity extends Activity {
	private WebView m_webview = null ;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about) ;
		
		m_webview = (WebView) findViewById(R.id.aboutview);
		m_webview.getSettings().setJavaScriptEnabled(false);
		m_webview.loadUrl("file:///android_asset/about.html") ;

		String ua = m_webview.getSettings().getUserAgentString() ;
		Log.i("AboutActivity", "UA = "+ua) ;
	}
}
And I get this result:

Code:
UA = Mozilla/5.0 (Linux; U; Android 2.1; en-us; sdk Build/ERD79) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17
Best of luck finding a alternative solution, if that won't work for you.

Regards,

Mark
markb is offline  
Reply With Quote
Reply

Bookmarks

Tags
user-agent, webkit, websettings, webview


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the User Agent String setting on stock Android Browser Gambit Sprint Hero - Support and Troubleshooting 18 November 29th, 2011 12:07 PM
Please help User Agent umeree Introductions 1 January 3rd, 2011 11:05 AM
User Agent/web mode bug DotMpeg Samsung Epic 4G 0 September 19th, 2010 10:28 AM
Altering User Agent? tunnie Android Lounge 0 August 1st, 2009 06:06 AM



All times are GMT -5. The time now is 12:19 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo