1.啟動程式無需動畫
Java代碼
- myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);//1.5的應該使用,這樣就可以沒有動畫效果了
- getWindow().setWindowAnimations(1)//1.6的應該使用,這不要忘記放在activity
2.SD卡建立目錄
Java代碼
- File wallpaperDirectory = new File("/sdcard/Wallpaper/");
- wallpaperDirectory.mkdirs();
- File outputFile = new File(wallpaperDirectory, filename);
- FileOutputStream fos = new FileOutputStream(outputFile);
注意要添加許可權哦
Xml代碼
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3.文字中間加橫線效果
Java代碼
- priceTV.setText("價格:2.00元");
- priceTV.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
4.android中使用事務操作SQLite資料庫
Java代碼
- SQLiteDatabase db = ....;
- db.beginTransaction();//開始事務
- try {
- db.execSQL("insert into person(name, age) values(?,?)", new Object[]{"張三",
-
- 4});
- db.execSQL("update person set name=? where personid=?", new Object[]{"李四", 1});
- db.setTransactionSuccessful();//調用此方法會在執行到endTransaction()時提交當前事
-
- 務,如果不調用此方法會復原事務
- } finally {
- db.endTransaction();//由事務的標誌決定是提交事務,還是復原事務
- }
- db.close();
5. 關於簡訊類SmsMessage的疑問
Java代碼
- public void onReceive(Context context, Intent intent) {
- // TODO Auto-generated method stub
- Log.d(TAG, "--->onReceive ,SMS reach");
-
- Bundle bundle = intent.getExtras();
- if (bundle != null) {
- Object[] pdus = (Object[]) bundle.get("pdus");
- SmsMessage[] messages = new SmsMessage[pdus.length];
- for (int i = 0; i < pdus.length; i++) {
- messages = SmsMessage.createFromPdu((byte[]) pdus);
- }
- for (SmsMessage smsMessage : messages) {
- from = smsMessage.getDisplayOriginatingAddress();
- data = smsMessage.getDisplayMessageBody().trim();
- Log.d(TAG, from + " " + data);
- //處理內容
- response(context, data);
- }
- }
- }
6.android中的WebView支援多點觸控:
Java代碼
- public class UsingMyWebview extends Activity {
- private WebView mWebView;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- // Get Web view
- mWebView = (WebView) findViewById(R.id.MyWebview);// This is the id you gave to the WebView in the main.xml
- mWebView.getSettings().setJavaScriptEnabled(true);
- mWebView.getSettings().setSupportZoom(true);
- // Zoom Control on web (You don't need this if ROM supports Multi-Touch
- mWebView.getSettings().setBuiltInZoomControls(true);// Enable Multitouch if supported by ROM
- //Load URL
- mWebView.loadUrl("http://www.firstdroid.com/advertisement.htm");
- }
- }
7.android程式開機自動啟動實現:
Xml代碼
- <receiver android:name=".BootBroadcastReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- </receiver>
在manifest檔案的application標籤中添加receiver標籤,並且android:name指定一個BroadcastReceiver,通過過濾器實現過濾開機的完成那個廣播。
Java代碼
- package com.jftt.bootstart;
-
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
-
- public class BootBroadcastReceiver extends BroadcastReceiver {
- static final String ACTION = "android.intent.action.BOOT_COMPLETED";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(ACTION)) {
- Intent sayHelloIntent = new Intent(context, BootStart.class);//指定要開啟的activity頁面
- sayHelloIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
- context.startActivity(sayHelloIntent);
- }
- }
- }