Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab4.BMI計算.

Similar presentations


Presentation on theme: "Lab4.BMI計算."— Presentation transcript:

1 Lab4.BMI計算

2 Outline 題目說明 建立一個新專案 UI設置 程式撰寫

3 題目說明 使用身高及體重來計算自己的BMI,新增RadioButton選擇性別,輸入身高及體重後,按下Button顯示BMI值。

4 匯入已有的專案 開啟Eclipse選擇File ->Import ->Existing Code Into Workspace

5 匯入已有的專案

6 選擇專案

7 選擇專案

8 選定要匯入的專案

9 匯入後開啟/layout/activity_Main
此次使用AbsoluteLayout佈局

10 改變物件排列方式-絕對排序

11 UI使用元件 TextView Button EditText RadioGroup

12 新增TextView 元件

13 新增RadioGroup元件

14 新增Button元件

15 新增EditText元件

16 設定元件顯示文字

17 新增字串資料

18 填入字串資料

19 設定元件寬度

20 設定元件長度

21 設定元件文字大小

22 設定元件位置( X , Y )

23 輸入元件X軸座標

24 輸入元件Y軸座標

25 設定元件ID

26 設定EditText的Input Type

27 設定RadioButton在RadioGroup的排列方式(由左向右橫式排列)

28 ID title R.String 顯示文字 計算你/妳的BMI值 width 243dp height 29dp layout_x 36dp layout_y 32dp text size 24sp

29 ID text1 R.String 顯示文字 男性/女性 width wrap_content height 37dp layout_x 10dp layout_y 108dp text size 18sp

30 ID text2 R.String 顯示文字 身高(m) width wrap_content height 42dp layout_x 10dp layout_y 142dp text size 18sp

31 ID text3 R.String 顯示文字 體重(kg) width wrap_content height 42dp layout_x 10dp layout_y 200dp text size 18sp

32 ID height input type NumberDecimal width 130dp wrap_content layout_x 96dp layout_y 142dp text size 18sp

33 ID weight Input Type NumberDecimal width 130dp height wrap_content layout_x 96dp layout_y 200dp text size 18sp

34 ID button1 R.String text_button 顯示文字 計算 width 70dp height 48dp layout_x 125dp layout_y 252dp text size

35 ID sex R.String 顯示文字 width 300dp height wrap_content layout_x 110dp layout_y 98dp text size

36 ID male R.String text4 顯示文字 男性 width wrap_content height layout_x layout_y text size

37 ID female R.String text5 顯示文字 女性 width wrap_content height layout_x layout_y text size

38 程式撰寫(MainActivity)

39 UI介面(Main_child) ID tvBMI R.String 顯示文字 textview width wrap_content
height layout_x 50px layout_y 72px text size 20sp ID tvAdvice R.String 顯示文字 textview width wrap_content height layout_x 50px layout_y 172px text size 20sp ID button1 R.String 顯示文字 回上一頁 width wrap_content height 48px layout_x 110px layout_y 280px

40 程式撰寫(Main_child)

41 程式撰寫(Main_child)

42 程式撰寫(Main_child)

43 執行結果

44 執行結果

45 Lab5.公尺與英呎轉換

46 取得字串值 - values\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">公尺與英呎轉換</string> <string name="title"> 請輸入要轉換的值:</string> <string name="btn1">公尺轉換成英呎</string> <string name="btn2">英呎轉換成公尺</string> </resources> 手機畫面的內容顯示 <String-array> 下拉式選單

47 字串值 – menu/menu.xml <menu xmlns:android=" <item android:alphabeticShortcut="r" android:title="重設" /> </menu> Item:menu的選項 android:icon:menu顯示的圖示。 android:title:menu標題,顯示在icon下。 android:alphabeticShortcut:menu的快捷鍵。

48 手機畫面配置 - main.xml

