欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android Intent调用 Uri的方法总结

程序员文章站 2023-12-15 16:14:34
android intent调用 uri的方法总结 //调用浏览器 uri uri = uri.parse(""); intent it = new i...

android intent调用 uri的方法总结

//调用浏览器

uri uri = uri.parse(""); 
intent it = new intent(intent.action_view,uri); 
startactivity(it); 

//显示某个坐标在地图上

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=d&saddr=startlat%20startlng&daddr=endlat%20endlng&hl=en"); 
intent it = new intent(intent.action_view,uri); 
startactivity(it); 

//拨打电话

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); 

需要添加 <uses-permission id="android.permission.call_phone" /> 这个权限到androidmanifest.xml

//发送短信或彩信

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", "cwj");  
startactivity(it);  

//发送彩信

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);  

//发送邮件

uri uri = uri.parse("mailto:android123@163.com"); 
intent it = new intent(intent.action_sendto, uri); 
startactivity(it); 
intent it = new intent(intent.action_send);  
it.putextra(intent.extra_email, android123@163.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_view); 
uri uri = uri.parse("file:///sdcard/cwj.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);  

//卸载apk

uri uri = uri.fromparts("package", strpackagename, null);  
intent it = new intent(intent.action_delete, uri);  
startactivity(it); 

//卸载apk 2

uri uninstalluri = uri.fromparts("package", "xxx", null); 
returnit = new intent(intent.action_delete, uninstalluri); 

//安装apk

uri installuri = uri.fromparts("package", "xxx", null); 
returnit = new intent(intent.action_package_added, installuri); 

//播放音乐

uri playuri = uri.parse("file:///sdcard/download/sth.mp3"); 
returnit = new intent(intent.action_view, playuri); 

//发送附件

intent it = new intent(intent.action_send);  
it.putextra(intent.extra_subject, "the email subject text");  
it.putextra(intent.extra_stream, "file:///sdcard/cwj.mp3");  
sendintent.settype("audio/mp3");  
startactivity(intent.createchooser(it, "choose email client")); 
 

//market上某个应用信,pkg_name就是应用的packagename 

uri uri = uri.parse("market://search?q=pname:pkg_name");  
intent it = new intent(intent.action_view, uri);  
startactivity(it);  

//market上某个应用信息,app_id可以通过www网站看下

uri uri = uri.parse("market://details?id=app_id");  
intent it = new intent(intent.action_view, uri);  
startactivity(it);  

//调用搜索

intent intent = new intent(); 
intent.setaction(intent.action_web_search); 
intent.putextra(searchmanager.query,"android123") 
startactivity(intent); 

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:

下一篇: