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

Android跳转到系统联系人及拨号或短信界面

程序员文章站 2024-02-28 17:10:52
现在开发中的功能需要直接跳转到拨号、联系人、短信界面等等,查找了很多资料,自己整理了一下。  1、跳转到拨号界面,代码如下:  1)直接...

现在开发中的功能需要直接跳转到拨号、联系人、短信界面等等,查找了很多资料,自己整理了一下。 

1、跳转到拨号界面,代码如下: 

1)直接拨打 

intent intentphone = new intent(intent.action_call, uri.parse("tel:" + phonenumber)); 
startactivity(intentphone);

2)跳转到拨号界面 

intent intent = newintent(intent.action_dial,uri.parse("tel:" + phonenumber)); 
intent.setflags(intent.flag_activity_new_task); 
startactivity(intent); 

2、跳转到联系人页面,使用一下代码: 

intent intentphone = new intent(intent.action_call, uri.parse("tel:" + phonenumber)); 
startactivity(intentphone); 

以下内容为转载: 

android开发之intent跳转到系统应用中的拨号界面、联系人界面、短信界面 现在开发中的功能需要直接跳转到拨号、联系人、短信界面等等,查找了很多资料,自己整理了一下。 

//安装已经存在的apk 
string filepath="mnt/sdcard/abc.apk"; 
intent intent = new intent(intent.action_view); 
intent.setdataandtype(uri.parse("file://" + filepath), 
    "application/vnd.android.package-archive"); 
startactivity(intent);//直接跳到安装页面,但是还要点击按钮确定安装,还是取消安装 
//卸载某应用 
string packagename="org.adw.launcher2" 
uri packageuri = uri.parse("package:"+packagename);//包名,指定该应用 
intent uninstallintent = new intent(intent.action_delete, packageuri); 
startactivity(uninstallintent); 
//查看某一应用程序的信息 
 uri uri=uri.parse("package:"+packagename);//包名,指定该应用 
intent intent=new intent("android.settings.application_details_settings", uri); 
startactivity(intent);  
2.浏览网页某一具体网址 
 uri uri = uri.parse("http://xxxxxxxxxxxxxxxxxxxxxxxx");  
 intent intent  = new intent(intent.action_view,uri); 
//加下面这句话就是启动系统自带的浏览器打开上面的网址, 不加下面一句话, 如果你有多个浏览器,就会弹出让你选择某一浏览器, 然后改浏览器就会打开该网址............... 
intent.setclassname("com.android.browser", "com.android.browser.browseractivity");  
 startactivity(intent); 
//系统 设置 界面 
intent intent=new intent(); 
 intent.setclassname("com.android.settings","com.android.settings.settings"); 
startactivity(intent);  
//回到桌面吗 
intent intent = new intent(intent.action_main); 
intent.addcategory(intent.category_home); 
startactivity(intent); 
//系统  拨号  界面 
intent intent= new intent(intent.action_dial);  
intent.setclassname("com.android.contacts","com.android.contacts.dialtactsactivity"); 
startactivity(intent);    
//系统 通话记录 界面 
intent intent =new intent();  
intent.setaction("android.intent.action.call_button");  
startactivity(intent); 
//拨号 
 uri uri = uri.parse("tel:xxxxxx");   
 intent intent = new intent(intent.action_dial, uri);    
 startactivity(intent);  
//启动拨号界面,指定了类名 包名  是系统的拨号界面  dialtactsactivity 
intent intent= new intent("android.intent.action.dial");  
 intent.setclassname("com.android.contacts","com.android.contacts.dialtactsactivity"); 
startactivity(intent);  
//系统 联系人 界面  peopleactivity 
intent intent001 = new intent(); 
intent001.setclassname("com.android.contacts","com.android.contacts.activities.peopleactivity"); 
startactivity(intent001);  
//系统 搜索  界面  searchactivity 
intent intent002=new intent(); 
intent002.setclassname("com.android.quicksearchbox", "com.android.quicksearchbox.searchactivity"); 
startactivity(intent002); 
//启动短信收件箱的界面,指定了包名,类名 
 intent intent4 = new intent(); 
intent4.setclassname("com.android.mms","com.android.mms.ui.conversationlist"); 
startactivity(intent4); 
 //启动联系人界面,不好 
intent intent = new intent();  
 intent.setaction(intent.action_pick);  
 intent.setdata(contacts.people.content_uri);  
 startactivity(intent); 
插入联系人 
intent intent=newintent(intent.action_edit,uri.parse("content://com.android.contacts/contacts/"+"1"));  
startactivity(intent); 
到联系人列表界面 
intent intent = new intent(intent.action_insert_or_edit);  
intent.settype("vnd.android.cursor.item/person");  
intent.settype("vnd.android.cursor.item/contact");  
intent.settype("vnd.android.cursor.item/raw_contact");  
intent.putextra(android.provider.contactscontract.intents.insert.name, name);  
intent.putextra(android.provider.contactscontract.intents.insert.company,company);  
intent.putextra(android.provider.contactscontract.intents.insert.phone, tel);  
intent.putextra(android.provider.contactscontract.intents.insert.phone_type, 3); 
//启动短信收件箱的界面,指定了包名,类名 
intent intent = new intent(); 
intent.setclassname("com.android.mms","com.android.mms.ui.conversationlist"); 
startactivity(intent); 
//启动编辑短信的界面 
intent intent = new intent(intent.action_view);  
intent.settype("vnd.android-dir/mms-sms");  
 // intent.setdata(uri.parse("content://mms-sms/conversations/"));//此为号码 
startactivity(intent); 
--------------------------------------------------------------- 
2--------------------------------------------------------------- 
--------------------------------------------------------------- 
现在开发中的功能需要直接跳转到拨号、联系人、短信界面等等,查找了很多资料,自己整理了一下。 
 首先,我们先看拨号界面,代码如下: 
 intent intent =new intent();  
 intent.setaction("android.intent.action.call_button");  
 startactivity(intent); 
和 
uri uri = uri.parse("tel:xxxxxx");   
intent intent = new intent(intent.action_dial, uri);    
startactivity(intent);  
两者都行   
但是如果是跳转到应用,使用一下代码: 
intent intent= new intent("android.intent.action.dial");   
intent.setclassname("com.android.contacts","com.android.contacts.dialtactsactivity"); 
到通话记录界面: 
intent intent=new intent();  
intent.setaction(intent.action_call_button);  
startactivity(intent);  
到联系人界面: 
intent intent = new intent();   
intent.setaction(intent.action_view);   
intent.setdata(contacts.people.content_uri);   
startactivity(intent); 
到应用: 
intent intent= new intent("com.android.contacts.action.list_strequent");   
intent.setclassname("com.android.contacts","com.android.contacts.dialtactsactivity"); 
调用联系人界面: 
intent intent = new intent();   
intent.setaction(intent.action_pick);   
intent.setdata(contacts.people.content_uri);   
startactivity(intent);   
插入联系人 
intent intent=new intent(intent.action_edit,uri.parse("content://com.android.contacts/contacts/"+"1"));  
startactivity(intent);  
到联系人列表界面   
intent intent = new intent(intent.action_insert_or_edit);  
intent.settype("vnd.android.cursor.item/person");  
intent.settype("vnd.android.cursor.item/contact");  
intent.settype("vnd.android.cursor.item/raw_contact");  
intent.putextra(android.provider.contactscontract.intents.insert.name, name);  
intent.putextra(android.provider.contactscontract.intents.insert.company,company);  
intent.putextra(android.provider.contactscontract.intents.insert.phone, tel);   
intent.putextra(android.provider.contactscontract.intents.insert.phone_type, 3); 
复制代码 
到短信界面: 
intent intent = new intent(intent.action_view);  
intent.settype("vnd.android-dir/mms-sms");  
//intent.setdata(uri.parse("content://mms-sms/conversations/"));//此为号码  
startactivity(intent);  
到应用: 
intent intent = new intent("android.intent.action.conversation");  
startactivity(intent);  
以下是在网上找到的其他方法: 
1.从google搜索内容 
intent intent = new intent();   
intent.setaction(intent.action_web_search);   
intent.putextra(searchmanager.query,"searchstring")   
startactivity(intent);   
2.浏览网页 
uri uri = uri.parse("http://www.google.com");   
intent it  = new intent(intent.action_view,uri);   
startactivity(it); 
3.显示地图 
uri uri = uri.parse("geo:38.899533,-77.036476");   
intent it = new intent(intent.action_view,uri);   
startactivity(it);   
4.路径规划 
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);  
5.拨打电话 
uri uri = uri.parse("tel:xxxxxx");   
intent it = new intent(intent.action_dial, uri);    
startactivity(it);  
和 
uri = uri.parse("tel:"+number);   
intent = new intent(intent.action_call,uri);   
startactivity(intent);  
其中不同自己试验一下就知道了。  
6.调用发短信的程序 
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.parse("smsto:"+要发送短信的对方的number);   
intent = new intent(intent.action_sendto,uri);   
startactivity(intent);   
和 
mintent = new intent(intent.action_view);   
mintent.putextra("address", c.getstring(c.getcolumnindex(column)));   
mintent.settype("vnd.android-dir/mms-sms");   
startactivity(mintent);   
7.发送短信 
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);<span style="font-family:simsun;white-space: normal; background-color: rgb(255, 255, 255);"> </span>  
8.发送彩信 
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);   
9.发送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"));   
10.播放多媒体   
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);   
11.uninstall apk 
uri uri = uri.fromparts("package", strpackagename, null);    
intent it = new intent(intent.action_delete, uri);    
startactivity(it);  
12.install apk 
uri installuri = uri.fromparts("package", "xxx", null);   
returnit = new intent(intent.action_package_added, installuri);  
13. 打开照相机 
<1>intent i = new intent(intent.action_camera_button, null);   
     this.sendbroadcast(i);   