49 主程式 - GDA02.java public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main); /* 建立元件與物件的連結關係(findViewByld) */ Button button01 = (Button)findViewById(R.id.submit01); button01.setOnClickListener(MtoFT); Button button02 = (Button)findViewById(R.id.submit02); button02.setOnClickListener(FTtoM); } /* 點選手機menu後,執行以下的指令 */ public boolean onCreateOptionsMenu(Menu menu) { /* 獲取目前的menu,透過MenuInflater類別將Menu下的xml檔 ,實體化成Menu類別的物件,再用inflate()方法將xml檔的內容 顯示出來 */ MenuInflater inflater = getMenuInflater();   inflater.inflate(R.menu.menu, menu); return true;

50 主程式 - GDA02.java /* 點擊menu後的命令*/
public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()){ case R.id.menue_rset: ResetValue(); break; } return true; /* 點擊menu後,將EditText、TextView清空 */ private void ResetValue() EditText ed = (EditText)findViewById(R.id.input_value); ed.setText(""); TextView tv = (TextView)findViewById(R.id.result); tv.setText("");

51 主程式 - GDA02.java /* 點選公尺轉換成英呎 */
private OnClickListener MtoFT = new OnClickListener() { public void onClick(View v) /* 將值格式化 */ DecimalFormat nf = new DecimalFormat("0.00"); EditText fieldinput = (EditText)findViewById(R.id.input_value); /* 使用parseDouble()方法,將指定的String轉型為double */ double input = Double.parseDouble(fieldinput.getText().toString()); double MFT = input * 3.28; TextView result = (TextView)findViewById(R.id.result); result.setText(input+"公尺 = "+nf.format(MFT)+"英呎"); } }; 英呎=公尺*3.28

52 主程式 - GDA02.java /* 點選英呎轉換成公尺 */
private OnClickListener FTtoM = new OnClickListener() { public void onClick(View v) /* 將值格式化 */ DecimalFormat nf = new DecimalFormat("0.00"); EditText fieldinput = (EditText)findViewById(R.id.input_value); /* 使用parseDouble()方法,將指定的String轉型為double */ double input = Double.parseDouble(fieldinput.getText().toString()); double FTM = input * ; TextView result = (TextView)findViewById(R.id.result); result.setText(input+"英呎 = "+nf.format(FTM)+"公尺"); } }; 公尺=英呎*0.3048

53 Lab6.簡單記事

54 取得字串值 - values\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">簡單記事</string> </resources> 手機畫面的內容顯示 <String-array> 下拉式選單

55 手機畫面配置 - main.xml LinearLayout線性布局 保持子元素之間的間隔互相對齊

56 手機畫面配置 - list.xml

57 主程式 - GDA02.java /* 設定Button是否被啟用 */ Button02.setEnabled(false);
/* 宣告CREATE_SQL 字串內容*/ String CREATE_SQL = "create table if not exists "+TABLENAME+" ("+FIELD01_NAME+" integer primary key autoincrement, "+FIELD02_NAME+" varchar not null);"; /* 宣告資料庫內容*/ dataBase = openOrCreateDatabase(DBNAME, MODE_WORLD_WRITEABLE, null); /* 資料庫呼叫execSQL()方法*/ dataBase.execSQL(CREATE_SQL); /* 查詢資料表名稱*/ cursor = dataBase.query(TABLENAME , null, null, null, null, null, null);

58 主程式 - GDA02.java /* 宣告連接至新的字串陣列與新的整數陣列 */
android.widget.SimpleCursorAdapter adapter = new android.widget.SimpleCursorAdapter(this, R.layout.list, cursor, new String[] { FIELD02_NAME }, new int[] { R.id.CheckedTextView01 }); /* 將adapter設定給ListView01使用,adapter功能為資料轉換 */ ListView01.setAdapter(adapter); /* 設定監聽Button01的程式,並設定內容(新增)*/ Button01.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(!EditText01.getText().toString().equals("")){ insert(""+EditText01.getText()); } }});

