Android logcatのログをSDカードなどに出力する

Android

Android logcatのログをSDカードなどに出力する

ANR解析のためや、いろんなことのためにlogcatのログを取り出したいことはあると思いますが、

 /data/anr/traces.txt

などに出力されたものを

 adb cat /data/anr/traces.txt

なんて面倒ですし、エンジニアではない人から渡してもらうのに不便ですよねっ。

というわけで、普通の人でもファイルマネージャーでアクセスできる場所にlogcatを出力しちゃいましょう。

Google Playで配布しないアプリにクラッシュログ機能を実装するで作りましたMyApplication.javaなどに次のように書きましょう。

 @Override
 public void onCreate() {
      super.onCreate();
      String LOGDIR = Environment.getExternalStorageDirectory().getPath() + "/smart.location.edison/";
      String[] cmd = new String[] { "logcat", "-f", LOGDIR+"logcat", "-v", "time", "ActivityManager:W", "myapp:D" };
      try {
          proc = Runtime.getRuntime().exec(cmd);
      } catch (IOException e1) {
          Log.e(TAG, "ログ出力時エラー"+e1);
      }
 }

Android error this package depends on Missing SDK Platform Android API 17

Android

Android error this package depends on Missing SDK Platform Android API 17

Android SDK Managerから、Android4.2 API17をダウンロードしようとしても、MIPSとかARMだけが表示されていて、SDK Platformが表示されません。
MIPSとかARMをダウンロードしようとしても、上記のようなそもそもSDKが入っていないので、MIPSとかARMはインストールできないよ、という警告が。

これ、次のように解決しました。

  1. Android SDK Managerの上部のメニュー Tools→Optionをクリック
  2. Force https://… とあるところにチェック
  3. Clear Cacheのボタンを押して、キャッシュをクリア
  4. すると、Android SDK Managerのリストに、Android4.2 API17が表示され、無事ダウンロードできました。

Android dipとdpの違い

Android

Android dipとdpの違い

Androidの画面を開発する時に利用するdipとdpという単位ですが、同じ意味です。

古い本だとdipってなってることが多いですよね。

Android This text field does not specify an inputType or a hint

Android

Android This text field does not specify an inputType or a hint

Androidのレイアウトファイルで、入力フォームを表示する部分で、黄色のエラーで上記のようなエラーが表示されることがあります。

 <EditText
   android:id="@+id/nick_name"
   android:layout_width="230dip"
   android:layout_height="wrap_content"
   android:layout_marginLeft="5dip"
   >

android:inputTypeという、パラメーターが足りないということのようです。

 <EditText
   android:id="@+id/nick_name"
   android:layout_width="230dip"
   android:layout_height="wrap_content"
   android:layout_marginLeft="5dip"
   android:inputType="text" >

一番最後にinputTypeを付与してなおりました!

ちなみに、

 <EditText
   android:id="@+id/email"
   android:layout_width="230dip"
   android:layout_height="wrap_content"
   android:layout_marginLeft="5dip"
   android:inputType="text" >

とか書くと、これも下記のエラーが表示されます。

The view name (@+id/email) suggests this is an e-mail address, but it does not include ‘textEmail’ in the inputType

どうやらこれはEmailを入力するフォームのようだけど、テキストタイプがEmailになっていないよ、ということのようです。

 <EditText
    android:id="@+id/email"
    android:layout_width="230dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:inputType="textEmailAddoress" >

ちなみに、上記はtextEmailだとエラーになります。textEmailAddoressが正解です。

他にも、下記で

 <EditText
    android:id="@+id/phone_number"
    android:layout_width="230dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:inputType="text" >

The view name (@+id/phone_number) suggests this is a phone number, but it does not include ‘phone’ in the inputType

と出ます。正しくは、下記ですね。

 <EditText
    android:id="@+id/phone_number"
    android:layout_width="230dip"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dip"
    android:inputType="phone" >

どうですか?
Androidの開発環境さん、優しくないですか?!
ぁたし なぃちゃったよ…w

idに適当な文字を割り振るのではなくて、ちゃんとテキストフォームの属性を指定する名前をつけるべし、です。

Android TextViewにリンクを張る

Android

Android TextViewにリンクを張る

ボタンとか作らずに、簡単にURLにリンクを張りたい時ありますよね。
レイアウトファイルのTextViewを利用するだけで、URLへのリンクが簡単に作れます。

 //例 main.xml内
 <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:autoLink="web"
       android:text="@string/register_url" 
       android:textSize="16dp">
 </TextView>
 //例 strings.xml内
 <string name="register_url">http://onlineconsultant.jp</string>

http://onlineconsultant.jpへのリンクが作られます。
HTMLのように、日本語などにリンクを張るのは、この方法ではできないのが残念です。