Android開發—隨筆雜記(2010年的)

2010.8.9php

一、\res\layout\目錄下的xml文件的文件名必須是小寫的字母或數字。html

二、跨資源文件交叉使用的方式:使用@符號後面加上resource_type名稱String,最後加上變量名稱String。例:在res\layout\main.xml佈局文件當中引用另外一個資源文件res\values\Strings.xml中的變量string1來設置變量text:android:text="@string/string1"。java

三、"@+"符號表示自動建立R.id類的資源號碼,例:<EditText id="@+id/text"/>就表示替<EditText>XML加上一個資源ID號碼,而這個資源會自動唄定義到R.java資源類文件中。android

 

四、在設置畫面佈局的時候,注意:<ScrollView>標籤內部不能有多個標籤組對,只能有對標籤;網絡

        例如:   <ScrollView> <LinearLayout>......</LinearLayout></ScrollView>ide

2010.8.10工具

 五、學習其餘人應用的佈局方法:佈局

Hierarchy Viewer 幫你分析應用程序UI佈局

Hierarchy Viewer在android的工具文件夾裏: \android\tools\hierarchyviewer.bat

   1.啓動 模擬器。

   2.到\android\tools\目錄下,雙擊能夠啓動hierarchyviewerbat文件,打開一個圖形界面。

  3.點擊 load View hierarchy按鈕,就能夠捕獲模擬器當前activity的畫面佈局信息。

  4.hierarchy經過樹形結構展現佈局形式。

  5.雙擊樹節點能夠展現單獨的UI部分。

  6.當模擬器activity畫面變動後,點擊refresh能夠加載新的頁面佈局信息。

經過Hierarchy Viewer你就能夠學習別人優秀的佈局方式,
同時也更能更深刻更全面更總體的把握xml佈局文件。
體會UI和代碼(java code)以及資源(res)的相互分離。post

轉自:http://rayleung.javaeye.com/blog/434025學習

6、畫面佈局的時候涉及到EditText的時候,軟鍵盤對畫面的這該問題(待總結)。

七、設計界面UI的一款開源工具:droiddraw;下載地址:http://code.google.com/p/droiddraw/downloads/list(另見附件:droiddraw.jar)

八、Android開發中應該注意的細節:轉自:http://wayfarer.javaeye.com/blog/444061

2010.8.13

九、調用android系統自帶的應用的Intent總結(來自網絡)

 來個總結:

顯示網頁: Uri uri = Uri.parse("http://www.google.com");

Intent it = new Intent(Intent.ACTION_VIEW,uri);

startActivity(it);
複製代碼顯示地圖: Uri uri = Uri.parse("geo:38.899533,-77.036476");

Intent it = new Intent(Intent.Action_VIEW,uri);

startActivity(it); 
複製代碼路徑規劃: 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);
複製代碼撥打電話:
調用撥號程序 Uri uri = Uri.parse("tel:xxxxxx");

Intent it = new Intent(Intent.ACTION_DIAL, uri);  

startActivity(it);  
複製代碼Uri uri = Uri.parse("tel.xxxxxx");

Intent it =new Intent(Intent.ACTION_CALL,uri);

要使用這個必須在配置文件中加入<uses-permission id="android.permission.CALL_PHONE" />
複製代碼發送SMS/MMS
調用發送短信的程序 Intent it = new Intent(Intent.ACTION_VIEW);  

it.putExtra("sms_body", "The SMS text");  

it.setType("vnd.android-dir/mms-sms");  

startActivity(it);  
複製代碼發送短信 Uri uri = Uri.parse("smsto:0800000123");  

Intent it = new Intent(Intent.ACTION_SENDTO, uri);  

it.putExtra("sms_body", "The SMS text");  

startActivity(it);  
複製代碼發送彩信 Uri uri = Uri.parse("content://media/external/p_w_picpaths/media/23");  

Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra("sms_body", "some text");  

it.putExtra(Intent.EXTRA_STREAM, uri);  

it.setType("p_w_picpath/png");  

startActivity(it); 
複製代碼發送Email 

Uri uri = Uri.parse("mailto:xxx@abc.com");

Intent it = new Intent(Intent.ACTION_SENDTO, uri);

startActivity(it);
複製代碼Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");  

it.putExtra(Intent.EXTRA_TEXT, "The email body text");  

it.setType("text/plain");  

startActivity(Intent.createChooser(it, "Choose Email Client"));  
複製代碼Intent it=new Intent(Intent.ACTION_SEND);  

String[] tos={"me@abc.com"};  

String[] ccs={"you@abc.com"};  

it.putExtra(Intent.EXTRA_EMAIL, tos);  

it.putExtra(Intent.EXTRA_CC, ccs);  

it.putExtra(Intent.EXTRA_TEXT, "The email body text");  

it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

it.setType("message/rfc822");  

startActivity(Intent.createChooser(it, "Choose Email Client"));  
複製代碼添加附件 Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");  

sendIntent.setType("audio/mp3");  

startActivity(Intent.createChooser(it, "Choose Email Client"));
複製代碼播放多媒體  

Intent it = new Intent(Intent.ACTION_VIEW);

Uri uri = Uri.parse("file:///sdcard/song.mp3");

it.setDataAndType(uri, "audio/mp3");

startActivity(it);
複製代碼Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");  

Intent it = new Intent(Intent.ACTION_VIEW, uri);  

startActivity(it);  
複製代碼Uninstall 程序 Uri uri = Uri.fromParts("package", strPackageName, null);  

Intent it = new Intent(Intent.ACTION_DELETE, uri);  

startActivity(it);

例子:一個應用,其中的一項功能是收發e-mail,android系統自己帶有e-mail功能,能夠把系統自帶的功能加入到該應用中來。

只要指定email地址,而後發個intent就能夠把Email啓動起來了:

Uri uri = Uri.parse("mailto:xxx@abc.com"); 

Intent it = new Intent(Intent.ACTION_SENDTO, uri); 

startActivity(it); 

2010.8.16

十、startActivityForResult 用法:

startActivityForResult 用法:http://www.javaeye.com/topic/577342

android Activity 之 startActivityForResult 的使用:http://hi.baidu.com/stalwart/blog/item/a25334cd72b8e2580fb34580.html

Android:不一樣Activity之間的數據傳遞:http://blog.chinaunix.net/u/20947/showart_1964127.html

十一、自定義控件的相關分析資料:

 

 

 2010.10.16

Android開發經驗:得到IMSI / IMEI的方法(SIM和手機的惟一識別ID)

  學習內容: 你將學到如何讀出你手機裏的SIM卡的IMSI (國際移動用戶ID) 和IMEI (國際移動設備ID). IMSI 與 SIM惟一對應, IMEI 與 設備惟一對應.

  可能應用的場合: 你可能須要 惟一的id 去受權/註冊,或者用於你的Android-Activity的license目的 下面的兩行代碼將會使你得到SIM卡惟一 ID IMSI 和設備惟一ID IMEI

  描述:
  IMSI是一個 惟一的數字, 標識了GSM和UMTS 網絡裏的惟一一個用戶. 它 存儲 在手機的SIM卡里,它會經過手機發送到網絡上.

  IMEI也是一串惟一的數字, 標識了 GSM 和 UMTS網絡裏的惟一一個手機. 它一般被打印在手機裏電池下面的那一面,撥  *#06# 也能看到它.

  代碼: 這裏是你在Android裏讀出 惟一的 IMSI-ID / IMEI-ID 的方法。
Java:
         String myIMSI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMSI);
// within my emulator it returns:   310995000000000

String myIMEI = android.os.SystemProperties.get(android.telephony.TelephonyProperties.PROPERTY_IMEI);
// within my emulator it returns:   0000000000000

 

 

 

 

深度定製界面風格淺析:http://www.ophonesdn.com/article/show/37

Android高手進階教程(四)之----Android 中自定義屬性(attr.xml,TypedArray)的使用:http://weizhulin.blog.51cto.com/1556324/311453

相關文章
相關標籤/搜索