<2>long datetaken = system.currenttimemillis();   
     string name = createname(datetaken) + ".jpg";   
     filename = folder + name;   
     contentvalues values = 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 = getcontentresolver().insert(   
     mediastore.images.media.external_content_uri, values);   
     intent inttphoto = new intent(mediastore.action_image_capture);   
     inttphoto.putextra(mediastore.extra_output, photouri);   
     startactivityforresult(inttphoto, 10); 
14.从gallery选取图片 
    intent i = new intent();   
    i.settype("image/*");   
    i.setaction(intent.action_get_content);   
    startactivityforresult(i, 11);   
15. 打开录音机 
intent mi = new intent(media.record_sound_action);   
startactivity(mi); 
16.显示应用详细列表 
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<span style="font-family:simsun;white-space: normal; background-color: rgb(255, 255, 255);">  </span> 
刚才找app id未果,结果发现用package name也可以 uri uri = uri.parse("market://details?id=<packagename>");
这个简单多了  
17寻找应用 
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<span style="font-family:simsun;white-space: normal; background-color: rgb(255, 255, 255);">   </span>  
18打开联系人列表 
     intent i = new intent();   
     i.setaction(intent.action_get_content);   
     i.settype("vnd.android.cursor.item/phone");   
     startactivityforresult(i, request_text); 
     uri uri = uri.parse("content://contacts/people");   
     intent it = new intent(intent.action_pick, uri);   
     startactivityforresult(it, request_text);  
