android 常用intent
16lz
2021-12-04
android联系人、短信、邮件url总结
- 博客分类:
- android
到打电话界面
Java代码- uri=Uri.parse("tel:"+number);
- intent=newIntent(Intent.ACTION_CALL,uri);
- startActivity(intent);
到发送短信页面
Java代码- uri=Uri.parse("smsto:"+要发送短信的对方的number);
- intent=newIntent(Intent.ACTION_SENDTO,uri);
- startActivity(intent);
另一种
Java代码
- mIntent=newIntent(Intent.ACTION_VIEW);
- mIntent.putExtra("address",c.getString(c.getColumnIndex(column)));
- mIntent.setType("vnd.android-dir/mms-sms");
- startActivity(mIntent);
添加到短信收件箱
Java代码
- ContentValuescv=newContentValues();
- cv.put("type","1");
- cv.put("address","短信地址");
- cv.put("body","短信内容");
- getContentResolver().insert(Uri.parse("content://sms/inbox"),cv);
从sim卡或者联系人中查询
Java代码- Cursorcursor;
- Uriuri;
- if(type==1){
- Intentintent=newIntent();
- 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()){
- intpeopleId=cursor.getColumnIndex(People._ID);
- intnameId=cursor.getColumnIndex(People.NAME);
- intphoneId=cursor.getColumnIndex(People.NUMBER);}
删除
Java代码- uri=ContentUris.withAppendedId(People.CONTENT_URI,联系人id);
- intcount=activity.getContentResolver().delete(uri,null,null);
添加到联系人:
Java代码- ContentValuescv=newContentValues();
- ArrayList<ContentProviderOperation>operationList=newArrayList<ContentProviderOperation>();
- ContentProviderOperation.Builderbuilder=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(RemoteExceptione){
- e.printStackTrace();
- }catch(OperationApplicationExceptione){
- e.printStackTrace();
- }
动作 | 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代码
- Uriuri=Uri.parse("mailto:terryyhl@gmail.com");
- IntentMymailIntent=newIntent(Intent.ACTION_SEND,uri);
- startActivity(MymailIntent);
方法二:
Java代码
- Intenttestintent=newIntent(Intent.ACTION_SEND);
- String[]tos={"terryyhl@gmail.com"};
- String[]ccs={"kalaicheng@hotmail.com"};
- testintent.putExtra(Intent.EXTRA_EMAIL,tos);
- testintent.putExtra(Intent.EXTRA_CC,ccs);
- testintent.putExtra(Intent.EXTRA_TEXT,"这是内容");
- testintent.putExtra(Intent.EXTRA_SUBJECT,"这是标题");
- testintent.setType("message/rfc822");
- startActivity(Intent.createChooser(testintent,"发送"));
播放多媒体:
Java代码
- //播放多媒体
- Intentit=newIntent(Intent.ACTION_VIEW);
- Uriuri=Uri.parse("file:///sdcard/song.mp3");it.setDataAndType(uri,"audio/mp3");
- startActivity(it);
- Uriuri=Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
- Intentit=newIntent(Intent.ACTION_VIEW,uri);startActivity(it);
更多相关文章
- Android(安卓)百分比布局
- Android(安卓)支持的 media 文件格式--MediaFile
- Android之Input子系统事件分发流程
- Android(安卓)布局
- Eclipse+CDT+GDB调试android NDK程序 轉
- vlc android 代码编译
- Android(安卓)Pull解析xml
- android 导出签名APK--混淆文件proguard.cfg详解
- Google Android(安卓)应用程序结构