59 主程式 - GDA02.java /* 設定監聽Button02的程式,並設定內容(更新修改)*/
Button02.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(_id!=-1 && !EditText01.getText().toString().equals("")){ update(_id,""+EditText01.getText()); Button02.setEnabled(false); Button03.setEnabled(false); } }});

60 主程式 - GDA02.java /* 設定監聽Button02的程式,並設定內容(刪除)*/
Button03.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(_id!=-1){ delete(_id); Button02.setEnabled(false); Button03.setEnabled(false); } }});

61 主程式 - GDA02.java /* 設定監聽ListView01的程式,並設定內容*/
ListView01.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener(){ @Override public void onItemClick(android.widget.AdapterView<?> arg0, View arg1, int arg2, long arg3) { /* 將cursor移到所點選的資料上 */ cursor.moveToPosition(arg2); /* 取得此筆資料的第0個欄位,即id */ _id = cursor.getInt(0); /* EditText顯示此筆資料的第1個欄位,即內容值 */ EditText01.setText(cursor.getString(1)); Button02.setEnabled(true); Button03.setEnabled(true); }});

62 主程式 - GDA02.java /* 宣告insert()方法,並設定內容*/
private void insert(String text){ /* 儲存資料 */ android.content.ContentValues cv = new android.content.ContentValues(); /* put()方法把所傳入的text值加入FIELD02_NAME集合裡 */ cv.put(FIELD02_NAME, text); /* 使用SQLiteDatabase物件的insert()方法,將cv加入資料庫的TABLENAME表單裡 */ dataBase.insert(TABLENAME, null, cv); /* 重新查詢資料庫 */ cursor.requery(); }

63 主程式 - GDA02.java /* 宣告update()方法,並設定內容*/
private void update(int id,String text){ String where = FIELD01_NAME + " = ?"; String[] whereValue = { Integer.toString(id) }; /* 儲存資料 */ android.content.ContentValues cv = new android.content.ContentValues(); /* put()方法把所傳入的text值加入FIELD02_NAME集合裡 */ cv.put(FIELD02_NAME, text); /* 使用SQLiteDatabase物件的update()方法,將資料庫的TABLENAME表單所選取的資料更新成cv */ dataBase.update(TABLENAME, cv, where, whereValue); /* 重新查詢資料庫 */ cursor.requery(); }

64 主程式 - GDA02.java /* 宣告delete()方法,並設定內容*/ private void delete(int id){
String where = FIELD01_NAME + " = ?"; String[] whereValue = { Integer.toString(id) }; /* 使用SQLiteDatabase物件的delete()方法,將TABLENAME表單所選取的資料刪除 */ dataBase.delete(TABLENAME, where, whereValue); /* 重新查詢資料庫 */ cursor.requery(); }

65 Lab7.接收SMS

66 取得字串值 - values\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="title1">Waiting SMS</string> <string name="title2">Receiver SMS</string> <string name="app_name">Receiver SMS</string> </resources> 手機畫面的內容顯示 <String-array> 下拉式選單

67 手機畫面配置 - main.xml LinearLayout線性布局 保持子元素之間的間隔互相對齊

68 手機畫面配置 - image.xml

69 AndroidManifest.xml 註冊Activity的語法 註冊Broadcast Receiver的語法
<application <activity android:name=".GDA03" <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Image" android:label="Image"> <receiver android:name="SMSreceiver"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </receiver> </application> <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8"/> 註冊Activity的語法 註冊Broadcast Receiver的語法 Broadcast Receiver廣播接收器

70 主程式 - GDA03.java package COM.TQC.GDA03; import android.app.Activity;
import android.os.Bundle; /* 宣告GDA03繼承Activity類別 */ public class GDA03 extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }

