Mozilla/5.0 (Linux; U; Android 2.1-update1; ja-jp; SO-01B Build/2.0.2.B.0.29) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17HTC Ariaのユーザーエージェントはこう。
Mozilla/5.0 (Linux; U; Android 2.2.1; ja-jp; HTC Liberty Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1Androidなのに『Mobile Safari』なのが面白いところですね。 これはAndroidの標準ブラウザやWebViewが WebKitを元に開発されているからです。 ]]> String userAgentString = webView.getSettings().getUserAgentString(); Log.v("CHECK", userAgentString); webView.getSettings().setUserAgentString(userAgentString+" AppName"); userAgentString = webView.getSettings().getUserAgentString(); Log.v("CHECK", userAgentString); とすればOKです。 (参考)ユーザーエージェントに関する非推奨APIが面白い件 - adakoda 上記はアプリ開発時にユーザーエージェントをいじる方法ですが ユーザーとして標準ブラウザのユーザーエージェントを変更する方法も見つけました。 ・標準ブラウザのUAを変更する方法 参考までにどーぞ。 ]]>
08-21 20:59:11.663: DEBUG/skia(2053): --- decoder->decode returned falseしかも不可解なことに、 Xperia では発生しないのに IS05 と HTC Aria では発生してました。 ]]> // URLからBitmapへの変換 public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } } 修正後のOKメソッド↓
// URLからBitmapへの変換 public static Bitmap getBitmapFromURL(String src) { HttpGet httpRequest = new HttpGet(src); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; try { response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); Bitmap bm = BitmapFactory.decodeStream(instream); return bm; } catch (ClientProtocolException e) { e.printStackTrace(); Log.v("CHECK", "failed! "+src); return null; } catch (IOException e) { e.printStackTrace(); Log.v("CHECK", "failed! "+src); return null; }Xperia だけで開発していたら気づけなかったな・・・。 ]]>
Uri uri = Uri.parse ("mailto:info@hogehoge.com"); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.putExtra(Intent.EXTRA_SUBJECT, "メールの件名"); intent.putExtra(Intent.EXTRA_TEXT, "メールの本文"); activity.startActivity(intent);インテントが発行されると、 端末で使用可能なメーラーの選択ダイアログが立ちあがります。 ]]> //メールで問い合わせ public static void contactByMail(final Activity activity) { AlertDialog.Builder ad=new AlertDialog.Builder(activity); ad.setMessage("メールで問い合わせますか?"); ad.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { //メールの起動 Uri uri = Uri.parse ("mailto:"+activity.getString(R.string.mail)); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.putExtra(Intent.EXTRA_SUBJECT, "メールの件名"); intent.putExtra(Intent.EXTRA_TEXT, "メールの本文"); activity.startActivity(intent); } }); ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { } }); ad.create(); ad.show(); } 引数は Activity のみ取るようになってますが メール件名や本文を引数にとってもいいかもしれません。 ]]>
Uri uri = Uri.parse("tel:0123456789"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent);tel: のあとに電話番号を入れるだけでOKです。 あとはインテントを発行するだけ。 ]]> public static void contactByTel(final Activity activity) { AlertDialog.Builder ad=new AlertDialog.Builder(activity); ad.setMessage("電話で問い合わせますか?"); ad.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //電話の起動 Uri uri = Uri.parse("tel:0123456789"); Intent intent = new Intent(Intent.ACTION_DIAL, uri); activity.startActivity(intent); } }); ad.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int whichButton) { } }); ad.create(); ad.show(); } (複数Activityで共有できるように、Activityを引数に取るメソッド化しています。) ちなみに、2の直接発信する方法は
Uri uri = Uri.parse("tel:0123456789"); Intent intent = new Intent(Intent.ACTION_CALL, uri); startActivity(intent);とします。 Intent に設定するのが Intent.ACTION_CALL になります。 こちらの方法の場合は、 android.permission.CALL_PHONE を設定するのを忘れずに。 ]]>