回來時,我做了一個應用程序有兩個按鈕Android攝像頭畫面的URI以失敗交付結果ResultInfo
- 一個從庫中選擇圖像
- 一個採取一個新的形象與相機
畫廊選擇的過程工作正常,如果我用相機拍攝照片,它會一直出現Failure delivering result ResultInfo
錯誤。看起來圖像沒有寫入文件夾。
既然返回相同我有一個處理程序來應付結果;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK && data.getData() != null){
try {
Log.i("YADDA",data.getData().toString());
Uri targetUri = data.getData();
if (targetUri != null) {
//Log.i("YADDA",targetUri.toString());
myImage nsi = new myImage();
nsi.ThumbNail = getThumbnail(targetUri);
nsi.path = targetUri;
nsi.FileName = FileNameBase + "_" + String.valueOf(1 + photos.size());
photos.add(nsi);
}
} catch (IOException e) {
e.printStackTrace();
}
DrawImageGallery();
}
}
Button處理程序;
nsbu1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
}
});
nsbu2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// Uri myuri=Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath(), FileNameBase + ".jpg"));
Uri myuri=Uri.fromFile(new File("/mnt/sdcard/tmp/" + FileNameBase + ".jpg"));
Log.i("YADDA", myuri.toString());
intent.putExtra(MediaStore.EXTRA_OUTPUT, myuri);
startActivityForResult(cameraIntent, 1);
}
});
事情我想:
- 我仔細檢查過的,清單上的SD卡
- 奇怪的事情寫權限是,處理程序必須是正確的,因爲從畫廊的作品圖片很好
- 某些版本的android有這個相機處理程序的錯誤,但我檢查過,我的Nexus S不是其中之一。
- 一派/調試幾個小時
logcat的輸出;
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): FATAL EXCEPTION: main
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.android.spot/com.android.spot.newsite}: java.lang.NullPointerException
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.os.Handler.dispatchMessage(Handler.java:99)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.os.Looper.loop(Looper.java:130)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at java.lang.reflect.Method.invoke(Method.java:507)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at dalvik.system.NativeStart.main(Native Method)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): Caused by: java.lang.NullPointerException
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at com.android.spot.newsite.onActivityResult(newsite.java:351)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
09-01 10:02:59.085: ERROR/AndroidRuntime(1898): ... 11 more
http://www.softwarepassion.com/android-series-taking-photos-with-andorid-built-in-camera/ –
感謝您的建議,我試過了,沒有結果,同樣的錯誤。 thnx annyways! – Lectere
你可以發佈logcat錯誤嗎? –