我正在录制音频并将其与日期一起存储在 SD 卡中。这是我
添加音频文件的日期和其他详细信息的代码。
audioFileName=input.getText().toString();
current = System.currentTimeMillis();
String artist = "" + getResources().getText(R.string.artistName);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, audiofile.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, audioFileName);
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) current );
callMessage();
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/3gpp");
values.put(MediaStore.Audio.Media.ARTIST, artist);
values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri1 = contentResolver.insert(base, values);
这是我获取音频的所有详细信息的代码。
try {
mAdapter = new SimpleCursorAdapter(
this,
// Use a template that displays a text view
R.layout.media_select_row,
// Give the cursor to the list adatper
createCursor(""),
// Map from database columns...
new String[] {
String.valueOf(MediaStore.Audio.Media.DATE_ADDED ),
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media._ID},
// To widget ids in the row layout...
new int[] {
R.id.row_date,
R.id.row_album,
R.id.row_title,
R.id.row_icon,
R.id.row_options_button});
setListAdapter(mAdapter);
getListView().setItemsCanFocus(true);
// Normal click - open the editor
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent,
View view,
int position,
long id) {
startRecordingEditor();
}
});
} catch (SecurityException e) {
// No permission to retrieve audio?
Log.e("RecordingApp", e.toString());
// todo error 1
} catch (IllegalArgumentException e) {
// No permission to retrieve audio?
Log.e("RecordingApp", e.toString());
// todo error 2
}
mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view,
Cursor cursor,
int columnIndex) {
if (view.getId() == R.id.row_options_button){
// Get the arrow image view and set the onClickListener to open the context menu.
ImageView iv = (ImageView)view;
iv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openContextMenu(v);
}
});
return true;
} else if (view.getId() == R.id.row_icon) {
setSoundIconFromCursor((ImageView) view, cursor);
return true;
}
return false;
}
});
它显示了其他详细信息,但是当我想通过使用DATE_ADDED
它来显示日期时,会显示
以下我无法理解的错误。
08-09 13:15:52.519: E/AndroidRuntime(3265): FATAL EXCEPTION: main
08-09 13:15:52.519: E/AndroidRuntime(3265): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blitze.recordingapp/com.blitze.recordingapp.RecorderListActivity}: java.lang.NullPointerException
08-09 13:15:52.519: E/AndroidRuntime(3265): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-09 13:15:52.519: E/AndroidRuntime(3265): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1797)
08-09 13:15:52.519: E/AndroidRuntime(3265): at android.view.View.performClick(View.java:3511)
08-09 13:15:52.519: E/AndroidRuntime(3265): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 13:15:52.519: E/AndroidRuntime(3265): at java.lang.reflect.Method.invoke(Method.java:511)
08-09 13:15:52.519: E/AndroidRuntime(3265): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-09 13:15:52.519: E/AndroidRuntime(3265): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-09 13:15:52.519: E/AndroidRuntime(3265): at dalvik.system.NativeStart.main(Native Method)
08-09 13:15:52.519: E/AndroidRuntime(3265): Caused by: java.lang.NullPointerException
08-09 13:15:52.519: E/AndroidRuntime(3265): at com.blitze.recordingapp.RecorderListActivity.onCreate(RecorderListActivity.java:149)
08-09 13:15:52.519: E/AndroidRuntime(3265): at android.app.Activity.performCreate(Activity.java:4465)
08-09 13:15:52.519: E/AndroidRuntime(3265): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-09 13:15:52.519: E/AndroidRuntime(3265): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
我正在尝试,但无法从 SD 卡获取日期。
请有人指导我正确的观点。
提前致谢。