2012-05-11 14 views
0

私はアレルギー反応を起こしたときにアレルギー反応を起こすことができるアプリケーションを作成したいと思います。次に、ドキュメントに情報を追加し、そのすべてを保存し、ジオローカライゼーションを保存することができます。 (考えてみると、アレルギーの人は日記を必要とするので、通常彼は6ヶ月に1回アレルギーを見ることができます)私はコードを作成し、アンドロイドカメラを使用する必要があります

私はこのコードを書いています:私は電話のメニューボタンを押す必要がありますカメラ。しかし、今私はカムを使用できるボタンを持っています。誰も私のコードを変更し、私は自分のアンドロイド携帯電話で写真を撮ることができるようにカメラの使用を許可するボタンを正しく追加する手助けをすることができますか?

忠実に、

私のコード:

パッケージandroid.camera。あなたのonCreateメソッド内

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:text="Take Picture" android:id="@+id/take_picture"></Button> 

その後:

 import android.app.Activity; 
     import android.content.Intent; 
     import android.graphics.Bitmap; 
     import android.os.Bundle; 
    import android.provider.MediaStore; 
     import android.view.Menu; 
     import android.view.MenuInflater; 
     import android.view.MenuItem; 
     import android.widget.ImageView; 



     public class CameraActivity extends Activity { 

      private static final int PICTURE_RESULT = 9; 

      private Bitmap mPicture; 
      private ImageView mView; 

      public void onCreate(Bundle icicle) { 
       super.onCreate(icicle); 
       setContentView(R.layout.main); 

       mView = (ImageView) findViewById(R.id.view); 
      } 

      @Override 
      public boolean onCreateOptionsMenu(Menu menu) { 
       MenuInflater inflater = getMenuInflater(); 
       inflater.inflate(R.menu.menu, menu); 
       return true; 
      } 

      @Override 
      public boolean onOptionsItemSelected(MenuItem item) { 
       switch (item.getItemId()) { 
       case R.id.camera: 
        Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        CameraActivity.this.startActivityForResult(camera, PICTURE_RESULT); 
        return true; 
       default: 
        return super.onOptionsItemSelected(item); 
       } 
      } 

    /*  public void onDestroy() { 
       super.onDestroy(); 
       if (mPicture != null) { 
        mPicture.recycle(); 
       } 
      }*/ 

      @Override 
      protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
       super.onActivityResult(requestCode, resultCode, data); 

       // if results comes from the camera activity 
       if (requestCode == PICTURE_RESULT) { 

        // if a picture was taken 
        if (resultCode == Activity.RESULT_OK) { 
         // Free the data of the last picture 
         if(mPicture != null) 
          mPicture.recycle(); 

         // Get the picture taken by the user 
         mPicture = (Bitmap) data.getExtras().get("data"); 

         // Avoid IllegalStateException with Immutable bitmap 
         Bitmap pic = mPicture.copy(mPicture.getConfig(), true); 
         mPicture.recycle(); 
         mPicture = pic; 

         // Show the picture 
         mView.setImageBitmap(mPicture); 

         // if user canceled from the camera activity 
        } else if (resultCode == Activity.RESULT_CANCELED) { 

        } 
       } 
      } 
     } 

答えて

0

私は、これはあなたが求めているものだと思う...

あなたのレイアウトファイル(main.xml)でボタンを追加

public void onCreate(Bundle icicle) { 
      super.onCreate(icicle); 
      setContentView(R.layout.main); 

      mView = (ImageView) findViewById(R.id.view); 
      mTakePictureButton = (Button) findViewById(R.id.take_picture); 
      mTakePictureButton.setClickable(true); 
      mTakePictureButton.setOnClickListener(new View.onClickListener(){ 

        @Override 
     public void onClick(View v) { 
      Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       startActivityForResult(camera, PICTURE_RESULT); 

     } 
      }); 
     } 
+0

はい!それは素晴らしいことです !ありがとう、これは働いています!写真はどこに保存されているのだろうか?私は、ユーザーのコメント、画像、地理位置情報を保存できる場所に同じ文書を置くことができればと願っています。データをファイルに保存する必要がありますか?またはSqliteで管理しているローカルデータベースにありますか?誰でも助けてくれますか? (私は多分私が初心者であることを忘れているかもしれませんが、私はコードを書くのが好きです^^) –

+0

私はあなたが写真を保存する必要があると信じています。私はそれが救われるかどうか分からない。このコードを実行し、ギャラリーが保存されているかどうかを確認することができます。ユーザーのコメント、写真などを保存するには、sqliteデータベースを管理する必要があります。ここで例を見ることができます:http://adblogcat.com/sqlite-database/ –

+0

例のおかげで。しかし、私はまだ質問があります。同じローカルデータベースに画像のユーザを置くことは可能ですか?ファイルを使用してユーザーのデータを保存できますか?私を助けてください –

関連する問題