【发布时间】:2014-06-18 02:57:12
【问题描述】:
我正在尝试学习如何将设置添加为联系人铃声功能。我已经知道如何设置默认铃声,但我不知道如何设置为联系人铃声。 我到了我选择联系人的部分,但我不知道如何为该联系人分配铃声。 那部分困扰着我,我似乎无法在已经就该主题提出的问题中找到答案。 到目前为止,这是我的代码:
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);
}
});
}
编辑赏金:我想知道是否有人可以告诉我如何这样做,我尝试使用其他问题中找到的代码,但我无法将它们应用于我的代码。我可以复制文件,但如何获取联系人并为该联系人分配铃声?
【问题讨论】: