//能夠取得螢幕的資訊
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
dm.widthPixels; //取得寬像素
dm.heightPixels; //取得高像素
//擷取當地的日曆
Calendar c=Calendar.getInstance(); mYear=c.get(Calendar.YEAR);//擷取年份 mMonth=c.get(Calendar.MONTH);//擷取月份 mDay=c.get(Calendar.DAY_OF_MONTH);//擷取號數 mHour=c.get(Calendar.HOUR_OF_DAY);//擷取小時
mMinute=c.get(Calendar.MINUTE); //擷取分鐘
//把EditText的內容設為可視或隱藏
/* 設定EditText的內容為可見的 */
editText.setTransformationMethod(
HideReturnsTransformationMethod.getInstance());
/* 設定EditText的內容為隱藏的 */
editText.setTransformationMethod(
PasswordTransformationMethod.getInstance());
//啟動activity時不自動彈出軟鍵盤
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//設定全屏(在setContentView之前設定) getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//設定取消全屏
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//設定無標題
(在setContentView之前設定)
requestWindowFeature(Window.FEATURE_NO_TITLE);
//設定禁止手機橫屏(在setContentView之前設定)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
//調用手機預設的攝像功能,而且可以設定儲存位置
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment .getExternalStorageDirectory(),"pic.jpg")));
//解決中文亂碼方法
A. 使用getBytes("") 來對漢字進行重編碼,得到它的位元組數組
B. 再使用new String(Bytes[] , "解碼方式") 來對位元組數組進行相應的解碼
//在Android中輕鬆實現橫豎屏的布局
豎屏的布局一般在layout下面設定;橫屏的布局則在layout的同等級檔案夾建立名字layout-land的檔案夾。模擬器可以使用Ctrl+F11進行快速切換。
//Android橫豎屏切換不重啟Activity
androidmanifest.xml中的activit元素加入這個屬性android:configChanges="orientation|keyboardHidden"
然後在Activity中重載以下方法:
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.imageswitch);
//橫屏
} else {
setContentView(R.layout.editcontact);//豎屏
}
super.onConfigurationChanged(newConfig);
}
卸載程式:
Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI); startActivity(uninstallIntent);
安裝apk:
String str = "/CanavaCancel.apk"; String fileName = Environment.getExternalStorageDirectory() + str; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); startActivity(intent);