1. 說明
撥打電話權限:<uses-permission android:name="android.permission.CALL_PHONE" />
允許程式新增模擬位置(DDMS提供模擬GPS位址給模擬器測試用):android.permission.ACCESS_MOCK_LOCATION
允許程式存取CellID或WiFi熱點來取得粗略的位置:android.permission.ACCESS_COARSE_LOCATION
存取閃光燈:android.permission.FLASHLIGHT
允許程式使用網路權限android.permission.INTERNET
允許程式讀取簡訊訊息android.permission.READ_SMS
請求能夠重新啟動設備:android.permission.REBOOT
允許一個程式初始化一個電話撥號不需透過撥號使用者界面需要使用者確認:android.permission.CALL_PHONE
允許程式錄製音訊:android.permission.RECORD_AUDIO
允許程式發送簡訊:android.permission.SEND_SMS
允許程式讀取使用者聯絡人資料:android.permission.READ_CONTACTS
允許程式設定時間區域android.permission.SET_TIME_ZONE
允許存取振動設備:android.permission.VIBRATE
允許程式寫入資料:android.permission.WRITE_OWNER_DATA
允許一個程式存取精確位置(如GPS):android.permission.ACCESS_FINE_LOCATION
允許程式存取Wi-Fi網路狀態訊息:android.permission.ACCESS_WIFI_STATE
允許程式更新手機電池統計訊息:android.permission.BATTERY_STATS
允許程式連接到已配對的藍牙設備:android.permission.BLUETOOTH
請求存取使用照相設備:android.permission.CAMERA
允許程式刪除暫存檔案:android.permission.DELETE_CACHE_FILES
允許程式改變Wi-Fi連接狀態:android.permission.CHANGE_WIFI_STATE
2013年8月6日 星期二
(Android Note) App 呼叫另一個 App
1. code
Intent intent = new Intent("android.intent.action.MAIN");
intent.setClassName("package", "package.class"); //package name and class name
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT );
startActivity(intent);
<!--隱藏不顯示在桌面 <category android:name="android.intent.category.LAUNCHER" /> -->
intent.setClassName("package", "package.class"); //package name and class name
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT );
startActivity(intent);
<!--隱藏不顯示在桌面 <category android:name="android.intent.category.LAUNCHER" /> -->
2013年5月31日 星期五
(Android Note) Refresh Tabhost
加入此行(addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)),每次按tab鍵就會重整.
example:
new Intent(this,X.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
example:
new Intent(this,X.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
2013年5月29日 星期三
(Android Note) is not valid; is your activity running?
由於父activity包含子activity,但是子的activity要產生一個new AlertDialog.Builder(this),此時就會發生錯誤。
解決方式,把this改成指向父節點getParent()。
解決方式,把this改成指向父節點getParent()。
2013年2月28日 星期四
android:Theme 用法
說明
(1) /res/values/目錄, 預設的styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
(2) 參數
android:theme="Theme.Light" //背景為白色
android:theme="Theme.Light.NoTitleBar" //白色背景並無標題欄
android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,無標題欄,全螢幕
android:theme="Theme.Black" //背景黑色
android:theme="Theme.Black.NoTitleBar" //黑色背景,無標題欄
android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,無標題欄,全螢幕
android:theme="Translucent" //半透明
android:theme="Theme.Translucent.NoTitleBar"
android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
android:theme="@android:style/Theme.Dialog" //將一個Activity顯示為話框模式
android:theme="@android:style/Theme.NoTitleBar" //無標題欄
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //無標題欄,全螢幕
android:theme="Theme.Wallpaper" //系統桌面為應用程式背景
android:theme="Theme.Wallpaper.NoTitleBar" //系統桌面為應用程式背景,無標題欄
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //系統桌面為應用程式背景,無標題欄,全螢幕
(1) /res/values/目錄, 預設的styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
</resources>
(2) 參數
android:theme="Theme.Light" //背景為白色
android:theme="Theme.Light.NoTitleBar" //白色背景並無標題欄
android:theme="Theme.Light.NoTitleBar.Fullscreen" //白色背景,無標題欄,全螢幕
android:theme="Theme.Black" //背景黑色
android:theme="Theme.Black.NoTitleBar" //黑色背景,無標題欄
android:theme="Theme.Black.NoTitleBar.Fullscreen" //黑色背景,無標題欄,全螢幕
android:theme="Translucent" //半透明
android:theme="Theme.Translucent.NoTitleBar"
android:theme="Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="Theme.Panel"
android:theme="Theme.Light.Panel"
android:theme="@android:style/Theme.Dialog" //將一個Activity顯示為話框模式
android:theme="@android:style/Theme.NoTitleBar" //無標題欄
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" //無標題欄,全螢幕
android:theme="Theme.Wallpaper" //系統桌面為應用程式背景
android:theme="Theme.Wallpaper.NoTitleBar" //系統桌面為應用程式背景,無標題欄
android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" //系統桌面為應用程式背景,無標題欄,全螢幕
2013年1月15日 星期二
(Android Note) 驗證是否有網路連線
1. code
//判斷當前網路連接狀態 、0 無連接 、1 3G、2 WIFI
public static int checkNetworkInfo(Context context){
int stateType = 0;
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
State mobile =
cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); //取得3G連線狀態
State wifi =
cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); //取得WIFI連線狀態
if (mobile == State.CONNECTED || mobile == State.CONNECTING){
stateType = 1;
}
if (wifi == State.CONNECTED || wifi == State.CONNECTING){
stateType = 2;
}
return stateType;
}
- <uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE" /> //訪問存取網路狀態許可權限
- <uses-permissionandroid:name="android.permission.ACCESS_WIFI_STATE" /> //訪問存取wifi狀態許可權限
- <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> //訪問存取手機狀態許可權限
(Android Note) AlertDialog.Builder
1. Code
final AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(" Test ");
builder.setMessage(" Test ");
builder.setIcon(android.R.drawable.ic_dialog_alert);
//3種事件處理方式
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setNeutralButton("other things", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
final AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle(" Test ");
builder.setMessage(" Test ");
builder.setIcon(android.R.drawable.ic_dialog_alert);
//3種事件處理方式
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setNeutralButton("other things", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
2013年1月3日 星期四
(Android Note) 內部和外部儲存空間大小
1. Code
(1) sdcard 是否存在
android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
return true; //存在
return false; //不存在
(2) 內部儲存空間
File path = android.os.Environment.getDataDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
(3) sdcard儲存空間
File path = android.os.Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
2. 說明
bs(block size),在fat32檔案系統, block size是 4096 byte,其他可以用getBlockSize()來找出block size 大小。
(1) sdcard 是否存在
android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
return true; //存在
return false; //不存在
(2) 內部儲存空間
File path = android.os.Environment.getDataDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
(3) sdcard儲存空間
File path = android.os.Environment.getExternalStorageDirectory();
StatFs sf = new StatFs(path.getPath());
long bs = sf.getBlockSize();
long ab = stat.getAvailableBlocks();
long bc = stat.getBlockCount();
retrun bs*ab; //剩餘儲存空間
retrun bs*bc; //總儲存空間
2. 說明
bs(block size),在fat32檔案系統, block size是 4096 byte,其他可以用getBlockSize()來找出block size 大小。
訂閱:
文章 (Atom)