`
kerlubasola
  • 浏览: 678744 次
文章分类
社区版块
存档分类
最新评论

android 常用intent

 
阅读更多

到打电话界面

Java代码收藏代码
  1. uri=Uri.parse("tel:"+number);
  2. intent=newIntent(Intent.ACTION_CALL,uri);
  3. startActivity(intent);

到发送短信页面

Java代码收藏代码
  1. uri=Uri.parse("smsto:"+要发送短信的对方的number);
  2. intent=newIntent(Intent.ACTION_SENDTO,uri);
  3. startActivity(intent);

另一种

Java代码收藏代码
  1. mIntent=newIntent(Intent.ACTION_VIEW);
  2. mIntent.putExtra("address",c.getString(c.getColumnIndex(column)));
  3. mIntent.setType("vnd.android-dir/mms-sms");
  4. startActivity(mIntent);

添加到短信收件箱

Java代码收藏代码
  1. ContentValuescv=newContentValues();
  2. cv.put("type","1");
  3. cv.put("address","短信地址");
  4. cv.put("body","短信内容");
  5. getContentResolver().insert(Uri.parse("content://sms/inbox"),cv);

从sim卡或者联系人中查询

Java代码收藏代码
  1. Cursorcursor;
  2. Uriuri;
  3. if(type==1){
  4. Intentintent=newIntent();
  5. intent.setData(Uri.parse("content://icc/adn"));
  6. uri=intent.getData();
  7. }else
  8. uri=People.CONTENT_URI;
  9. cursor=activity.getContentResolver().query(uri,null,null,null,null);
Java代码收藏代码
  1. while(cursor.moveToNext()){
  2. intpeopleId=cursor.getColumnIndex(People._ID);
  3. intnameId=cursor.getColumnIndex(People.NAME);
  4. intphoneId=cursor.getColumnIndex(People.NUMBER);}

删除

Java代码收藏代码
  1. uri=ContentUris.withAppendedId(People.CONTENT_URI,联系人id);
  2. intcount=activity.getContentResolver().delete(uri,null,null);

添加到联系人:

Java代码收藏代码
  1. ContentValuescv=newContentValues();
  2. ArrayList<ContentProviderOperation>operationList=newArrayList<ContentProviderOperation>();
  3. ContentProviderOperation.Builderbuilder=ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
  4. builder.withValues(cv);
  5. operationList.add(builder.build());
  6. builder=ContentProviderOperation.newInsert(Data.CONTENT_URI);
  7. builder.withValueBackReference(StructuredName.RAW_CONTACT_ID,0);
  8. builder.withValue(Data.MIMETYPE,StructuredName.CONTENT_ITEM_TYPE);
  9. builder.withValue(StructuredName.DISPLAY_NAME,"自定义联系人名");
  10. operationList.add(builder.build());
  11. builder=ContentProviderOperation.newInsert(Data.CONTENT_URI);
  12. builder.withValueBackReference(Phone.RAW_CONTACT_ID,0);
  13. builder.withValue(Data.MIMETYPE,Phone.CONTENT_ITEM_TYPE);
  14. builder.withValue(Phone.NUMBER,"联系人的phonenumber");
  15. builder.withValue(Data.IS_PRIMARY,1);
  16. operationList.add(builder.build());
  17. try{
  18. getContentResolver().applyBatch(ContactsContract.AUTHORITY,operationList);
  19. }catch(RemoteExceptione){
  20. e.printStackTrace();
  21. }catch(OperationApplicationExceptione){
  22. e.printStackTrace();
  23. }

动作 Uri 说明

Intent.ACTION_VIEW

geo:latitude,longtitude

打开地图应用程序并显示指定的纬度和经度

Intent.ACTION_VIEW

geo:0,0?q=street+address

打开地图应用程序并显示指定的地址

Intent.ACTION_CALL

tel:phone_number

打开电话应用程序并拨打指定的电话号码

Intent.ACTION_DIAL

tel:phone_number

打开电话应用程序并拨下指定电话(但不打出)

Intent.ACTION_DIAL

voicemail:

打开电话应用程序并拨下语音信箱号码(但不打出)

Intent.ACTION_VIEW

http://web_address

打开浏览器应用程序并显示指定的URL

Intent.ACTION_VIEW

https://web_address

打开浏览器应用程序并显示指定的URL

Intent.ACTION_WEB_SEARCH

plain_text

打开浏览器应用程序并使用Google搜索引擎

发送邮件:

Java代码收藏代码
  1. Uriuri=Uri.parse("mailto:terryyhl@gmail.com");
  2. IntentMymailIntent=newIntent(Intent.ACTION_SEND,uri);
  3. startActivity(MymailIntent);

方法二:

Java代码收藏代码
  1. Intenttestintent=newIntent(Intent.ACTION_SEND);
  2. String[]tos={"terryyhl@gmail.com"};
  3. String[]ccs={"kalaicheng@hotmail.com"};
  4. testintent.putExtra(Intent.EXTRA_EMAIL,tos);
  5. testintent.putExtra(Intent.EXTRA_CC,ccs);
  6. testintent.putExtra(Intent.EXTRA_TEXT,"这是内容");
  7. testintent.putExtra(Intent.EXTRA_SUBJECT,"这是标题");
  8. testintent.setType("message/rfc822");
  9. startActivity(Intent.createChooser(testintent,"发送"));

播放多媒体:

Java代码收藏代码
  1. //播放多媒体
  2. Intentit=newIntent(Intent.ACTION_VIEW);
  3. Uriuri=Uri.parse("file:///sdcard/song.mp3");it.setDataAndType(uri,"audio/mp3");
  4. startActivity(it);
  5. Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
  6. Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics