Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我对HTC android应用程序的感觉有问题_Android - Fatal编程技术网

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

我对HTC android应用程序的感觉有问题,android,Android,我想创建一个应用程序,拍摄照片并重新显示该应用程序。 但是,当我在三星上测试htc代码时,我的感觉不起作用,它可以工作 我的代码: public class CameraDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.

我想创建一个应用程序,拍摄照片并重新显示该应用程序。 但是,当我在三星上测试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上工作吗


谢谢。

我在使用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);
    }

希望这有助于……

它不起作用意味着什么?请更具体地说,如果要运行它,我拍摄了照片,应用程序关闭时不显示照片。是否引发了任何异常?请检查logcat以查看是否存在任何异常。此外,您还应该检查onActivityResult方法中的resultCode是否确实是Activity.RESULT\u OK。好的是,问题不在代码中,因为它在samsung上工作。但是它在我的HTC sensation上不起作用。pathToPhoto对应什么?pathToPhoto应该对应:_outputFileUri,它是在第一个代码块中设置的_outputFileUri=Uri.fromFilefile;我已经把这些样本编辑成它们应该是什么样子
    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;
}