Android相机应用程序。两项活动

时间:2014-05-06 12:13:40

标签: java android android-intent camera imageview

我正在尝试开发Android应用程序。我正在学习Android,所以我去了。 我的用法与此类似:http://www.tutorialspoint.com/android/android_camera.htm; 除了我有两个活动..一个叫做Report.java,另一个叫做Form.java。 在Report.java中,我有一个按钮,当我点击按钮时,我想打开相机并拍照。拍完照片之后,我想开始第二个活动(Form.java)和我的图像保存在ImageView中。 我怎样才能做到这一点?提前谢谢。

Report.java

package com.example.harta;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class Report extends Activity implements View.OnClickListener{
    ImageView iv;
    Button report;
    final static int cameraData = 0;
    Bitmap bmp;
    Intent i;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.report);
        initialize();
        report.setOnClickListener(this);
    }



    private void initialize() {
        // TODO Auto-generated method stub
        report = (Button) findViewById(R.id.bReport);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
           case R.id.bReport:
               i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
               startActivityForResult(i, cameraData);
               break;
        }   
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK){
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");
            Intent i = new Intent(Report.this, Formular.class);
            startActivity(i);
        }
    }
}

Form.java

package com.example.harta;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

public class Formular extends Activity{
    Button button;
    ImageView iv;
    int cameraResults;
    final static int cameraData = 0;
    Bitmap bmp;
    TextView tvAdress, tvAmpers, tvCommunication, tvCoordinates;
    TextView tvName, tvInformations, tvDataIntro, tvPhone, tvLatitude;
    TextView tvLongitude, tvInstalledPower, tvContor, tvNetwork;
    EditText etAdress, etAmpers, etCommunication, etCoordinates;
    EditText etName, etInformations, etDataIntro, etPhone, etLatitude;
    EditText etLongitude, etInstalledPower, etContor, etNetwork;
    Spinner spinNetwork;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.formular);
        initialize();
    }

    private void initialize() {
        // TODO Auto-generated method stub
        tvAdress = (TextView) findViewById(R.id.tvAdresa);
        tvAmpers = (TextView) findViewById(R.id.tvAmperaj);
        tvCommunication = (TextView) findViewById(R.id.tvComunicatie);
        tvCoordinates = (TextView) findViewById(R.id.tvCoord);
        tvName = (TextView) findViewById(R.id.tvDenumire);
        tvInformations = (TextView) findViewById(R.id.tvInfo);
        tvDataIntro = (TextView) findViewById(R.id.tvIntroducereDate);
        tvPhone = (TextView) findViewById(R.id.tvIPtelefon);
        tvLatitude = (TextView) findViewById(R.id.tvLat);
        tvLongitude = (TextView) findViewById(R.id.tvLong);
        tvInstalledPower = (TextView) findViewById(R.id.tvPutereInstalata);
        tvContor = (TextView) findViewById(R.id.tvSerieContor);
        tvNetwork = (TextView) findViewById(R.id.tvTipulRetelei);
        etAdress = (EditText) findViewById(R.id.etAdresa);
        etAmpers = (EditText) findViewById(R.id.etAmperaj);
        etCommunication = (EditText) findViewById(R.id.etComunicatie);
        etName = (EditText) findViewById(R.id.etDenumire);
        etPhone = (EditText) findViewById(R.id.etIPtelefon);
        etInstalledPower = (EditText) findViewById(R.id.etPutereInstalata);
        etContor = (EditText) findViewById(R.id.etSerieContor);
        spinNetwork = (Spinner) findViewById(R.id.spinTipulRetelei);
        button = (Button) findViewById(R.id.bTrimitere);
        iv = (ImageView) findViewById(R.id.ivPic);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub

    }
}

0 个答案:

没有答案