android编程中的琐碎知识点汇总(5)
2012-01-06 16:27
330 查看
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);
}
}
}
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);
}
}
}
相关文章推荐
- android编程中的琐碎知识点汇总(2)
- android编程中的琐碎知识点汇总(3)
- android编程中的琐碎知识点汇总(4)
- Android 琐碎知识点汇总
- android编程易忘知识点
- Android知识点汇总
- Android琐碎知识点,不断更新中
- [置顶] Android应用开发—知识点汇总
- STL + c++ + 模板 + 重要思维 + 基础算法+ 经典算法 + 经典实例 + 编程总结+ 心得+ 入门必会 + 知识点汇总。+string +dfs +bfs等重要算法
- android琐碎知识点记载
- Android知识点汇总--第二篇
- Android 开发过程中小知识点汇总
- Android知识点汇总
- 【Android知识点精讲】(10)网络编程
- Android知识点汇总
- Android RecyclerView源码与知识点汇总
- STL + c++ + 模板 + 重要思维 + 基础算法+ 经典算法 + 经典实例 + 编程总结+ 心得+ 入门必会 + 知识点汇总。
- Office编程知识点汇总:基本工作簿任务
- 常用Android布局学习知识点汇总