Android 用Intent调用系统中经常被用到的组件

Uri uri= Uri. parse ( "http://kuikui.javaeye.com" );

returnIt = new Intent(Intent. ACTION_VIEW , uri );

2,地图

Uri mapUri = Uri. parse ( "geo:38.899533,-77.036476" );

returnIt = new Intent(Intent. ACTION_VIEW , mapUri);

3,调拨打电话界面

Uri telUri = Uri. parse ( "tel:100861" );

returnIt = new Intent(Intent. ACTION_DIAL , telUri);

4,直接拨打电话

Uri callUri = Uri. parse ( "tel:100861" );

returnIt = new Intent(Intent. ACTION_CALL , callUri);

5,卸载

Uri uninstallUri = Uri. fromParts ( "package" , " xxx " , null );

returnIt = new Intent(Intent. ACTION_DELETE , uninstallUri);

6,安装

Uri installUri = Uri. fromParts ( "package" , " xxx " , null );

returnIt = new Intent(Intent. ACTION_PACKAGE_ADDED , installUri);

7,播放

Uri playUri = Uri. parse ( "file:///sdcard/download/everything.mp3" );

returnIt = new Intent(Intent. ACTION_VIEW , playUri);

8,调用发邮件

Uri emailUri = Uri. parse ( "mailto:shenrenkui@gmail.com" );

returnIt = new Intent(Intent. ACTION_SENDTO , emailUri);

9,发邮件

returnIt = new Intent(Intent. ACTION_SEND );

String[] tos = { "shenrenkui@gmail.com" };

String[] ccs = { "shenrenkui@gmail.com" };

returnIt .putExtra(Intent. EXTRA_EMAIL , tos);

returnIt .putExtra(Intent. EXTRA_CC , ccs);

returnIt .putExtra(Intent. EXTRA_TEXT , "body" );

returnIt .putExtra(Intent. EXTRA_SUBJECT , "subject" );

returnIt .setType( "message/rfc882" );//真机上使用这行

//returnIt.setType("text/plain");//模拟器请使用这行


Intent. createChooser ( returnIt , "Choose Email Client" );

10,发短信

Uri smsUri = Uri. parse ( "tel:100861" );

returnIt = new Intent(Intent. ACTION_VIEW , smsUri);

returnIt.putExtra( "sms_body" , "shenrenkui" );

returnIt.setType( "vnd.Android-dir/mms-sms" );

11,直接发邮件

Uri smsToUri = Uri. parse ( "smsto://100861" );

returnIt = new Intent(Intent. ACTION_SENDTO , smsToUri);

returnIt.putExtra( "sms_body" , "shenrenkui" );

12,发彩信

Ur i mmsUri = Uri. parse ( "content://media/external/images/media/23" );

returnIt = new Intent(Intent. ACTION_SEND );

returnIt.putExtra( "sms_body" , "shenrenkui" );

returnIt.putExtra(Intent. EXTRA_STREAM , mmsUri);

returnIt.setType( "image/png" )


相当一部分来自文档,希望能有朋友继续完善此贴,以作搜藏。


安装指定apk  public void setupAPK(String apkname){ String fileName = Environment.getExternalStorageDirectory() + "/" + apkname; Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); mService.startActivity(intent); }


进入联系人页面 1.Intent intent = new Intent(); 2.intent.setAction(Intent.ACTION_VIEW); 3.intent.setData(People.CONTENT_URI); 4.startActivity(intent); 查看指定联系人 1.Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, info.id);//info.id联系人ID 2.Intent intent = new Intent(); 3.intent.setAction(Intent.ACTION_VIEW); 4.intent.setData(personUri); 5.startActivity(intent);

显示网页:

1. Uri uri = Uri.parse("http://www.google.com");
2. Intent it = new Intent(Intent.ACTION_VIEW,uri);
3. startActivity(it);

显示地图:

1. Uri uri = Uri.parse("geo:38.899533,-77.036476");
2. Intent it = new Intent(Intent.Action_VIEW,uri);
3. startActivity(it);

路径规划:

1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
2. Intent it = new Intent(Intent.ACTION_VIEW,URI);
3. startActivity(it);

拨打电话:
调用拨号程序

1. Uri uri = Uri.parse("tel:xxxxxx");
2. Intent it = new Intent(Intent.ACTION_DIAL, uri);  
3. startActivity(it);  

1. Uri uri = Uri.parse("tel.xxxxxx");
2. Intent it =new Intent(Intent.ACTION_CALL,uri);
3. 要使用这个必须在配置文件中加入<uses-permission />

发送SMS/MMS
调用发送短信的程序

1. Intent it = new Intent(Intent.ACTION_VIEW);
2. it.putExtra("sms_body", "The SMS text");
3. it.setType("vnd.android-dir/mms-sms");
4. startActivity(it);  

发送短信

1. Uri uri = Uri.parse("smsto:0800000123");
2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
3. it.putExtra("sms_body", "The SMS text");
4. startActivity(it);  

发送彩信

1. Uri uri = Uri.parse("content://media/external/images/media/23");
2. Intent it = new Intent(Intent.ACTION_SEND);
3. it.putExtra("sms_body", "some text");
4. it.putExtra(Intent.EXTRA_STREAM, uri);
5. it.setType("image/png");
6. startActivity(it);

发送Email

1.
2. Uri uri = Uri.parse("mailto:xxx@abc.com");
3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);
4. startActivity(it);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwdgjg.html