2012-05-01 12 views
1

いくつかのアプリケーションで動作しています。しかし、私はスナップショットを撮るために携帯電話のネイティブカメラを起動し、ビデオを録画する2つのモジュールを完成しました。私は電話アプリケーションを使用して、イメージと、撮影し、録画したビデオを、作成しようとしているウェブサイトに送信するつもりです。しかし、テキスト情報の場合、私は文字列として情報を保存することができました。画像とビデオのために、投稿時にUrisとして残す必要があるかどうかはわかりません。以下は自分の写真とビデオプログラムです。ありがとう ピクチャーコード:ビデオと画像の可変タイプ

package com.project; 

import java.io.File; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.os.Environment; 
import android.provider.MediaStore; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class MyPicture extends Activity { 
    /** Called when the activity is first created. */ 
    /*constant and variable created so as to work with the taken pictures*/ 
    private static int TAKE_PICTURE = 1; 
    private Uri outputFileUri; 
    Uri imageUri; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.pic); 
     Button pictureButton=(Button) findViewById(R.id.pictureButton); 
     pictureButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       File file = new File(Environment.getExternalStorageDirectory(),"test.jpg"); 
       outputFileUri = Uri.fromFile(file); 
       intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
       startActivityForResult(intent, TAKE_PICTURE); 

      } 
     }); 
    } 
    @Override 
    protected void onActivityResult(int requestCode,int resultCode, Intent data){ 
     if (requestCode == TAKE_PICTURE){ 
      imageUri = data.getData(); 
      //do something about the image in the in outputFileUri 
      Toast.makeText(MyPicture.this, 
        "Picture successfully taken", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyPicture.this,/*program execution proceeds back to MyPicture, our start page after success of image takin*/ 
          Myindex.class); 
        startActivity(i); 

     }else{ 
      Toast.makeText(MyPicture.this, 
        "Picture Unsuccessfully taken", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyPicture.this,/*program execution proceeds back to MyPicture, so we can redo the recording*/ 
          MyPicture.class); 
        startActivity(i); 
     } 

    } 
} 

ビデオコード:イメージの場合

package com.project; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class MyVideo extends Activity { 
    /*program for the vid button*/ 
    private static int RECORD_VIDEO = 1; 
    private static int HIGH_VIDEO_QUALITY = 1; 
    //private static int MMS_VIDEO_QUALITY = 0; 
    Uri recordedVideo; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.vid); 
     Button videoButton=(Button) findViewById(R.id.videoButton); 
     videoButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
       //intent.putExtra(MediaStore.EXTRA_OUTPUT, output); 
       intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, HIGH_VIDEO_QUALITY); 
       startActivityForResult(intent, RECORD_VIDEO); 
      } 
     }); 
    } 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data){ 
     if (requestCode == RECORD_VIDEO){ 
      recordedVideo = data.getData(); 
      //to do something with the recorded video 
      //we shall insert this information in the database 
      Toast.makeText(MyVideo.this, 
        "Video successfully recorded", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyVideo.this,/*program execution proceeds back to Myindex, our start page*/ 
          Myindex.class); 
        startActivity(i); 
     } 
     else{ 
      /*Happens after unsuccessfull recording of video*/ 
      Toast.makeText(MyVideo.this, 
        "Video Unsuccessfully recorded", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyVideo.this,/*program execution proceeds back to MyVideo, so we can redo the recording*/ 
          MyVideo.class); 
        startActivity(i); 
     } 

    } 
} 

答えて

0

私が通常行うことBitmapとしてデータをデコードすることですし、私はマルチパートコンテンツタイプを使用してHTTP POSTを介して、それを送信。

BitmapFactory.decodeFileを使用して、画像ファイルをBitmapとしてデコードすることができます。ここで

は私がApacheライブラリ使用してマルチパートでBitmapを送信する方法の例です:ビデオファイルの場合は

public String doHttpMultipart(String url, 
            List<NameValuePair> pairs, 
            Bitmap bitmap, 
            String fileName) throws IOException, 
               ClientProtocolException, 
               UnsupportedEncodingException { 
      ByteArrayOutputStream bos = new ByteArrayOutputStream();   
      bitmap.compress(CompressFormat.PNG, 100, bos); 
      byte[] imageData = bos.toByteArray(); 
      ByteArrayBody byteArrayBody = new ByteArrayBody(imageData, fileName); 
      MultipartEntity reqEntity = 
         new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

      reqEntity.addPart("image", byteArrayBody); 

      for(NameValuePair p : pairs) { 
       reqEntity.addPart(p.getName(), new StringBody(p.getValue())); 
      } 

      HttpPost request = new HttpPost(url); 
      request.setEntity(reqEntity); 

      HttpClient client = new DefaultHttpClient(); 
      HttpResponse httpResponse = client.execute(request); 

      String response = ""; 
      BufferedReader in = null; 

      try { 
       response = super.readHttpStream(response, in, httpResponse);  
      } catch(IllegalStateException e) { 
       throw new IllegalStateException(); 
      } catch(IOException e) { 
       throw new IOException(); 
      } finally { 
       if (in != null) { 
        try { 
         in.close(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
       } 
      } 

      return response; 
     } 

を、それはあなたがバイトの配列としてそれをデコードする方法を確認する必要があり同じである必要がありますマルチパートで送信します。

関連する問題