Idolonの回答のおかげで、私のアプリはこれをバックグラウンドで処理できました。
しかし、どういうわけか、2.3.3を実行するAT&TのHTC Inspire 4Gでは、catchステートメントに移動し、バックグラウンドスレッドで実行できなくなります。これに対する私の解決策は次のとおりです。
public static String getUserAgent(Context context) {
try {
Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class);
constructor.setAccessible(true);
try {
WebSettings settings = constructor.newInstance(context, null);
return settings.getUserAgentString();
} finally {
constructor.setAccessible(false);
}
} catch (Exception e) {
String ua;
if(Thread.currentThread().getName().equalsIgnoreCase("main")){
WebView m_webview = new WebView(context);
ua = m_webview.getSettings().getUserAgentString();
}else{
mContext = context;
((Activity) mContext).runOnUiThread(new Runnable() {
@Override
public void run() {
WebView webview = new WebView(mContext);
mUserAgent = webview.getSettings().getUserAgentString();
}
});
return mUserAgent;
}
return ua;
}
}
(フィールドにmContextとmUserAgentがあるとします)