您的位置:首页 > 移动开发 > Android开发

android Intent用法实例(1)

2013-11-21 16:02 387 查看


ACTION_MAIN  应用程序入口

ACTION_VIEW  显示指定数据

ACTION_DIAL  显示拨号面板
ACTION_CALL  直接向指定用户打电话
ACTION_SENDTO   向其他人发送消息
ACTION_SEND        向其他人发送数据
ACTION_DELETE 删除数据


ACTION_MAIN   应用程序入口

[b]返回桌面[/b]


Intent it = new Intent(Intent.ACTION_MAIN);
it.addCategory(Intent.CATEGORY_HOME);
startActivity(it);


[b]ACTION_VIEW   显示指定数据
[/b]

显示网页

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


播放多媒体

      
Uri uri = Uri.parse("file:///sdcard/song.mp3");
Intent it = new Intent(Intent.ACTION_VIEW);
it.setDataAndType(uri, "video/mp3");
startActivity(it);


ACTION_DIAL  显示拨号面板

ACTION_CALL  直接向指定用户打电话

打电话  

//叫出拨号程序
Uri uri = Uri.parse("tel:10086");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
//直接打电话出去
Uri uri = Uri.parse("tel:10086");
Intent it = new Intent(Intent.ACTION_CALL, uri);
startActivity(it);
//权限
//<uses-permission id="android.permission.CALL_PHONE" />


ACTION_SENDTO   向其他人发送消息

ACTION_SEND        向其他人发送数据

[b]发送SMS/MMS[/b]

//调用短信程序
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://10086");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
//发送 MMS
Uri uri = Uri.parse("content://media/external/images/media/23");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "some text");
//uri 可以是你从手机相册中得到图片的地址,取手机相册图片可以参考Intent.ACTION_PICK或Intent.ACTION_GET_CONTENT
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/*");
startActivity(it);


 

传送 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);
//我在测试时发现 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");
//把地址改成你从手机里取到的地址(data.getData()一个URI)
it.putExtra(Intent.EXTRA_STREAM, data.getData());
it.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));


ACTION_DELETE 删除数据

[b]Uninstall 应用程序
[/b]
Uri uri = Uri.fromParts("package", "包名", null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android intent