打开主界面:
Intent intent = new Intent();
intent.setAction(“android.intent.action.MAIN”);
intent.addCategory(“android.intent.category.HOME”);
startActivity(intent);
从google搜索内容
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,”searchString”)
startActivity(intent);
显示地图
Uri uri = Uri.parse(“geo:38.899533,-77.036476”);
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);
路径规划
Uri uri = Uri.parse(“http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en“);
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);
调用发短信的程序
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra(“sms_body”, “The SMS text”);
it.setType(“vnd.android-dir/mms-sms”);
startActivity(it);
发送短信
Uri uri = Uri.parse(“smsto:0800000123”);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra(“sms_body”, “The SMS text”);
startActivity(it);
String body=”this is sms demo”;
Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(“smsto”, number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
startActivity(mmsintent);
发送彩信
Uri uri = Uri.parse(“content://media/external/images/media/23”);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(“sms_body”, “some text”);
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType(“image/png”);
startActivity(it);
StringBuilder sb = new StringBuilder();
sb.append(“file://”);
sb.append(fd.getAbsoluteFile());
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(“mmsto”, number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);
startActivity(intent);
发送Email
Uri uri = Uri.parse(“mailto:xxx@abc.com”);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, “me@abc.com”);
it.putExtra(Intent.EXTRA_TEXT, “The email body text”);
it.setType(“text/plain”);
startActivity(Intent.createChooser(it, “Choose Email Client”));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={“me@abc.com”};
String[] ccs={“you@abc.com”};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, “The email body text”);
it.putExtra(Intent.EXTRA_SUBJECT, “The email subject text”);
it.setType(“message/rfc822”);
startActivity(Intent.createChooser(it, “Choose Email Client”));
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, “The email subject text”);
it.putExtra(Intent.EXTRA_STREAM, “file:///sdcard/mysong.mp3”);
sendIntent.setType(“audio/mp3”);
startActivity(Intent.createChooser(it, “Choose Email Client”));
播放多媒体
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(“file:///sdcard/song.mp3”);
it.setDataAndType(uri, “audio/mp3”);
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, “1”);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
打开照相机
<1>Intent i &#61; new Intent(Intent.ACTION_CAMERA_BUTTON, null);
this.sendBroadcast(i);
<2>long dateTaken &#61; System.currentTimeMillis();
String name &#61; createName(dateTaken) &#43; “.jpg”;
fileName &#61; folder &#43; name;
ContentValues values &#61; new ContentValues();
values.put(Images.Media.TITLE, fileName);
values.put(“_data”, fileName);
values.put(Images.Media.PICASA_ID, fileName);
values.put(Images.Media.DISPLAY_NAME, fileName);
values.put(Images.Media.DESCRIPTION, fileName);
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);
Uri photoUri &#61; getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent inttPhoto &#61; new Intent(MediaStore.ACTION_IMAGE_CAPTURE); inttPhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); startActivityForResult(inttPhoto, 10);
从gallery选取图片
Intent i &#61; new Intent();
i.setType(“image/*”);
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(i, 11);
打开录音机
Intent mi &#61; new Intent(Media.RECORD_SOUND_ACTION);
startActivity(mi);
显示应用详细列表
Uri uri &#61; Uri.parse(“market://details?id&#61;app_id”);
Intent it &#61; 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
刚才找app id未果&#xff0c;结果发现用package name也可以 Uri uri &#61; Uri.parse("market://details?id&#61;
寻找应用
Uri uri &#61; Uri.parse(“market://search?q&#61;pname:pkg_name”);
Intent it &#61; new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
打开联系人列表
<1>
Intent i &#61; new Intent(); i.setAction(Intent.ACTION_GET_CONTENT); i.setType("vnd.android.cursor.item/phone"); startActivityForResult(i, REQUEST_TEXT);
<2>
Uri uri &#61; Uri.parse("content://contacts/people"); Intent it &#61; new Intent(Intent.ACTION_PICK, uri); startActivityForResult(it, REQUEST_TEXT);
打开另一程序
Intent i &#61; new Intent();
ComponentName cn &#61; new ComponentName(“com.yellowbook.android2”,
“com.yellowbook.android2.AndroidSearch”);
i.setComponent(cn);
i.setAction(“android.intent.action.MAIN”);
startActivityForResult(i, RESULT_OK);
调用系统编辑添加联系人&#xff08;高版本SDK有效&#xff09;&#xff1a;
Intent it &#61; newIntent(Intent.ACTION_INSERT_OR_EDIT);
it.setType(“vnd.android.cursor.item/contact”);
//it.setType(Contacts.CONTENT_ITEM_TYPE);
it.putExtra(“name”,”myName”);
it.putExtra(android.provider.Contacts.Intents.Insert.COMPANY, “organization”);
it.putExtra(android.provider.Contacts.Intents.Insert.EMAIL,”email”);
it.putExtra(android.provider.Contacts.Intents.Insert.PHONE,”homePhone”);
it.putExtra(android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,
“mobilePhone”);
it.putExtra( android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,
“workPhone”);
it.putExtra(android.provider.Contacts.Intents.Insert.JOB_TITLE,”title”);
startActivity(it);
调用系统编辑添加联系人&#xff08;全有效&#xff09;&#xff1a;
Intent intent &#61; newIntent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.NAME, “My Name”);
intent.putExtra(Contacts.Intents.Insert.PHONE, “&#43;1234567890”);
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE,Contacts.PhonesColumns.TYPE_MOBILE);
intent.putExtra(Contacts.Intents.Insert.EMAIL, “com&#64;com.com”);
intent.putExtra(Contacts.Intents.Insert.EMAIL_TYPE,Contacts.ContactMethodsColumns.TYPE_WORK);
startActivity(intent);
打开系统短信应用,分享软件:
Intent intent&#61;new Intent();
intent.setAction(“android.intent.action.SEND”);
intent.setType(“text/plain”);
intent.putExtra(Intent.EXTRA_TEXT, “推荐您使用一款软件”&#43;appInfo.getName()&#43;”,下载地址google市场”);
startActivity(intent);
打开程序详细信息:
// 详细信息
Intent intent &#61;new Intent();
intent.setAction(“android.settings.APPLICATION_DETAILS_SETTINGS”);
intent.setData(Uri.parse(“package:”&#43;appInfo.getPackageName()));//打开指定包名应用的详细信息
startActivity(intent);
拨打电话意图:
// 电话
Intent intent &#61; new Intent();
intent.setAction(Intent.ACTION_CALL); // 设置动作
intent.setData(Uri.parse(“tel://123456”)); // 设置数据
启动浏览器打开指定网页:
// 网页
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(“http://192.168.1.45:8080/androidWeb“));
启动音乐播放器意图:
// 音频/视频&#xff0c;设置type
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(“file:///mnt/sdcard/daqin.mp3”), “audio/*”); // 设置数据和数据类型&#xff0c;将启动音频播放器&#xff08;vedio&#xff09;
通过指定意图过滤器的data-type,设置指定类型文件打开方式:
Another common configuration is filters with a scheme and a data type. For example, a element like the following tells Android that the component can retrieve video data from the network in order to perform the action:
…
启动应用程序意图:
PackageManager manager&#61;getPackageManager();
// 可以获取到指定包名的应用程序的启动的intent对象
Intent launchIntentForPackage &#61; manager.getLaunchIntentForPackage(appInfo.getPackageName());
if(launchIntentForPackage!&#61;null){
startActivity(launchIntentForPackage);
}else{
Toast.makeText(getApplicationContext(), “系统底层应用不能启动”, 0).show();
}
卸载程序意图:
String packageQualifyName &#61; appInfoNowClick.getPackageQualifyName();
//卸载程序意图
Intent unInstallIntent &#61; new Intent();
unInstallIntent.setAction(“android.intent.action.DELETE”);
unInstallIntent.addCategory(“android.intent.category.DEFAULT”);
unInstallIntent.setData(Uri.parse(“package:” &#43; packageQualifyName));
startActivityForResult(unInstallIntent, 0);
安装程序意图:
* 安装 打开系统的packageInstallerActivity
*/
protected void installApk() {
//
//
//
//
//
//
//
Intent intent &#61; new Intent();
intent.setAction(“android.intent.action.VIEW”);
intent.addCategory(“android.intent.category.DEFAULT”);
intent.setDataAndType(
Uri.fromFile(new File(“/mnt/sdcard/mobilesafe2.0.apk”)),
“application/vnd.android.package-archive”);
startActivity(intent);
}
//自定义android Intent类&#xff0c;
//可用于获取打开以下文件的intent
//PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO//错误示例:
//这个不行&#xff0c;可能是因为PDF.apk程序没有权限访问其它APK里的asset资源文件,又或者是路径写错?
//Intent it &#61; getPdfFileIntent("file:///android_asset/helphelp.pdf");//下面这些都OK
Intent it &#61; getHtmlFileIntent("/mnt/sdcard/tutorial.html");//SD卡主目录
//Intent it &#61; getHtmlFileIntent("/sdcard/tutorial.html");//SD卡主目录,这样也可以
//Intent it &#61; getHtmlFileIntent("/system/etc/tutorial.html");//系统内部的etc目录
//Intent it &#61; getPdfFileIntent("/system/etc/helphelp.pdf");
//Intent it &#61; getWordFileIntent("/system/etc/help.doc");
//Intent it &#61; getExcelFileIntent("/mnt/sdcard/Book1.xls")
//Intent it &#61; getPptFileIntent("/mnt/sdcard/download/Android_PPT.ppt");//SD卡的download目录下
//Intent it &#61; getVideoFileIntent("/mnt/sdcard/ice.avi");
//Intent it &#61; getAudioFileIntent("/mnt/sdcard/ren.mp3");
//Intent it &#61; getImageFileIntent("/mnt/sdcard/images/001041580.jpg");
//Intent it &#61; getTextFileIntent("/mnt/sdcard/hello.txt",false);
startActivity( it );
public class MyIntent {//android获取一个用于打开HTML文件的intentpublic static Intent getHtmlFileIntent( String param ) {Uri uri &#61; Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(param ).build();Intent intent &#61; new Intent("android.intent.action.VIEW");intent.setDataAndType(uri, "text/html");return intent;}//android获取一个用于打开图片文件的intentpublic static Intent getImageFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "image/*");return intent;}//android获取一个用于打开PDF文件的intentpublic static Intent getPdfFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "application/pdf");return intent;}//android获取一个用于打开文本文件的intentpublic static Intent getTextFileIntent( String param, boolean paramBoolean) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);if (paramBoolean) {Uri uri1 &#61; Uri.parse(param );intent.setDataAndType(uri1, "text/plain");} else {Uri uri2 &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri2, "text/plain");}return intent;}//android获取一个用于打开音频文件的intentpublic static Intent getAudioFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);intent.putExtra("oneshot", 0);intent.putExtra("configchange", 0);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "audio/*");return intent;}//android获取一个用于打开视频文件的intentpublic static Intent getVideoFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);intent.putExtra("oneshot", 0);intent.putExtra("configchange", 0);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "video/*");return intent;}//android获取一个用于打开CHM文件的intentpublic static Intent getChmFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "application/x-chm");return intent;}//android获取一个用于打开Word文件的intentpublic static Intent getWordFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "application/msword");return intent;}//android获取一个用于打开Excel文件的intentpublic static Intent getExcelFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "application/vnd.ms-excel");return intent;}//android获取一个用于打开PPT文件的intentpublic static Intent getPptFileIntent( String param ) {Intent intent &#61; new Intent("android.intent.action.VIEW");intent.addCategory("android.intent.category.DEFAULT");intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);Uri uri &#61; Uri.fromFile(new File(param ));intent.setDataAndType(uri, "application/vnd.ms-powerpoint");return intent;}
}