以下代码在某些设备上不断崩溃(立即关闭铃声选择器对话框),在大多数设备上它按预期工作。我没有为它崩溃的设备找到一个共同的共同点。
如果有人可以帮助我解决这个问题,我会非常高兴。顺便说一句:Logcat 完全没有显示任何内容。没有错误。
这是代码
protected void chooseRingtone() {
final Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.choose_ringtone));
if (ringtoneURI != null) {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneURI);
}
else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
}
startActivityForResult(intent, RINGTONE_RESULT);
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == RESULT_OK && requestCode == RINGTONE_RESULT) {
ringtoneURI = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
if (ringtoneURI != null) {
try {
ringtoneString = RingtoneManager.getRingtone(this, ringtoneURI).getTitle(this);
} catch (final Exception e) {
ringtoneString = "unknown";
}
ringtone.setText(ringtoneString);
}
}
}
清单看起来像这样:
<uses-sdk
android:maxSdkVersion="17"
android:minSdkVersion="8"
android:targetSdkVersion="8"
/>