顯示具有 Android 標籤的文章。 顯示所有文章
顯示具有 Android 標籤的文章。 顯示所有文章

2013年3月25日 星期一

Android LayoutInflater

LayoutInflater
簡單來說-->將Layout文件轉換為View

2013年3月24日 星期日

Android SQLiteOpenHelper, Cursor

Android 資訊系統訓練班
        -->內容函SharedPreference, SQLiteOpenHelper,
                         Cursor, FileInputStream與FileOutputStream的範例

Android下SQLite3数据库操作笔记(二)之-SQLiteOpenHelper


Android Cursor:

This interface provides random read-write access to the result set returned by a database query. Cursor implementations are not required to be synchronized so code using a Cursor from multiple threads should perform its own synchronization when using the Cursor.

簡單來說 就是data reader

Android學習_對SQLite查詢(query方法)取得Cursor

Android開發筆記-使用Cursor讀取SQLite回傳值

Android 【Cursor】 的介绍

Android開發筆記-建立SQLite實作類別

2013年3月21日 星期四

Google Map Location

Android Location API - Tutorial

Android - 定位資訊(GPS)相關類別使用說明

Android 開發筆記 - 透過 Google Maps API 畫出 GPS 路徑

[Android] Google地圖標誌


Android - 定位資訊(GPS)相關類別使用說明

Stop Location Listener in Android


看了那麼多
我們來練習一下
GoogleMapTrackTest.class

package com.example.googlemaptracktest;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MapActivity;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.ZoomControls;

public class GoogleMapTrackTest extends MapActivity {
    private MapController mapController = null;
    private MapView mMapview = null;
    private ZoomControls myZoom = null;
    private Drawable startdrawable = null;
    private Drawable enddrawable = null;
    private MapItemizedOverlay mymapoverlay = null;
    private boolean firstLocation = true;
    GeoPoint startPoint = null;

    private LocationManager mLocationManager = null;
    private String strLocationPrivider = "";
    private Location mLocation = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        MapView mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);

        LinearLayout maplinearlayout;

        maplinearlayout = (LinearLayout) findViewById(R.id.zoomview);
        mMapview = (MapView) findViewById(R.id.mapview);
        myZoom = (ZoomControls) (mMapview).getZoomControls();
        mapController = mMapview.getController();
        maplinearlayout.addView(myZoom);

        startdrawable = this.getResources().getDrawable(R.drawable.b1);// 指定標誌圖示
        enddrawable = this.getResources().getDrawable(R.drawable.ic_launcher);
        mymapoverlay = new MapItemizedOverlay(startdrawable, mMapview);

        // Location
        mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
                || mLocationManager
                        .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            Criteria mCriteria01 = new Criteria();
            mCriteria01.setAccuracy(Criteria.ACCURACY_FINE);
            mCriteria01.setAltitudeRequired(false);
            mCriteria01.setBearingRequired(false);
            mCriteria01.setCostAllowed(true);
            mCriteria01.setPowerRequirement(Criteria.POWER_LOW);
            strLocationPrivider = mLocationManager.getBestProvider(mCriteria01, true);
            mLocation = mLocationManager
                    .getLastKnownLocation(strLocationPrivider);

            // Initialize the location fields
            if (mLocation != null) {
                int lat = (int) (mLocation.getLatitude());
                int lng = (int) (mLocation.getLongitude());
                Toast.makeText(GoogleMapTrackTest.this,
                        String.valueOf(lat) + "," + String.valueOf(lng),
                        Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(GoogleMapTrackTest.this,
                        "Location not available", Toast.LENGTH_SHORT).show();
                mMapview.getController().setCenter(new GeoPoint(24778289, 120988108));
                mapController.setZoom(14);
            }
        }

        // Define a listener that responds to location updates
        LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                // Called when a new location is found by the network location
                // provider.
                int lat = (int) (location.getLatitude() * 1e6);
                int lng = (int) (location.getLongitude() * 1e6);
                GeoPoint addPoint = new GeoPoint(lat, lng); // 指定位置

                if (firstLocation == true) {
                    Toast.makeText(GoogleMapTrackTest.this,
                            String.valueOf(lat) + "," + String.valueOf(lng),
                            Toast.LENGTH_SHORT).show();
                    firstLocation = false;
                    startPoint = addPoint;
                    // 加入經緯度
                    OverlayItem myoverlayitem = new OverlayItem(addPoint, null,    null);
                    mymapoverlay.addOverlayItem(myoverlayitem);
                    mMapview.getOverlays().add(mymapoverlay);
                    // 依照mypoint設定之經緯度為中心點

                    mymapoverlay = new MapItemizedOverlay(enddrawable, mMapview);
                    // 換圖示
                } else {
                    Toast.makeText(GoogleMapTrackTest.this,
                            String.valueOf(lat) + "," + String.valueOf(lng),
                            Toast.LENGTH_SHORT).show();
                    OverlayItem myoverlayitem = new OverlayItem(addPoint, null,    null);
                    mymapoverlay.addOverlayItem(myoverlayitem, startPoint);
                    mMapview.getOverlays().add(mymapoverlay);
                }
                mMapview.getController().setCenter(addPoint);
                mapController.setZoom(14);
            }

            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
                
            }

            public void onProviderEnabled(String provider) {
                Toast.makeText(GoogleMapTrackTest.this, " onProviderEnabled ",
                        Toast.LENGTH_SHORT).show();
            }

            public void onProviderDisabled(String provider) {
                Toast.makeText(GoogleMapTrackTest.this, " onProviderDisabled ",
                        Toast.LENGTH_SHORT).show();
            }

        };

        // Register the listener with the Location Manager to receive location
        // updates
        mLocationManager.requestLocationUpdates(strLocationPrivider, 0, 0,
                locationListener);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}



