在首选项屏幕中从 SD 卡中选择 .mp3 文件
Pick .mp3 file from sdcard in preferencescreen
如何在 android preferenceScreen 菜单中从 sdcard 中选择 mp3 文件..
这是我的偏好屏幕:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/app_setting">
<Preference android:title="@string/ChooseRingtone"
android:key="sdPref" />
</PreferenceCategory>
</PreferenceScreen>
这里是我的设置活动:
public class SettingsActivity extends AppCompatPreferenceActivity{
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
if(savedInstanceState == null){
android.app.Fragment infoFragment = new MyPreferenceFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.fragment_container, infoFragment);
ft.commit();
}
public static class MyPreferenceFragment extends PreferenceFragment {
private AppSettings settings;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref);
Preference sdPrefs = findPreference("sdPref");
sdPrefs.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
return false;
}
});
}
}
我不知道如何打开 sdcard 并从整个 sdcard 中只选择 .mp3 扩展文件。以及如果可能的话如何将该 mp3 文件存储到我的 asset/raw 目录
尝试使用以下代码仅选择 mp3 文件,
sdPrefs.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent_upload = new Intent();
//intent_upload.setType("audio/*"); // For All Audio Files
intent_upload.setType("audio/mp3"); // For only MP3 Files
intent_upload.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent_upload,1);
return false;
}
});
如何在 android preferenceScreen 菜单中从 sdcard 中选择 mp3 文件..
这是我的偏好屏幕:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/app_setting">
<Preference android:title="@string/ChooseRingtone"
android:key="sdPref" />
</PreferenceCategory>
</PreferenceScreen>
这里是我的设置活动:
public class SettingsActivity extends AppCompatPreferenceActivity{
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
if(savedInstanceState == null){
android.app.Fragment infoFragment = new MyPreferenceFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.fragment_container, infoFragment);
ft.commit();
}
public static class MyPreferenceFragment extends PreferenceFragment {
private AppSettings settings;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref);
Preference sdPrefs = findPreference("sdPref");
sdPrefs.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
return false;
}
});
}
}
我不知道如何打开 sdcard 并从整个 sdcard 中只选择 .mp3 扩展文件。以及如果可能的话如何将该 mp3 文件存储到我的 asset/raw 目录
尝试使用以下代码仅选择 mp3 文件,
sdPrefs.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent_upload = new Intent();
//intent_upload.setType("audio/*"); // For All Audio Files
intent_upload.setType("audio/mp3"); // For only MP3 Files
intent_upload.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent_upload,1);
return false;
}
});