日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

怎么调用系统通讯录并向被选中联系人发送短信

發布時間:2023/12/18 windows 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 怎么调用系统通讯录并向被选中联系人发送短信 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

每做一個項目都會有收獲,前提是要在這個項目上付出努力的!

好吧,如今講一下:怎么通過調用系統通訊錄,當你點擊聯系人姓名時,跳轉到向其發送短信的頁面<收件人是被點中的聯系人,短信已自己主動編輯>。

看看圖片效果:


以下看一下具體代碼:

Uri result = data.getData();String phoneName = getPhoneContacts(result);Log.d("phone", "---------->phoneName=="+contactName);String smsContent="發給你一個時尚園APP的注冊邀請碼,他們家的東西非常有品。" +""+"\n"+strInviteCode+"(時尚園 APP下載地址http://t.so)";sendSMS(phoneName,smsContent);
/*** 獲取聯系人手機號碼* @param contactId* @return*/ @SuppressWarnings("deprecation")private String getPhoneContacts(Uri contactId) {Cursor cursor = null;String phoneName = "";//聯系人姓名String phoneNum = "";//聯系人電話號碼String phoneID = "";//聯系人IDtry { // Uri uri = People.CONTENT_URI;cursor=getContentResolver().query(contactId, null, null, null, null);if (cursor.moveToNext()) {phoneName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));phoneID=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));Log.d("phone", "phoneName&&phoneNumber=="+phoneName+"-----"+phoneID);Cursor c=getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID+"="+phoneID, null, null);while(c.moveToNext()){phoneNum=c.getString(c.getColumnIndex("data1"));Log.d("phone", "phoneNumber=="+phoneNum);}} else {Toast.makeText(this, "找不到該聯系人",Toast.LENGTH_LONG).show();}} catch (Exception e) {e.printStackTrace();} finally {if (cursor != null) {cursor.close();}}return phoneNum;}
/*** 發送短信* * @param smsBody*/private void sendSMS(String phoneNum, String smsBody) {Log.d("phone", "sendSMS(String phoneNum, String smsBody)=="+phoneNum);Uri smsToUri = Uri.parse("smsto:"+phoneNum);Intent intent = new Intent(Intent.ACTION_SENDTO, smsToUri);intent.putExtra("sms_body", smsBody);startActivity(intent);// Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("smsto", phoneNum, null)); // mmsintent.putExtra("sms_body", smsBody); // startActivity(mmsintent);/* 建立SmsManager對象 */ // SmsManager smsManager = SmsManager.getDefault(); // smsManager.sendTextMessage(phoneNum, null, smsBody, null, null);}

轉載于:https://www.cnblogs.com/mfrbuaa/p/3800101.html

總結

以上是生活随笔為你收集整理的怎么调用系统通讯录并向被选中联系人发送短信的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。