71 主程式 - SMSreceiver.java /* 宣告SMSreceiver繼承BroadcastReceiver類別 */
public class SMSreceiver extends BroadcastReceiver { /* 宣告一個String物件,用來判斷接收的Broadcast是否為SMS簡訊接收*/ private static final String mACTION = "android.provider.Telephony.SMS_RECEIVED"; /* 當Broadcast Receiver接收到廣播時,Android系統會呼叫onReceive()方法 */ @Override public void onReceive(Context context, Intent intent) { /* 判斷接收到的Broadcast是SMS簡訊接收 */ if (intent.getAction().equals(mACTION)) /* 建立一個Intent ,要從原來的Activity切換到新的Image Activity */ Intent i = new Intent(context, Image.class); /* 宣告Bundle與 i 的內容*/ Bundle mbundle = new Bundle(); /* 把Bundle所帶的資料放入Intent中 */ i.putExtras(mbundle);

72 主程式 - SMSreceiver.java /* Intent加入一個額外的Flags,LAG_ACTIVITY_NEW_TASK設定此Activity為這個工作的起始Activity */ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* 啟動新的Activity*/ context.startActivity(i); }

73 主程式 - Image.java package COM.TQC.GDA03; import android.app.Activity;
import android.os.Bundle; /* 宣告Image繼承Activity*/ public class Image extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image); }

74 Lab8.接收簡訊

75 取得字串值 - values\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">接收簡訊</string> </resources>

76 取得字串值 - values\color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="darkgray">#808080</drawable> <drawable name="white">#FFFFFF</drawable> <drawable name="blue">#0000FF</drawable> </resources>

77 手機畫面配置 - main.xml LinearLayout線性布局 保持子元素之間的間隔互相對齊

78 AndroidManifest.xml <application <activity android:name=".GDA03" <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 建立receiver聆聽系統廣播訊息 --> <receiver android:name="GDA03_SM_Receiver"> <!-- 設定要捕捉的訊息名稱為provider中Telephony.SMS_RECEIVED --> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </receiver> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> Broadcast Receiver廣播接收器

79 主程式 - GDA03.java public class GDA03 extends Activity {
private TextView mTextView1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView1 = (TextView) findViewById(R.id.myTextView1); mTextView1.setText("等待接收簡訊..."); }

80 主程式 - GDA03_SM_Receiver /* 宣告SMSreceiver繼承BroadcastReceiver類別 */
public class GDA03_SM_Receiver extends BroadcastReceiver { /* 宣告一個String物件,用來判斷接收的Broadcast是否為SMS簡訊接收*/ private static final String mACTION = "android.provider.Telephony.SMS_RECEIVED"; /* 當Broadcast Receiver接收到廣播時,Android系統會呼叫onReceive()方法 */ @Override public void onReceive(Context context, Intent intent) /* 判斷接收到的Broadcast是SMS簡訊接收 */ if (intent.getAction().equals(mACTION)) /* 建立一個StringBuilder類別的物件,此類別可以產生字串*/ StringBuilder sb = new StringBuilder(); /* 取得intent的內容,亦即SMS簡訊的內容*/ Bundle bundle = intent.getExtras();

81 主程式 - GDA03_SM_Receiver /* 如果SMS簡訊的內容不是空的 */ if (bundle != null) {
/* 透過bundle.get(“pdus”)建立一個物件 */ Object[] myOBJpdus = (Object[]) bundle.get("pdus"); /* 將pdu轉成SmsMessage */ SmsMessage[] messages = new SmsMessage[myOBJpdus.length]; for (int i = 0; i<myOBJpdus.length; i++) messages[i] = SmsMessage.createFromPdu ((byte[]) myOBJpdus[i]); } /* 將收到的簡訊合併,放入StringBuilder類別的物件中 */ for (SmsMessage currentMessage : messages) sb.append("接收到來自:\n"); /* 取得簡訊的來源位址,放入StringBuilder類別的物件中*/ sb.append(currentMessage.getDisplayOriginatingAddress()); sb.append("\n------傳來的簡訊------\n"); /* 取得簡訊的訊息內容,放入StringBuilder類別的物件中*/ sb.append(currentMessage.getDisplayMessageBody()); PDU(protocol description unit)

82 主程式 - GDA03_SM_Receiver /* 用Toast把簡訊顯示出來 */
oast.makeText(context, sb.toString(), Toast.LENGTH_LONG).show(); /* 透過Intent,回到主程式*/ Intent i = new Intent(context, GDA03.class); /* 設定標籤*/ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } Toast可以快顯訊息,只佔用訊息所需的螢幕空間,顯示幾秒後就消失,且不會與使用者互動,在顯示中不會影響目前與後續作業,適合用在提示「檔案已經刪除」、「電力不足」等提醒功能。

