Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old May 7th, 2010, 06:57 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 4
 
Device(s):
Carrier: Not Provided

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
sponsored links
Old May 10th, 2010, 09:49 AM   #2 (permalink)
New Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 4
 
Device(s):
Carrier: Not Provided

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.
Carrier: Not Provided

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
Tags
user-agent, webkit, websettings, webview


Go Back   Android Forums > Android Development > Application Development
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



All times are GMT -5. The time now is 04:11 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.