MapItemizedOverlay.class

package com.example.googlemaptracktest;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> gList = new ArrayList<OverlayItem>();
    private ArrayList<GeoPoint> gListGeoPoint = new ArrayList<GeoPoint>();
    private Drawable marker = null;
    private Context context = null;
    private boolean firstmove = true;    
    private MapView myMapView = null;

    // Projection myProjection = null;
    // Point mapViewOut = null;

    public MapItemizedOverlay(Drawable arg0, MapView mMapview) {
        super(arg0);
        // TODO Auto-generated constructor stub
        marker = arg0;
        context = mMapview.getContext();
        myMapView = mMapview;
    }

    public void addOverlayItem(OverlayItem oItem) {
        gList.clear();
        gList.add(oItem);
        populate();
    }

    public void addOverlayItem(OverlayItem oItem, GeoPoint startPoint) {
        if (firstmove == true) {
            gListGeoPoint.add(startPoint);
            firstmove = false;
        }
        gListGeoPoint.add(oItem.getPoint());
        gList.clear();
        gList.add(oItem);
        populate();
    }

    @Override
    protected OverlayItem createItem(int arg0) {
        // TODO Auto-generated method stub
        return gList.get(arg0);
    }

    public void draw(Canvas canvas, com.google.android.maps.MapView mapview,
            boolean shadow) {
        super.draw(canvas, mapview, shadow);
        boundCenterBottom(marker);
        
         Projection myProjection = myMapView.getProjection();
         Point out;
         Path myPath = new Path(); 
         
        for (int i = 0; i < gListGeoPoint.size(); i++) {
            GeoPoint in = new GeoPoint(gListGeoPoint.get(i).getLatitudeE6(),
                    gListGeoPoint.get(i).getLongitudeE6());
            out = new Point();
            myProjection.toPixels(in, out);
            if (i == 0) {
                myPath.moveTo(out.x, out.y);
            } else {
                myPath.lineTo(out.x, out.y);
                myPath.setLastPoint(out.x, out.y);
            }
        }
         
         Paint myPaint = new Paint();
         myPaint.setColor(Color.RED);
         myPaint.setStyle(Paint.Style.STROKE);
         myPaint.setStrokeWidth(2);
         myPaint.setAlpha(70);
        
         canvas.drawPath(myPath, myPaint);
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return gList.size();
    }

}



AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemaptracktest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <permission
        android:name="com.example.googlemaptracktest.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <!--
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name="com.example.googlemaptracktest.GoogleMapTrackTest"
            android:label="@string/app_name"  android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/zoomview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <com.google.android.maps.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="04PWltFqrvM9KGKh8Dvlh3hN73M_xFBck0zmI5w"
        android:clickable="true"
        android:enabled="true" 
        />

</LinearLayout>


Result:

























我拿了我的實機測試
GPS抓得很慢!!!!!!
所以要等一下
僅供參考喽!









Android SharedPreferences


SharedPreferences
        提供一個簡易的方式來儲存應用程式的設定值,方便下次應用程式被啟動時,載入偏好設定,讓應用程式自動回復到前一次設定值。此外,也可與同一套件之應用程式共享。


2013年3月20日 星期三

