Tips

「Tips」の編集履歴(バックアップ)一覧に戻る

Tips - (2008/09/06 (土) 18:03:16) のソース

*sdk m5 → β で修正が必要な部分
・MapActivity
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-library android:name="com.google.android.maps"/>          ←applicationタグの中に入れる
|com.google.android.maps.Point	|→ com.google.android.maps.GeoPoint|
|Point|→ GeoPoint|
|zoomTo|→ setZoom|
|isRouteDisplayed()をOverrideする|>|

・GPS
AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_LOCATION"/> 
↓
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

・Menu
|menu.add(0, 1, "表示する内容")|→ menu.add(0, 1, Menu.NONE, "表示する内容");|
|onMenuItemSelected(int featureId, Item item)|→ onMenuItemSelected(int featureId, MenuItem item)|
|getId|→ getItemId|

・AlertDialog
AlertDialog.show(this, タイトル, 任意の整数, 本文, ボタン1の表示, false);
↓
ab = new AlertDialog.Builder(this);
ad = ab.create();
ad.setButton("ボタン1の表示", this);
ad.setButton2("ボタン2の表示", this); ←表示しない場合は不要
ad.setTitle("タイトル");
ad.setMessage("メッセージ");
ad.show();

・データベース
import android.database.sqlite.SQLiteOpenHelper|>|
|first|→ moveToFirst|
|count|→ getCount|
以下openまでの例
-----------------------------------------------------------------------
private SQLiteDatabase db;
private static final int DATABASE_VERSION = 2;
private static final String  DATABASE_NAME = "データベースのファイル名";
private DatabaseHelper mDbHelper;

mDbHelper = new DatabaseHelper(this);
db = mDbHelper.getWritableDatabase();

private static class DatabaseHelper extends SQLiteOpenHelper {
    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("テーブル作成のSQL文");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS notes");
        onCreate(db);
    }
}
-----------------------------------------------------------------------


*Proxy(プロキシ)の設定方法
プロキシ経由でしかインターネットに接続できない環境では、Android上の通信機能が使えません。
ブラウザを開いて検索しても"Network Error 32"とエラーが出てしまいます。
プロキシ経由で通信するためには以下のように設定します。
+emulator.exeを起動し、待ち受け画面が出るまで待つ
+emulator.exeがある場所でプロンプトを開く
+"adb shell"と打ってEnter
+"#"が表示されたら、"setprop net.gprs.http-proxy http://hoge:8080"と打つ。&br()※「hoge」はプロキシーのアドレス、8080はプロキシのポート番号に置き換えてください。
プロキシ認証にも対応しているようです。
しかし、GoogleMapsアプリはプロキシ経由では使用できないようです。
(プロキシ設定しても、DNSサーバーを見に行ってしまう。)

こんな情報もあります。こっちはGoogleMapsもいけるのかな??
-[[Android エミュレータのプロキシ設定>http://homepage.dynalias.net/moblog/archives/003826.html]]

*エミュレータのスキンを変える方法
emulator -skin HVGA-L
emulator -skin HVGA-P
emulator -skin QVGA-L
emulator -skin QVGA-P

*ユーザーデータの場所
デフォルトでは、
|Linux or Mac OSX| ~/.android/userdata.img|
|Windows|C:\Documents and Settings\ユーザー名\Local Settings\Application Data\Android\userdata.img|
にあります。
自作[[アプリケーションのアンインストール方法が見当たらない>http://www.atmarkit.co.jp/fjava/column/koyama/koyama09_2.html]]ようなのでこのイメージファイルを消したり、リネームすることで初期状態に戻すことが出来ます。あるいはwipe-dataオプションを付けてエミュレータを起動すると、エミュレータを初期化できます。
|$ emulator -wipe-data|

*localhostに接続する
エミュレータ上のアプリからエミュレータと同じPC上のサーバーと通信する場合、127.0.0.1やlocalhostでは接続できないので、PCのIPアドレスを調べて、それを使うことで接続できます。
[[ネタ元:Androidでlocalhostに接続>http://chephes.cocolog-nifty.com/blog/2007/12/androidlocalhos_3bec.html]]

*WebカメラをAndroid上で使う方法
-[[Live Camera Previews in Android>http://www.tomgibara.com/android/camera-source]]

*sdk m3-rc37a → m5-rc14 で修正が必要な部分
・AndroidManifest.xml
|activity class		|→ activity android:name|
|action android:value	|→ action android:name|
|category android:value	|→ category android:name|

GPSを使用している場合は以下を追加([[ネタ元:りょうさん>http://homepage3.nifty.com/rio_i/lab/android/013gps.html]])
|<uses-permission android:name="android.permission.ACCESS_LOCATION"/>|
|<uses-permission android:name="android.permission.ACCESS_GPS"/>|

・xmlファイル(画面のレイアウトを設定している場合)
|id	 		|→ android:id|

・ソース
ダイアログ表示
AlertDialog.show(this, タイトル, 本文, ボタン1の表示, this, false, null);
↓
AlertDialog.show(this, タイトル, 任意の整数, 本文, ボタン1の表示, false);

データベース
|query(sql, null)	|→ rawQuery(sql, null)|

各UI
デカイ!
面積で4倍になった感じ。
レイアウトの基本設計から修正が必要になるかも。

ContentUri
↓
Uri

|m3-rc37aまで|m5-rc14|
|new ContentURI(String)|Uri.parse(String)|
|ContentURI.create(String)|Uri.parse(String)|
|ContentUri.countPathSegments()|Uri.getPathSegments().size()|
|ContentUri.getPathSegment()|Uri.getPathSegments().get()&br()or&br()Uri.getLastPathSegment()|
|ContentURI.addPath()|Uri.Builder.appendPath()|
|ContentURI.addId(id)|uri = Uri.withAppendedPath(SOME_URI, id);&br()or&br()uri = ContentUris.appendId(uri.buildUpon(), id).build();|

本家:http://code.google.com/android/migrating/m3-to-m5/m5-api-changes.html

他にあれば、追記をお願いします。
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。