1.启动程序无需动画
myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);//1.5的应该使用,这样就可以没有动画效果了 getWindow().setWindowAnimations(1)//1.6的应该使用,这不要忘记放在activity
2.SD卡创建目录
File wallpaperDirectory = new File("/sdcard/Wallpaper/"); wallpaperDirectory.mkdirs(); File outputFile = new File(wallpaperDirectory, filename); FileOutputStream fos = new FileOutputStream(outputFile);
注意要添加权限哦
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3.文字中间加横线效果
priceTV.setText("价格:2.00元"); priceTV.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
4.android中使用事务操作SQLite数据库
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的疑问
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支持多点触控:
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程序开机自动启动实现:
<receiver android:name=".BootBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
在manifest文件的application标签中添加receiver标签,并且android:name指定一个BroadcastReceiver,通过过滤器实现过滤开机的完成那个广播。
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); } } }