19 打开另一程序 
intent i = new intent();   
componentname cn = new componentname("com.yellowbook.android2",  "com.yellowbook.android2.androidsearch");   
i.setcomponent(cn);   
i.setaction("android.intent.action.main");   
startactivityforresult(i, result_ok);  
20 添加到短信收件箱 
contentvalues cv = new contentvalues();    
cv.put("type", "1");   
cv.put("address","短信地址");  
cv.put("body", "短信内容");   
getcontentresolver().insert(uri.parse("content://sms/inbox"), cv); 
21 从sim卡或者联系人中查询 
cursor cursor;  
uri uri;  
if (type == 1) {  
intent intent = new intent();  
intent.setdata(uri.parse("content://icc/adn"));  
uri = intent.getdata();  
} else  
uri = people.content_uri;  
cursor = activity.getcontentresolver().query(uri, null, null, null, null);  
while (cursor.movetonext()) {  
int peopleid = cursor.getcolumnindex(people._id); 
int nameid = cursor.getcolumnindex(people.name);  
int phoneid = cursor.getcolumnindex(people.number);} 
查看某个联系人,当然这里是action_view,如果为选择并返回action改为action_pick,当然处理intent时返回需要用到 startactivityforresult  
uri personuri = contenturis.withappendedid(people.content_uri, id);//最后的id参数为联系人provider中的数据库baseid,即哪一行  
intent intent = new intent(); intent.setaction(intent.action_view); intent.setdata(personuri); startactivity(intent);  
22 删除 
uri = contenturis.withappendedid(people.content_uri, 联系人id);  
int count = activity.getcontentresolver().delete(uri, null, null 
23 添加到联系人: 
contentvalues cv = new contentvalues();  
arraylist<contentprovideroperation> operationlist = new arraylist<contentprovideroperation>();  
contentprovideroperation.builder builder = contentprovideroperation.newinsert(rawcontacts.content_uri);  
builder.withvalues(cv);  
operationlist.add(builder.build());  
builder = contentprovideroperation.newinsert(data.content_uri);  
builder.withvaluebackreference(structuredname.raw_contact_id, 0);  
builder.withvalue(data.mimetype, structuredname.content_item_type);  
builder.withvalue(structuredname.display_name, "自定义联系人名");  
operationlist.add(builder.build());  
builder = contentprovideroperation.newinsert(data.content_uri);  
builder.withvaluebackreference(phone.raw_contact_id, 0);  
builder.withvalue(data.mimetype, phone.content_item_type);  
builder.withvalue(phone.number, "联系人的phonenumber");  
builder.withvalue(data.is_primary, 1);  
operationlist.add(builder.build());  
try {  
     getcontentresolver().applybatch(contactscontract.authority, operationlist);  
    } catch (remoteexception e) {  
      e.printstacktrace();  
    } catch (operationapplicationexception e) {  
     e.printstacktrace();  
   }  
23 选择一个图片 
intent intent = new intent(intent.action_get_content);   
intent.addcategory(intent.category_openable);  
intent.settype("image/*");  
startactivityforresult(intent, 0); 
24 调用android设备的照相机,并设置拍照后存放位置 
intent intent = new intent(mediastore.action_image_capture);  
intent.putextra(mediastore.extra_output, uri.fromfile(new file(environment .getexternalstoragedirectory().getabsolutepath()+"/cwj", android123 + ".jpg"))); //存放位置为sdcard卡上cwj文件夹,文件名为android123.jpg格式  
startactivityforresult(intent, 0);  
25 在market上搜索指定package name,比如搜索com.android123.cwj的写法如下 
uri uri = uri.parse("market://search?q=pname:com.android123.cwj");   
intent intent = new intent(intent.action_view, uri); startactivity(intent); 
26获取文件信息,并使用相对应软件打开 
private void openfile(file f)   
{   
  intent intent = new intent();   
  intent.addflags(intent.flag_activity_new_task);   
  intent.setaction(android.content.intent.action_view);   
  string type = getmimetype(f);   
  intent.setdataandtype(uri.fromfile(f), type);   
  startactivity(intent);   
}   
private string getmimetype(file f){   
  string end = f .getname() .substring(f.getname().lastindexof(".") + 1,f.getname().length()).tolowercase();   
 string type = "";   
 if (end.equals("mp3") || end.equals("aac") || end.equals("aac")|| end.equals("amr") || end.equals("mpeg")|| end.equals("mp4"))   
 {   
   type = "audio";   
 } 
 else if (end.equals("jpg") || end.equals("gif")|| end.equals("png") || end.equals("jpeg"))   
 {  
   type = "image";   
  } 
 else   
 {   
   type = "*";   
 }   
   type += "/*";    
   return type;   
}  
--------------------------------------------------------------- 
--------------------------------------------------------------- 
--------------------------------------------------------------- 
现在开发中的功能需要直接跳转到拨号、联系人、短信界面等等,查找了很多资料,自己整理了一下。 
1、跳转到拨号界面,代码如下: 
1)直接拨打 
intent intentphone = new intent(intent.action_call, uri.parse("tel:" + phonenumber)); 
startactivity(intentphone); 
2)跳转到拨号界面 
intent intent = newintent(intent.action_dial,uri.parse("tel:" + phonenumber)); 
intent.setflags(intent.flag_activity_new_task); 
startactivity(intent); 
2、跳转到联系人页面,使用一下代码: 
intent intentphone = new intent(intent.action_call, uri.parse("tel:" + phonenumber)); 
startactivity(intentphone); 
--------------------------------------------------------------- 
3--------------------------------------------------------------- 
---------------------------------------------------------------