83 使用DDMS來傳送SMS

84 Lab9.程式背景音樂

85 取得字串值 - values\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">程式背景音樂</string> </resources>

86 取得字串值 - values\color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="darkgray">#808080</drawable> <drawable name="white">#FFFFFF</drawable> <drawable name="black">#000000</drawable> <drawable name="blue">#0000FF</drawable> </resources>

87 手機畫面配置 - main.xml LinearLayout線性布局 保持子元素之間的間隔互相對齊

88 主程式 - GDA03.java @Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /* 實體化一個MediaPlayer物件 */ mMediaPlayer01 = new MediaPlayer(); /* 傳入音樂檔給此MediaPlayer物件 */ mMediaPlayer01 = MediaPlayer.create(GDA03.this, R.raw.light); /* 設定音樂重複播放 */ mMediaPlayer01.setLooping(true); }

89 主程式 - GDA03.java /* 覆寫onPause()方法 */ @Override
protected void onPause() { // TODO Auto-generated method stub try /* 停止音樂播放 */ mMediaPlayer01.stop(); } catch(Exception e) e.printStackTrace(); super.onPause();

90 主程式 - GDA03.java /* 覆寫onResume()方法 */ @Override
protected void onResume() { try /* 如果音樂在播放,則停止播放 */ if (mMediaPlayer01 != null) mMediaPlayer01.stop(); } /* 在MediaPlayer取得播放資源與stop()後,準備播放前要使用MediaPlayer.prepare() */ mMediaPlayer01.prepare(); mMediaPlayer01.start(); catch (Exception e) // TODO Auto-generated catch block e.printStackTrace(); super.onResume();

91 Lab10.判斷地標所屬區域

92 取得字串值 - values\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Please input...</string> <string name="app_name">判斷地標所屬區域</string> <string name="str_inside">Within Taipei Arena</string> <string name="str_outside">Outside Taipei Arena</string> </resources>

93 取得字串值 - values\color.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="darkgray">#808080</drawable> <drawable name="white">#FFFFFF</drawable> <drawable name="blue">#0000FF</drawable> </resources>

94 手機畫面配置 - main.xml LinearLayout線性布局 保持子元素之間的間隔互相對齊

95 AndroidManifest.xml 宣告google maps的函式庫 允許存取現在的地理位置
<application <activity android:name=".GDA03" <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="com.google.android.maps"></uses-library> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> </manifest> 宣告google maps的函式庫 Broadcast Receiver廣播接收器 允許存取現在的地理位置

96 主程式 - GDA03.java /* 實體化LocationManager類別的物件 */
mLocationManager01 = (LocationManager)getSystemService(Context.LOCATION_SERVICE); /* 呼叫getLocationPrivider()方法,取得手機地理位置 */ getLocationPrivider(); /* 將currentGeoPoint轉成Google maps的GeoPoint物件 */ currentGeoPoint = getGeoByLocation(currentLocation); /* strLocationPrivider註冊,每2000ms,或位置移動10公尺,就會更新一次GPS訊息*/ mLocationManager01.requestLocationUpdates(strLocationPrivider, 2000, 10, mLocationListener01); Target Name : Google APIs

97 主程式 - GDA03.java /* 判斷位置是否在限定範圍內,如果有就顯示“Within Taipei Arena”,如果沒有就顯示“Outside Taipei Arena”,此判斷是一開始啟動應用程式時*/ if((currentGeoPoint.getLatitudeE6()/1E6)<= && (currentGeoPoint.getLatitudeE6()/1E6)>= && (currentGeoPoint.getLongitudeE6()/1E6)>= && (currentGeoPoint.getLongitudeE6()/1E6)<= ) { mTextView01.setText(getResources().getText(R.string.str_inside)); } else mTextView01.setText(getResources().getText(R.string.str_outside)); Target Name : Google APIs

98 主程式 - GDA03.java /* 實體化LocationListener類別的物件 */
public final LocationListener mLocationListener01 = new LocationListener() { @Override public void onLocationChanged(Location location) /* 呼叫getGeoByLocation(),取得手機地理位置 */ currentGeoPoint = getGeoByLocation(location); /* 判斷位置是否在限定範圍內,此段判斷用在手機位置變動時 */ if((currentGeoPoint.getLatitudeE6()/1E6)<= && (currentGeoPoint.getLatitudeE6()/1E6)>= && (currentGeoPoint.getLongitudeE6()/1E6)>= && (currentGeoPoint.getLongitudeE6()/1E6)<= ) mTextView01.setText(getResources().getText(R.string.str_inside)); } else mTextView01.setText(getResources().getText(R.string.str_outside)); Target Name : Google APIs

99 主程式 - GDA03.java /* 覆寫onProviderDisabled()方法,並設定內容 */ @Override
public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } /* 覆寫onProviderEnabled ()方法,並設定內容 */ public void onProviderEnabled(String provider) /* 覆寫onStatusChanged()方法,並設定內容 */ public void onStatusChanged(String provider, int status, Bundle extras) }; Target Name : Google APIs

100 主程式 - GDA03.java /* 定義getGeoByLocation()方法,並設定內容 */
public GeoPoint getGeoByLocation(Location location) { /* 宣告一個GeoPoint類別的物件 */ GeoPoint gp = null; try if (location != null) /* 取得Locaton物件裡的緯度資料、經度資料*/ double geoLatitude = location.getLatitude()*1E6; double geoLongitude = location.getLongitude()*1E6; /* 由緯度和經度資料,實體化一個GeoPoint類別的物件*/ gp = new GeoPoint((int) geoLatitude, (int) geoLongitude); } catch(Exception e) e.printStackTrace(); return gp; Target Name : Google APIs

101 主程式 - GDA03.java 設定精確度 設定不提供高度訊息 設定不提供方位訊息 設定得到定位資訊時會產生費用 設定低電量需求
/* 定義getLocationPrivider()方法,並設定內容 */ public void getLocationPrivider() { try Criteria mCriteria01 = new Criteria(); mCriteria01.setAccuracy(Criteria.ACCURACY_FINE); mCriteria01.setAltitudeRequired(false); mCriteria01.setBearingRequired(false); mCriteria01.setCostAllowed(true); mCriteria01.setPowerRequirement(Criteria.POWER_LOW); /* 根據Criteria所設定的條件,取得最佳定位服務提供者 */ strLocationPrivider = mLocationManager01.getBestProvider(mCriteria01, true); /* 透過提供者,取得最後一筆位置資料*/ currentLocation = mLocationManager01.getLastKnownLocation(strLocationPrivider); } catch(Exception e) e.printStackTrace(); 設定精確度 設定不提供高度訊息 設定不提供方位訊息 設定得到定位資訊時會產生費用 設定低電量需求 Target Name : Google APIs

102 使用DDMS做移動手機的位置模擬


Download ppt "Lab4.BMI計算."

Similar presentations


Ads by Google