0

我正在尝试按照本教程进行操作,但是问题是当我单击应该确认图像的复选标记时,它根本没有做任何事情。我觉得我缺少某种访问 SD 卡或其他东西的权限。我正在调试模式下测试nexus 7。感谢所有帮助。

public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888; 
private static ImageView imageView;
protected String _path;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);

    _path =  Environment.getExternalStorageDirectory() + "/images/camocr";


    photoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            File file = new File( _path );
            Uri outputFileUri = Uri.fromFile( file );
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
            intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );

            //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            startActivityForResult( intent, 0 );
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == -1) {  
       // Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 4;
        Bitmap bitmap = BitmapFactory.decodeFile( _path, options );
        imageView.setImageBitmap(bitmap);

    }  
} 
protected static void identifyunicode() {
    // DATA_PATH = Path to the storage
    // lang for which the language data exists, usually "eng"


}

}

4

2 回答 2

0

尝试在方法中将您的更改requestCode为 -1 onCreate。那应该可以解决您的问题。

于 2013-04-26T00:39:07.920 回答
0

在您的 startActivity for result 中,请求代码为 0,在 onActivity 结果中您检查 -1 也必须使用:

sendBroadcast(new Intent(
            Intent.ACTION_MEDIA_MOUNTED,
            Uri.parse("file://" + Environment.getExternalStorageDirectory())));

让图片显示,否则直到下次打开手机时才会显示

于 2013-04-26T00:41:17.640 回答