一、打开一个网页,类别是Intent.ACTION_VIEW
Uri uri = Uri.parse(“http://www.chinasofti.com/”);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
二、打开地图并定位到一个点
Uri uri = Uri.parse(“geo:52.76,-79.0342″);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
三、打开拨号界面 ,类型是Intent.ACTION_DIAL
Uri uri = Uri.parse(“tel:10086″);
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
四、直接拨打电话,与三不同的是,这个直接拨打电话,而不是打开拨号界面
Uri uri = Uri.parse(“tel:10086″);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
五、卸载一个应用,Intent的类别是Intent.ACTION_DELETE
Uri uri = Uri.fromParts(“package”, “xxx”, null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
六、安装应用程序,Intent的类别是Intent.ACTION_PACKAGE_ADDED
Uri uri = Uri.fromParts(“package”, “xxx”, null);
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);
七、播放音频文件
Uri uri = Uri.parse(“file:///sdcard/download/everything.mp3″);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType(“audio/mp3″);
八、打开发邮件界面
Uri uri= Uri.parse(“mailto:test@163.com”);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
九、发邮件,与八不同这里是将邮件发送出去,
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { “ mailto:test@163.com ” };
String[] ccs = { “ test1@163.com ” };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, “I come from http://www.chinasofti.com”);
intent.putExtra(Intent.EXTRA_SUBJECT, “http://www.chinasofti.com”);
intent.setType(“message/rfc882″);
Intent.createChooser(intent, “Choose Email Client”);
//发送带附件的邮件
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, “The email subject text”);
intent.putExtra(Intent.EXTRA_STREAM, “file:///sdcard/mysong.mp3″);
intent.setType(“audio/mp3″);
startActivity(Intent.createChooser(intent, “Choose Email Client”));
十、发短信
Uri uri= Uri.parse(“tel:10086″);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(“sms_body”, “I come from http://www.chinasofti.com”);
intent.setType(“vnd.android-dir/mms-sms”);
十一、直接发邮件
Uri uri= Uri.parse(“smsto://100861″);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra(“sms_body”, “3g android http://www.chinasofti.com”);
十二、发彩信
Uri uri= Uri.parse(“content://media/external/images/media/23″);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(“sms_body”, “3g android http://www.chinasofti.com”);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType(“image/png”);
十三、# Market 相关
1 //寻找某个应用
Uri uri = Uri.parse(“market://search?q=pname:pkg_name”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
2 //显示某个应用的相关信息
Uri uri = Uri.parse(“market://details?id=app_id”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar
十四、路径规划
Uri uri = Uri.parse(“http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
使用流读取文件
/**
* find the file out put with str,via stream
*
* @author hiddenGreen
* @param context
* @param fileName
* @param fileContent
* @return
* @throws IOException
*/
public static String getFileViaStream(Context context, EditText fileName,
EditText fileContent) throws IOException {
InputStream in = context.openFileInput(fileName.getText().toString());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
byte[] b = out.toByteArray();
in.close();
out.close();
return new String(b);
}
/**
* save file via stream
*
* @author hiddenGreen
* @param context
* @param fileName
* @param fileContent
* @throws IOException
*/
public static void save2FileViaStream(Context context, EditText fileName,
EditText fileContent) throws IOException {
OutputStream out = context.openFileOutput( fileName.getText().toString(), context.MODE_APPEND);
out.write(fileContent.getText().toString().getBytes());
out.close();
}
9.3使用sharedPerference将文件写入xml和从xml读取/**
* map is used to put info with name and value
* @param context
* @param fileName
* @param map
* @param MODE
*/
public static void save2FileViaSharePreferences(Context context, String fileName,
Map<String, String> map, int MODE) {
SharedPreferences sf = context.getSharedPreferences(fileName,
context.MODE_PRIVATE);
Editor edit = sf.edit();
Set<Entry<String, String>> mapit = map.entrySet();
Iterator<Entry<String, String>> ite = mapit.iterator();
while (ite.hasNext()) {
Entry<String, String> et = ite.next();
edit.putString(et.getKey(), et.getValue());
}
edit.commit();//rollback or commit if pass or not
}
/**
*
* @param context
* @param fileName
* @param names
* @return string format as name:value;name:value
*/
public static String getFileViaSharePreferences(Context context, String fileName,
String[] names ) {
StringBuilder str=new StringBuilder();
SharedPreferences sf = context.getSharedPreferences(fileName,
context.MODE_PRIVATE);
for(int i=0;i<names.length;i++){
str.append(names[i]+":"+sf.getString(names[i], "no result")+";");
}
String str1=str.toString();
return str1.substring(0,str1.lastIndexOf(";"));
}
如果已经有wifi上网的,无视之。过程有点复杂,需要执行一些命令。这些命令可以写成脚本,下面我简单说一下原理。
先看脚本,这些脚本都是建立蓝牙局域网再执行,我把他放在前面,只是想对他进行简单的分析。
busybox ifconfig bnep0 192.168.3.120 netmask 255.255.255.0
busybox r oute del -net 192.168.0.0netmask 255.255.255.0dev bnep0
busybox r oute add default gw 192.168.3.9
busybox ifcofig
busybox r oute
busybox ping 192.168.3.9
如果有看得明白的,我想你已经懂了他的原理,以上命令都可以通过超级终端输入,把超级终端设置为su,第一条命令是对蓝牙设备设置ip ,蓝牙在安卓手机上装置代号为bnep0 ,蓝牙设备ip默认为192.168.0.1。因为与我pc的局域网的网段重复,所以修改成192.168.3.120;第二条命令删除能蓝牙设备自动产生的路由;第三条命令添加所需的路由,其中192.168.3.9为pc端蓝牙设备的网络连接的ip.注:不是本地连接;第四条命令查看ip;第五条命令查看路由;第六条命令测试与pc端蓝牙设备的通信(在pc端的蓝牙设备设置好了 再测试) 。pc端设置,先用蓝牙适配器与手机配对,并建立蓝牙局域网(如果不会 请看蓝牙说明书) ,把本地连接属性--高级--连接共享,家庭网络连接选择,蓝牙设备产生的网络连接(名字因不同的设备与不同的驱动,可以产生不同的名,比如:本地连接X,bluetooth等),修改pc蓝牙设备的ip为192.168.3.9255.255.255.0,dns 根据当地与运营商自行设置,这样你可以用手机上网了。