感謝您的時間。我正在做一個應用程序,我從那裏啓動畫廊和活動A選擇一個圖像,並回到同一活動A.從Gallery中選擇一張照片後,我的Android應用即將關閉。 (有帖子上的bug的視頻)
我這樣做沒有問題從一個單一的活動(它被定義爲啓動器清單),但是當我從清單上定義的Activity的整個項目作爲默認項目執行時,它無法正常工作。
我用開畫廊和選擇照片的意圖:
public void openGallery(int req_code){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select file to upload "), req_code);
}
從哪裏獲得的數據(當我從孔項目執行這是永遠不會被調用)的onActivityResult:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
if (requestCode == SELECT_FILE1)
{
selectedPath1 = getPath(selectedImageUri);
System.out.println("selectedPath1 : " + selectedPath1);
}
if (requestCode == SELECT_FILE2)
{
selectedPath2 = getPath(selectedImageUri);
System.out.println("selectedPath2 : " + selectedPath2);
}
tv.setText("Selected File paths : " + selectedPath1 + "," + selectedPath2);
}
}
這是logcat的轉儲:
01-05 15:18:14.569: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.UPLOADIMAGEDEMO cmp=com.example/.UploadImageDemo }
01-05 15:18:15.779: D/dalvikvm(2496): GC_EXTERNAL_ALLOC freed 2697 objects/189152 bytes in 92ms
01-05 15:18:16.599: I/ActivityManager(59): Displayed activity com.example/.UploadImageDemo: 1953 ms (total 1953 ms)
01-05 15:18:21.899: D/dalvikvm(279): GC_EXPLICIT freed 871 objects/134112 bytes in 217ms
01-05 15:18:26.620: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
01-05 15:18:28.250: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.GET_CONTENT typ=image/* flg=0x3000000 cmp=com.android.gallery/com.android.camera.ImageGallery }
01-05 15:18:28.670: D/dalvikvm(279): GC_EXTERNAL_ALLOC freed 388 objects/53352 bytes in 60ms
01-05 15:18:28.850: D/dalvikvm(279): GC_EXTERNAL_ALLOC freed 326 objects/90664 bytes in 53ms
01-05 15:18:29.200: I/ActivityManager(59): Displayed activity com.android.gallery/com.android.camera.ImageGallery: 873 ms (total 2345 ms)
01-05 15:18:29.420: D/dalvikvm(279): GC_EXTERNAL_ALLOC freed 725 objects/106960 bytes in 140ms
01-05 15:18:30.430: W/InputManagerService(59): Starting input on non-focused client [email protected] (uid=10002 pid=279)
01-05 15:18:32.010: D/dalvikvm(112): GC_FOR_MALLOC freed 9994 objects/476368 bytes in 149ms
要完成,我錄仿真器的行爲第一個來自整個項目(退出應用程序),第二個來自分離的項目,工作正常。
http://www.youtube.com/watch?v=SntnyKiJQ1Q&feature=youtu.be
非常感謝!
請共享logcat轉儲。 –
嘿hrehman!我在那裏更新了這篇文章。讓我知道如果你有任何想法.. – eyyo
我相信你的getPath(selectedImageUri)函數可能有問題。嘗試使用Uri類的函數selectedImageUri.getPath()。如果Uri無效,它將返回null。 –