Google MapView Zoom in&out

[Android] Zoom In & Out

Android SMS

SMS Messaging in Android

[Android] 接收SMS(簡訊)

SMS manager in Android

取得Google Map Key v2 MD5&SHA1 Problem

Google Maps Android v1 API Key Signup

MD5還是有辦法取得的!

只要在指令後方加入-v 便大功告成


$ keytool -list -alias androiddebugkey 
-keystore .keystore 
-storepass android -keypass android -v

Android User Interface

1.Layout

  • Linear Layout

  • 指定一個方向,垂直或水平,不管控制項有多大,向下向右排排站

  • Relative Layout

  • 使用相對位置去排版

  • List View

  • Grid View

        這就不用多說了

        Android學習_GridView的使用

Adapter



2.Input Controls



3.Input Events











2013年3月19日 星期二

Google Map API Key



Android筆記_如何申請Google Map API Key(模擬器用)

Android學習_如何申請Google Map API Key(實機用)

Android學習_如何開始使用Google Maps Android API v2

Android Intent



An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.

An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.

基本上 你知道Intent是什麼拉!

2011年4月28日 星期四

Android應用程式權限問題

一切的起因都是因為android:sharedUserId="android.uid.system"這句指令
使用NDK編譯了一個執行檔D2MCEDaemon
想要直接使用Android應用程式開啟他,但是一直開不起來
後來找到了可以輸出system.out的程式所以才發現原來是權限不足

程式碼是從哪裡找到的已經忘記了
首先在註冊檔上加入android:sharedUserId="android.uid.system"




然後勒
寫一個可以執行底層命令的程式

public class TESTTPERMISSION extends Activity {
 private static final String TAG = "execCommand";
 
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  setTitle("This is Matrix.");
  
  runRootCommand("/data/local/bin/D2MCEDaemon");
 }
 
 public static boolean runRootCommand(String command) {
        Process process = null;
        DataOutputStream os = null;
            try {
            process = Runtime.getRuntime().exec(command);
           // Log.e("runRootCommand", "su");
            os = new DataOutputStream(process.getOutputStream());
           // os.writeBytes(command+"\n");
            Log.e("runRootCommand", command);
            //os.writeBytes("exit\n");
            os.flush();
            process.waitFor();
            
            String line = null;
            
   InputStream stderr = process.getErrorStream();
   InputStreamReader esr = new InputStreamReader(stderr);
   BufferedReader ebr = new BufferedReader(esr);
   System.out.println("");
   while ((line = ebr.readLine()) != null) {
    System.out.println(line);
    Log.e("runRootCommand", line);
   }
   System.out.println("");

   InputStream stdout = process.getInputStream();
   InputStreamReader osr = new InputStreamReader(stdout);
   BufferedReader obr = new BufferedReader(osr);
   System.out.println("");
   while ((line = obr.readLine()) != null) {
    System.out.println(line);
    Log.e("runRootCommand", line);
   }
   System.out.println("");

            int exitVal = process.waitFor ();
            System.out.println ("Process exitValue: " + exitVal);
            Log.e("runRootCommand", String.valueOf(exitVal));
                                          
            } catch (Exception e) {
                    Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+e.getMessage());
                    return false;
            }
            finally {
                    try {
                            if (os != null) {
                                    os.close();
                            }
                            process.destroy();
                    } catch (Exception e) {
                            // nothing
                    }
            }
            return true;
    }

}



明顯的看見我們是想要執行runRootCommand("/data/local/bin/D2MCEDaemon");
這個Command
但是呢
第一個問題
如果沒加上這一行android:sharedUserId="android.uid.system"
他會說permission denied
這讓我頭痛了許多天
第二
加上了android:sharedUserId="android.uid.system"
卻出現
[2011...] Installation error: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
[2011...] Please check logcat output for more details.
[2011...] Launch canceled!
真的是氣死我了

麻煩的來了
網路上找了一些文章
像是
http://www.wretch.cc/blog/michaeloil/23398272
http://owen-hsu.blogspot.com/2010/09/android-apkuid.html
http://joshzhchen.blogspot.com/2010/09/androidshareduserid.html
http://blog.csdn.net/liujian885/archive/2010/03/22/5404834.aspx
完全看不懂
乖乖的自己去download Android source code之後卻一點頭緒也沒有
至於怎麼download source code
自己去android官網就有教學了
然後自己找了一些有關於signapk的文章
因為上面那些連結根本沒解釋什麼是signapk
好吧
找了一些
http://www.techwen.com/mobile/android/20101215/1422.html
http://www.bangchui.org/read.php?tid=11094
http://hi.baidu.com/langhongjian/blog/item/645a7d2427ecd1144c088d92.html

