在Android 2.3上工作但在android 4.2上没有

时间:2013-05-05 21:04:00

标签: android android-layout android-camera email-attachments

我的应用程序的基本结构是:

  1. 在我的应用的第一个屏幕上,用户点击了一个按钮,TAKE PICTURE。
  2. 手机的默认相机应用程序出现,用户即可拍照。
  3. 必须显示照片,并要求用户输入他的姓名和电话号码。
  4. 必须将姓名,电话号码和图像附加到要发送到预定义地址的电子邮件中。 (gmail android app)
  5. 我的问题是当我在拥有android 2.3的三星手机上运行我的应用程序时,它完美运行(我得到了我最近点击过的图像), 但是当我在拍摄照片后尝试使用Android 4.2的sony手机时,它显示的是另一张照片而不是我最近拍摄的照片。

    我的代码在这里 我的第一页代码:它接受图像并调用另一个活动INF.java

    Cameraproject.java

    public class CameraProject extends Activity {
    
    Button button;
    Bitmap btm;
    Bitmap thumbnail;
    String filePath;
      File pic;
    final static int CameraData = 0;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera_project);
        button = (Button) findViewById(R.id.cont);
    
    
    }
    
    
    //start camera activity
    public void camera(View v) {
        Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, CameraData);
                }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            btm = (Bitmap) extras.get("data");
    
        }
            if(resultCode == RESULT_OK)
            {
                //it moves to another activity
                Intent intent1=new Intent (CameraProject.this,INF.class);
    
                startActivity(intent1);
    
    
    }
            else {
                //if discard it reopen camera activity
                Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(i, CameraData);
            }
    
    }
    
        public void exit(View v)
        {
        finish();
    }
    

    }

    第二类INF.java:显示当前点击的图像,并询问用户输入姓名和电话号码。

    public class INF extends CameraProject {
    Bitmap bitmap;
    String pic,fullPath;
    String[] Paths;
    int era;
    Intent imageReturnedIntent;
    final static int CameraData = 0;
    ArrayList<Uri> uris;   
    File fileIn;
    
    
    private static final String TAG = "MyActivity";
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.in);
    
        Button bt = (Button)findViewById(R.id.bt);
    
        preview();
    
    }
        //to show the image 
    private void preview() {
        getLastImageId();
        File imgFile = new  File(fullPath);
        if(imgFile.exists()){
    
            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    
            ImageView myImage = (ImageView) findViewById(R.id.imageView1);
            myImage.setImageBitmap(myBitmap);
            //generate toast message
            Context context = getApplicationContext();
            CharSequence text = "image shown clearly or not ,if not than press back";
            int duration = Toast.LENGTH_LONG;
    
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
    
    
        }
    
    }
    
    public void Takepath(){
        getLastImageId();
        uris = new ArrayList<Uri>();
        Paths = new String[] {fullPath};
        for(String file : Paths ){
        fileIn= new File(file);
        Uri u=Uri.fromFile(fileIn);
        uris.add(u);
    
        }
    
    }
    //perform sending action
    
            public void sedmail(View v){
                Takepath();
                final EditText et = (EditText)findViewById(R.id.et1);
                final EditText et2 = (EditText)findViewById(R.id.et2);
    
                Intent i = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                i.setType("plain/text");
                i.setType("application/octet-stream");
    
                i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                i.putExtra(Intent.ACTION_DEFAULT, "test/");
    
                i.putExtra(Intent.EXTRA_EMAIL, new String[]{"pravind.india@gmail.com"});
                i.putExtra(Intent.EXTRA_SUBJECT, "My Information");
                i.putExtra(Intent.EXTRA_TEXT, "Name:"+et.getText().toString()+'\n'+"Mobile No."+et2.getText().toString());  
                startActivity(Intent.createChooser(i, "send email...."));
            }
    
    //call camera when back button is pressed
        public void cam(View v) {
            finish();
        }
    
    
        @Override
        public void onBackPressed() {
        finish();
        Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, CameraData);
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data){
            super.onActivityResult(requestCode, resultCode, data);
            if (resultCode == RESULT_OK) {
                Bundle extras = data.getExtras();
                btm = (Bitmap) extras.get("data");
    
            }
                if(resultCode == RESULT_OK){
                    Intent intent1=new Intent (this,INF.class);
                    startActivity(intent1);
        }
                else {
    
                    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(i, CameraData);
                }
    
    
        }
            //get the id of the last image taken by camera          
    private int getLastImageId(){
        final String[] imageColumns = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA };
        final String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
        Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);
        if(imageCursor.moveToFirst()){
            int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
             fullPath = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
            Log.d(TAG, "getLastImageId::id " + id);
            Log.d(TAG, "getLastImageId::path " + fullPath);
           imageCursor.close();
            return id;
        }else{
            return 0;
        }
    }
    
    }
    

0 个答案:

没有答案