Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中以编程方式向本机应用程序联系人添加铃声_Android_Contacts_Android Contacts_Ringtone - Fatal编程技术网

如何在android中以编程方式向本机应用程序联系人添加铃声

如何在android中以编程方式向本机应用程序联系人添加铃声,android,contacts,android-contacts,ringtone,Android,Contacts,Android Contacts,Ringtone,我知道如何使用编程方式为本机应用程序创建姓名、手机号码、电子邮件id的联系人。但我不知道如何与铃声建立联系。请帮帮我。提前谢谢 在将联系人添加到本机应用程序后,我获得了添加铃声的解决方案: String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" +first_name+ "\" )"; Cursor c1 = getContentResolver().query(ContactsContract.Cont

我知道如何使用编程方式为本机应用程序创建姓名、手机号码、电子邮件id的联系人。但我不知道如何与铃声建立联系。请帮帮我。提前谢谢

在将联系人添加到本机应用程序后,我获得了添加铃声的解决方案:

String select = "(" + ContactsContract.Contacts.DISPLAY_NAME + " == \"" +first_name+ "\" )"; 

Cursor c1 = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, 
CONTACTS_SUMMARY_PROJECTION, select, null, ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC");

startManagingCursor(c1);

int id=0;

if (c1.moveToNext()) {

id = new Integer(c1.getString(0)).intValue();

Toast.makeText(getApplicationContext(), "CONTACT ID: "+id+"", Toast.LENGTH_LONG).show(); 

} 

ContentResolver cr = getContentResolver(); 

cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);

ContentValues values=new ContentValues(); values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, newgroup_ringtone); 
cr.update(ContactsContract.Contacts.CONTENT_URI, values, Contacts._ID + "=" + id, null);

为什么不先添加联系人,然后检索该联系人,并用铃声更新联系人,代码如下:

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Contacts.CONTENT_URI)
        .withSelection(ContactsContract.Contacts._ID + " = ?", new String[] {id})
        .withValue(ContactsContract.Contacts.STARRED, starred)
        .withValue(ContactsContract.Contacts.SEND_TO_VOICEMAIL, sendToVoicemail)
        .withValue(ContactsContract.Contacts.CUSTOM_RINGTONE, ringtone)
        .build());

try {
    resolver.applyBatch(ContactsContract.AUTHORITY, ops);
}
ArrayList ops=new ArrayList();
添加(ContentProviderOperation.newUpdate(ContactsContract.Contacts.CONTENT\u URI)
.withSelection(Contacts contact.Contacts._ID+“=?”,新字符串[]{ID})
.带值(Contacts contract.Contacts.STARRED,STARRED)
.withValue(Contacts contract.Contacts.SEND_TO_语音信箱,sendto语音信箱)
.带值(Contacts contract.Contacts.CUSTOM_铃声,铃声)
.build());
试一试{
解析程序applyBatch(ContactsContract.AUTHORITY,ops);
}

如何使用铃声插入新联系人?请帮助我我需要非常紧急的以下代码不适用于我添加带有铃声的联系人。它显示插入失败的异常尝试{if(ringtonepath!=null){ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT\u URI)。withValueBackReference(contacts contract.Data.RAW_CONTACT_ID,0)。withValue(contacts contract.Data.MIMETYPE,contacts contract.commondatatypes.Phone.CONTENT_ITEM_TYPE)。withValue(contacts contract.commondatatypes.Phone.CUSTOM_铃声,ringtonepath.build());})