後來發現是sign的問題

先下載android source code
然後到 cd ~/AndroidSourceCode/build/tools/signapk
再來會看到SignApk.java
執行這一行javac SignApk.java
會出現SignApk$SignatureOutputStream.class和SignApk.class
建立目录s\com\android\signapk在signapk目錄底下
自己慢慢的mkdir
反正要建立完整
再來執行
jar cvfm signapk.jar SignApk.mf -C ./s .

然後會出現signapk.jar
這樣就OK拉~
然後利用Eclipse編譯APK
再專案上右鍵選擇Android tools->Export Unsigned Application Package
這樣就有APK拉~
然後回到linux的signapk目錄底下
執行java -jar signapk.jar platform.x509.pem platform.pk8 input.apk output.apk
大功告成
至於platform.x509.pem platform.pk8在AndroidSourceCode\build\target\product\security目錄底下

然後使用adb install output.apk
終於完成摟

2010年2月9日 星期二

Android Activity Life Cycle Demo



public class LifeCycleTest extends Activity {
    private static final String TAG = "ActivityLifeTest";

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.v(TAG, "onCreate");
        
        Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");  
        Intent it = new Intent(Intent.ACTION_VIEW, uri);  
        startActivity(it);  
    }

    public void onStart() {
        super.onStart();
        Log.v(TAG, "onStart");
    }

    public void onResume() {
        super.onResume();
        Log.v(TAG, "onResume");
    }

    public void onPause() {
        super.onPause();
        Log.v(TAG, "onPause");
    }

    public void onStop() {
        super.onStop();
        Log.v(TAG, "onStop");
    }

    public void onRestart() {
        super.onRestart();
        Log.v(TAG, "onReStart");
    }

    public void onDestroy() {
        super.onDestroy();
        Log.v(TAG, "onDestroy");
    }
}








First, new a project with Google APIs.
Then, Run it.



We can see that Log:ActivityLifeTest is onPause now. It means the Intent start another Activity.
If we press “BACK”, Activity:LifeCycleTest will resume again.


Now, restart the Activity, and press “Maps”.



We can find out that Activity:LifeCycleTest  is stopped. It means Activity:LifeCycleTest  is no longer visible.

Finally, press “BACK” to the Activity:LifeCycleTest, and Activity:LifeCycleTest will restart.





If we leave the Activity:LifeCycleTest, Activity:LifeCycleTest will be destroyed.





Reference:
http://stenlyho.blogspot.com/search/label/Android
http://code.google.com/p/androidbmi/wiki/LifeCycle
http://developer.android.com/intl/zh-TW/guide/topics/fundamentals.html
üW





üWe

2010年1月31日 星期日

Mp3Player With Service

Activity:

public class Mp3PlayerWithService extends Activity implements OnClickListener {
private static final String TAG = "Mp3Interface";
private static Mp3PlayerWithService appRef = null;

private ImageButton btn, btn2, btn3;
public TextView tv;
private IBinder ib;

public static Mp3PlayerWithService getApp() {
return appRef;
}

public void btEvent(String data) {
setTitle(data);
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
appRef = this;

btn = (ImageButton) findViewById(R.id.PlayMP3);
btn2 = (ImageButton) findViewById(R.id.Stop);
btn3 = (ImageButton) findViewById(R.id.exit);
btn.setId(101);
btn2.setId(102);
btn3.setId(103);

btn.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);

tv = (TextView) findViewById(R.id.TextView01);
tv.setText("Ready");

bindService(new Intent(Mp3PlayerWithService.this, mp3Service.class),
mContection, Context.BIND_AUTO_CREATE);
}

private ServiceConnection mContection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder ibinder) {
ib = ibinder;
tv.setText(className.toString());
}

@Override
public void onServiceDisconnected(ComponentName className) {
}
};

public void onClick(View v) {
switch (v.getId()) {
case 101:
try {
ib.transact(1, null, null, 0);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case 102:
try {
ib.transact(2, null, null, 0);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case 103:
finish();
break;
}
}
}

Binder:


public class mp3PlayerBinder extends Binder{
private MediaPlayer mPlayer = null;
private Context ctx;

public mp3PlayerBinder(Context cx){
ctx = cx; }
@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags){
if(code == 1)
this.play();
else if(code == 2)
this.stop();
return true;
}
public void play(){
if(mPlayer != null)
return;
mPlayer = MediaPlayer.create(ctx, R.raw.test);
mPlayer.start();
}
public void stop(){
if(mPlayer != null){
mPlayer.stop();
mPlayer.release();
mPlayer = null;
}
}
}

Service:


public class mp3Service extends Service{
private IBinder mBinder = null;
@Override
public void onCreate(){
mBinder = new mp3PlayerBinder(getApplicationContext());
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return mBinder;
}
}

layout:



?xml version="1.0" encoding="utf-8"?>
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
LinearLayout android:orientation="horizontal"
android:layout_height="wrap_content" android:layout_width="fill_parent">
ImageButton android:id="@+id/PlayMP3"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:src="@drawable/play" />
ImageButton android:id="@+id/Stop" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:src="@drawable/stop" />
ImageButton android:id="@+id/exit" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:src="@drawable/exit" />
      /LinearLayout>
/LinearLayout>

2010年1月27日 星期三

Install JDK






JDK:Java Development Kit
We can download at the following URL.


Select the appropriate JDK software and click Download JDK.

And choose a Platform whilch we are used. Then press download.



After download finish, double click the exe file and install.

....



Now, The JDK software is installed on your computer.
Next, 我的電腦->內容




進階->環境變數->path->加上安裝路徑\bin





DONE!
Open cmd to check.
Type command "java -version".




Google Map View


MapViewGoogleAPI.java:

public class MapViewGoogleAPI extends MapActivity {
List mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedOverlay;
MapController Mcontrol;
LinearLayout linearLayout;
MapView mapView;
ZoomControls mZoom;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
linearLayout = (LinearLayout) findViewById(R.id.zoomview);
mapView = (MapView) findViewById(R.id.mapview);
mZoom = (ZoomControls) mapView.getZoomControls();
GeoPoint point = new GeoPoint(25043943,121533841);
Mcontrol = mapView.getController();
Mcontrol.animateTo(point);
Mcontrol.setZoom(15);
processThread();
linearLayout.addView(mZoom);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.androidmarker);
HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);
OverlayItem overlayitem = new OverlayItem(point, "", "");
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
private void processThread() {
new Thread() {
public void run() {
longTimeMethod();
for(int i = 0 ; i < i =" i+10">
Mcontrol.scrollBy(i, 0);
longTimeMethod();
}
GeoPoint newcenter = mapView.getMapCenter();
Mcontrol.animateTo(newcenter);
for(int k = 0 ; k <> Log.e("forloop", "do i in the forloop?");
Mcontrol.scrollBy(0, k);
}
newcenter = mapView.getMapCenter();
Mcontrol.animateTo(newcenter);
HelloItemizedOverlay newitemizedoverlay = new HelloItemizedOverlay(drawable);
OverlayItem newitem = new OverlayItem(newcenter, "", "");
newitemizedoverlay.addOverlay(newit
em);
mapOverlays.add(newitemizedoverlay);
}
}.start();
}

private void longTimeMethod() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Log.e("mapview", e.getMessage());
}
}
}

HelloItemizedOverlay.java:

public class HelloItemizedOverlay extends ItemizedOverlay {
private ArrayList mOverlays = new ArrayList();
public HelloItemizedOverlay(Drawable defaultMarker) {
//super(defaultMarker);
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
}

@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}

@Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}

}

main.xml:


result:

2010年1月21日 星期四

Set up SD card for your Android Emulator with Window XP




First,
start cmd. 開始->執行->cmd
Second,
You can access mksdcard in the tools/ directory of the SDK which like "C:\android-sdk-windows-1.6_r1\tools",
cd C:\android-sdk-windows-1.6_r1\tools
and then create a disk image like this:
mksdcard <size> <file>
mksdcard 1024M C:\sdcardImg\sdcard.img
wait about 30 second.
Third,
create a Emulator with Eclipse
window->Android SDK and AVD Manager->New, then choice a target and SD Card->File with img

Fourth,
Run the Emulator, then you will see the view like next picture at setting->SD card& phone storage.

But, how do we put files into the sdcard?
There are some example which put the mp3 file into sdcard.
First, open the cmd and we can use command "adb push 'file path' /sdcard" in the tools/ directory of the SDK.

Then we type command "adb shell" and type "ls -l /sdcard".
you can see the following picture, and you will find out the file is put in the /sdcard successfully.











we can check the file with Emulator, too.
music->songs



Reference: