我正在尝试学习如何添加“设为联系人铃声”的功能。我已经知道如何设置默认铃声,但是我不知道如何将其设置为联系人铃声。 我到了选择联系人的部分,但是我不知道如何为该联系人分配铃声。 这个部分让我很困扰,我似乎找不到关于这个主题已经提出的问题的答案。 以下是我目前的代码:
static public final int CONTACT_CHOOSER_ACTIVITY_CODE = 73729;
private File csound;
private final File rpath = new File(Environment.getExternalStorageDirectory() + "/Ringtone sounds/Ringtones");
@Override
public void onClick(View v) {
setContRing();
}
private void setContRing() {
Boolean success = false;
csound = new File(rpath, FNAME);rpath.mkdirs();
if (!csound.exists()) {
try {
InputStream in = getResources().openRawResource(FPATH);
FileOutputStream out = new FileOutputStream(csound.getPath());
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
} catch (Exception e) {
success = false;
}
} else {
success = true;
setContRingtone();
}
if (!success) {
setContRingtone();
}
}
private void setContRingtone() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, CONTACT_CHOOSER_ACTIVITY_CODE);
}
});
}
编辑赏金: 我想知道有没有人能够向我展示如何做到这一点,我试着使用在其他问题中找到的代码,但我无法将它们应用到我的代码中。我可以复制文件,但如何获取联系人并为该联系人分配铃声呢?