android联系人、短信、邮件url总结

 

到打电话界面

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

到发送短信页面

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

另一种

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

添加到短信收件箱

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

从sim卡或者联系人中查询

Java代码 复制代码 收藏代码
  1. Cursor cursor;
  2. Uri uri;
  3. if (type == 1) {
  4. Intent intent = new Intent();
  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);
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);
Java代码 复制代码 收藏代码
  1. while (cursor.moveToNext()) {
  2. int peopleId = cursor.getColumnIndex(People._ID);
  3. int nameId = cursor.getColumnIndex(People.NAME);
  4. int phoneId = cursor.getColumnIndex(People.NUMBER);}
while (cursor.moveToNext()) {
     int peopleId = cursor.getColumnIndex(People._ID);
   int nameId = cursor.getColumnIndex(People.NAME);
   int phoneId = cursor.getColumnIndex(People.NUMBER);}

删除

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

添加到联系人:

Java代码 复制代码 收藏代码
  1. ContentValues cv = new ContentValues();
  2. ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
  3. ContentProviderOperation.Builder builder = 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 (RemoteException e) {
  20. e.printStackTrace();
  21. } catch (OperationApplicationException e) {
  22. e.printStackTrace();
  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();
					}

动作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. Uri uri=Uri.parse("mailto:terryyhl@gmail.com");
  2. Intent MymailIntent=new Intent(Intent.ACTION_SEND,uri);
  3. startActivity(MymailIntent);
Uri uri=Uri.parse("mailto:terryyhl@gmail.com"); 
            Intent MymailIntent=new Intent(Intent.ACTION_SEND,uri); 
            startActivity(MymailIntent); 

方法二:

Java代码 复制代码 收藏代码
  1. Intent testintent=new Intent(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, "发送"));
Intent testintent=new Intent(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代码 复制代码 收藏代码
  1. //播放多媒体
  2. Intent it = new Intent(Intent.ACTION_VIEW);
  3. Uri uri = Uri.parse("file:///sdcard/song.mp3");it.setDataAndType(uri,"audio/mp3");
  4. startActivity(it);
  5. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI,"1");
  6. Intent it = new Intent(Intent.ACTION_VIEW, uri);startActivity(it);
//播放多媒体
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);

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值