我对HTC android应用程序的感觉问题

时间:2011-08-17 13:29:55

标签: android

我想创建一个拍照并重新显示应用程序的应用程序。 但是当我在三星上测试它时,我对htc代码的感觉不起作用。它可以工作。

我的代码:

public class CameraDemo extends Activity {

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        final Button cameraButton = (Button) findViewById(R.id.button1); 
        cameraButton.setOnClickListener( new View.OnClickListener(){ 
         public void onClick(View v ){ 
          Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
          startActivityForResult(intent, 0); 
         } 
        }); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
        if (requestCode== 0 && resultCode == Activity.RESULT_OK){ 
            final ImageView iv = (ImageView) findViewById(R.id.imageView1);
            iv.setImageBitmap((Bitmap) data.getExtras().get("data"));
        } 
    }  
} 

你可以帮助我理解为什么它在我的htc感觉上不起作用,而它可以在另一部手机上工作。

感谢。

1 个答案:

答案 0 :(得分:0)

我在使用HTC相机时遇到了这个问题。

据我所知,HTC / Sense处理返回照片的方式略有不同,这里有一些假的,我希望能够处理两种处理照片的变体......

public static void StartCameraActivity()
{
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
        // Create the directory if it's not there
        File photoDir = new File(Environment.getExternalStorageDirectory() + "/.pics/");
        photoDir.mkdirs();

        // Construct the file..
        String fileName = File.separator + ".pics/photo" + String.valueOf(System.currentTimeMillis()) + ".jpg";
        File file = new File(Environment.getExternalStorageDirectory(), fileName);
         // Create the intent and remember the place we asked for the file to be placed
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
        intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, LinearLayout.VERTICAL );

        _outputFileUri = Uri.fromFile(file);
        context.getActivity().startActivityForResult(intent, 1);
    }

    Bitmap bm = null;
    BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = SAMPLE_SIZE;
        try
        {
            bm= (Bitmap) data.getExtras().get("data");
            FileOutputStream out = new FileOutputStream(_outputFileUri.getPath());
            bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
        }
        catch (NullPointerException ex)
        {
            bm = OtherImageProcessing(options);
        }
        catch (Exception e)
        {
            throw new Exception("Problem occured.", e);
        }

public static Bitmap OtherImageProcessing(BitmapFactory.Options options) throws Exception
{
    Bitmap bm = null;

    try
    {
        FileInputStream fis = new FileInputStream(_outputFileUri.getPath());
        BufferedInputStream bis = new BufferedInputStream(fis);
        bm = BitmapFactory.decodeStream(bis, null, options);

        // cleaning up
        fis.close();
        bis.close();
    }
    catch (Exception e)
    {
        throw new Exception("Problem", e);
    }

    return bm;
}

希望有帮助...