2012-03-01 8 views
-1

ようこそ皆様、 私のアプリケーションはギャラリーから写真を検索する必要があります。私はGoogleで検索しました 次に私のコードの下に簡単なコードを見つけました。 (私は参照ボタンを押してギャラリーに行く)が、私はそれが画像を取得するかどうかわからない あなたがエミュレータは、画像を追加しようとしていない知っているので、 エミュレータDDMS)しかし、私はこのコード(onActivityResult()とString getPath())のこれらの関数が選択された画像を取得するかどうかわからないので、私はできませんでしたか?ギャラリーアンドロイドアプリケーションから画像をアップロード

Q1:私の場合は、ケースオブジェクト(プロジェクトのクラス)に追加する方法を教えてください ?

public class MyCase { 


    //private ?? pic; 
    private String name; 
    private String gender ; 
    private int age; 
    private String clothes; 
    private String MoreInfo; 
    private String time; 
    private String location; 
    private int ID; 
} 

Q2:ケース画像にはどのようなデータタイプを使用しますか?

本当にありがとうございました,,

public class CreateNewForm extends Activity implements OnItemSelectedListener { 


     Button Browse, Cancelb, Nextb; 
     ImageView CasePic; 
     Spinner CaseDurationH, CaseDurationM; 
     TextView tesst; 
     RadioGroup GenderSelection; 
     EditText CaseName, CaseClothes, CaseMoreInfo, CaseAge; 

     //For Browsering Picture 
     private static final int SELECT_PICTURE = 1; 
     private String selectedImagePath; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) 
     { 

      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.create_new_form); 

      //To Call initializer Function 
      initializer(); 

      // 1-For Uploading Picture 
      Browse.setOnClickListener(new View.OnClickListener() { 

       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        // in onCreate or any event where your want the user to 
        // select a file 
        Intent intent = new Intent(); 
        intent.setType("image/*"); 
        intent.setAction(Intent.ACTION_GET_CONTENT); 
        startActivityForResult(Intent.createChooser(intent, 
          "Select Picture"), SELECT_PICTURE); 
       } 
      }); 


    } 

    // To initialize the variables 
    private void initializer() { 
     // TODO Auto-generated method stub 
     //This information will be filled by a plaintiff 
       //CasePic = (ImageView) findViewById(R.id.imageView1); 
       CaseName= (EditText) findViewById(R.id.caseNm); 
       GenderSelection= (RadioGroup) findViewById(R.id.radioGroup1); 
       CaseAge= (EditText) findViewById(R.id.caseaage); 
       tesst= (TextView) findViewById(R.id.textView8); 
       CaseDurationH= (Spinner) findViewById(R.id.Shr); 
       CaseDurationM= (Spinner) findViewById(R.id.Smin); 
       CaseClothes= (EditText) findViewById(R.id.caseClothes); 
       CaseMoreInfo= (EditText) findViewById(R.id.caseMrInfo); 
       CasePic = (ImageView) findViewById(R.id.casepic); 
       Browse = (Button) findViewById(R.id.browseCasePic); 
       Nextb= (Button)findViewById(R.id.next1); 
       Cancelb = (Button) findViewById(R.id.cancel1); 
    } 

     //For Uploading Picture 
     public void onActivityResult(int requestCode, int resultCode, Intent data) { 
      if (resultCode == RESULT_OK) { 
       if (requestCode == SELECT_PICTURE) { 
        Uri selectedImageUri = data.getData(); 
        selectedImagePath = getPath(selectedImageUri); 
       } 
      } 
     } 

     //For Uploading Picture 
     public String getPath(Uri uri) { 
      String[] projection = { MediaStore.Images.Media.DATA }; 
      Cursor cursor = managedQuery(uri, projection, null, null, null); 
      int column_index = cursor 
        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
      cursor.moveToFirst(); 
      return cursor.getString(column_index); 
     } 

答えて

0

あなたはDDMS FileExplorerまたは "ADBプッシュ" を使用してSDカードに画像をプッシュすることができます。完了したら、Media Scannerを実行する必要があります。 Media ScannerはSDCardをスキャンし、検出した画像をMediaStoreに追加します。 Media Scannerをプログラム的に起動することも、エミュレータ上で組み込みのDev Toolsアプリを使用することもできます。

コードをプログラム的にメディアスキャナをトリガする:たくさん

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 
+0

おかげで私は、このコードを入力しなければなりません?私はこれらのことで初心者です...もっと前にありがとう –

関連する問題