2016-05-22 9 views
0

オープンファイルのチューザーは、私にとって大きな問題であり、他の多くの人には大きな問題です...アンドロイドの入力タイプを処理する完全なソリューションがありますか? 4.1 ...解決策を見つけようと数週間のために... 4.1以外のバージョンbigerのために働いたが、成功画像ファイルのアップロードのためのAndroidファイルの選択タイプ

// For Android 3.0+ 
      public void openFileChooser(ValueCallback uploadMsg, String acceptType) { 
      mUploadMessage = uploadMsg; 
      Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
      i.addCategory(Intent.CATEGORY_OPENABLE); 
      i.setType("*/*"); 
      MyWb.this.startActivityForResult(
      Intent.createChooser(i, "File Browser"), 
      FILECHOOSER_RESULTCODE); 
      } 

     //For Android 4.1 
      public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){ 
       mUploadMessage = uploadMsg; 
       Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
       i.addCategory(Intent.CATEGORY_OPENABLE); 
       i.setType("image/*"); 
       MyWb.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MyWb.FILECHOOSER_RESULTCODE); 

      } 

答えて

0

せずに、以下の方法は、ファイルから画像を選択するために、より従来の方法ではありません。目的はonActivityResult()を使用して、ユーザーが選択した内容を取得します。

最初にインテントを作成します。
// Creates an Intent to pick a photo Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); は、その後の意図を実行します。
// ARGS: the intent, a key to access later startActivityForResult(i, 1);

あなたは今onActivityResult(int requestCode, int resultCode, Intent data)here利用できる詳細な手順)を設定する必要があります。ここ は、いくつかのサンプルコードです:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == 1 && resultCode == RESULT_OK && data != null) { 
     Uri selectedImage = data.getData(); 
     try { 
      // Do whatever you want with this bitmap (image) 
      Bitmap bitmapImage = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage); 
      Log.i("Image Path", selectedImage.getPath()); 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

直接あなたのクラスにメソッドを置きます。受け取ったBitmapを使用して、任意の操作を行うことができます。

+0

あなたのお返事ありがとうございますが、アンドロイドバージョン4.1+ではファイル選択が開かれていません.... –

関連する問題