2015-05-21 48 views
0

我是Android應用程序開發的新手。我和我的團隊正在創建一個使用照片庫文件夾上傳照片的應用程序。該應用程序可以拍攝照片並立即上傳該照片。但具體與三星設備,當我嘗試從相機文件夾上傳照片,應用程序崩潰或上傳白頁。當我嘗試從相冊中除了相機文件夾以外的其他文件夾,這也是完美的。它僅在相機文件夾中出現此錯誤。我用不同的nexus設備測試了我的應用程序,它的工作非常完美。我一直在這裏隨處搜尋。我在Android Studio上編寫了所有代碼以及Java和XML。有沒有人有同樣的問題,並能解決?我真的需要一個指導。感謝您的時間和您的關注。Android應用程序照片上傳問題

這裏是我的Java onGalleryClick方法:

public void onGalleryClick(View v) { 

    isCameraReleased = true; 
    //TODO 
    Intent intent = new Intent(); 
    intent.setType("image/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(Intent.createChooser(intent, 
      "Select Picture"), SELECT_PICTURE); 
} 
+1

顯示您上傳的代碼。 – SmulianJulian

+0

我有使用LG設備的類似問題。哪個應用程序打開照片庫? –

+0

我添加了我的onGalleryClick方法。 – tuygun

回答

0

我想我想通了與實施畢加索庫。最後,當我進入圖庫選項時,我可以訪問相機文件夾(其中一些設備是DCIM)。我相信三星設備有一個非常低的虛擬記憶,不知何故它不允許你看到你創建的Android應用程序的imageView。基本上我在android studio上創建了一個非常簡單的按鈕,它被稱爲activity_main.xml。它是:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

<ImageView 
    android:id="@+id/imgView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 
</ImageView> 

    <Button 
    android:id="@+id/buttonLoadPicture" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_weight="0" 
    android:onClick="loadImagefromGallery" 
    android:text="Load Picture" > 
    </Button> 

</LinearLayout> 

之後,我創建了MainActivity.java,它提供了所有功能。那就是:

import android.app.Activity; 
import android.content.Intent; 
import android.database.Cursor; 
import android.graphics.BitmapFactory; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.View; 
import android.widget.ImageView; 
import android.widget.Toast; 

public class MainActivity extends Activity { 
    private static int RESULT_LOAD_IMG = 1; 
    String imgDecodableString; 

    @Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

public void loadImagefromGallery(View view) { 
    // Create intent to Open Image applications like Gallery, Google Photos 
    Intent galleryIntent = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    // Start the Intent 
    startActivityForResult(galleryIntent, RESULT_LOAD_IMG); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    try { 
     // When an Image is picked 
     if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK 
       && null != data) { 
      // Get the Image from data 

      Uri selectedImage = data.getData(); 
      String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

      // Get the cursor 
      Cursor cursor = getContentResolver().query(selectedImage, 
        filePathColumn, null, null, null); 
      // Move to first row 
      cursor.moveToFirst(); 

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      imgDecodableString = cursor.getString(columnIndex); 
      cursor.close(); 
      ImageView imgView = (ImageView) findViewById(R.id.imgView); 
      // Set the Image in ImageView after decoding the String 
      imgView.setImageBitmap(BitmapFactory 
        .decodeFile(imgDecodableString)); 

     } else { 
      Toast.makeText(this, "You haven't picked Image", 
        Toast.LENGTH_LONG).show(); 
     } 
    } catch (Exception e) { 
     Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) 
       .show(); 
    } 

} 

} 

這是你必須在AndroidManifest文件中添加一行代碼:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 

這裏是一切的棘手的部分。在您的build.gradle(Module:app)中,您將在依賴項部分添加 compile'c​​om.squareup.picasso:picasso:2.3.3'。

後你必須添加

ImageView imageView = (ImageView) findViewById(R.id.imageView); 

    Picasso.with(this) 
      .load("https://cms-assets.tutsplus.com/uploads/users/21/posts/19431/featured_image/CodeFeature.jpg") 
      .into(imageView); 

而且你去!請看看http://code.tutsplus.com/tutorials/android-sdk-working-with-picasso--cms-22149