Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid camera implementation
    text
    copied!<p>I am going to implement camera feature for my android app.for this, I searched a lot on internet and found 2 way to implement camera feature</p> <ol> <li><p>design your own camera class using </p> <p><code>android.view.SurfaceHolder and android.view.SurfaceView</code> </p></li> </ol> <p>but this approach does look good to me as in this i have to take care of many things which will make my code complex.</p> <p>&nbsp;&nbsp;2. &nbsp;&nbsp;I can use intent to call device camera. now again in this , i have 2 option </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i ) using <code>MediaStore.EXTRA_OUTPUT</code> and not using <code>MediaStore.EXTRA_OUTPUT</code></p> <p>if i dont use <code>MediaStore.EXTRA_OUTPUT</code> I get a thumbnail which is not my actual requirement. i need image larger than this so if I scale this thumbnail, i find low quality image.</p> <p>if i use <code>MediaStore.EXTRA_OUTPUT</code> I dint get any image on some device like samsung as in </p> <p><code>onActivityResult(int requestCode, int resultCode, Intent intent)</code></p> <p>I find intent is null . after searching a lot on internet, i found that this is device specific issue. i have Samsung Galaxy with me. and on this i am facing this issue.</p> <p>i dont want my code to be a device specific code. so can any one tell me how to make my code generic. for your analysis, i am using following code </p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); File root = new File(Environment .getExternalStorageDirectory() + File.separator + "myDir" + File.separator) if(!root.exists()){ root.mkdirs(); } sdImageMainDirectory = new File(root, "myPicName"); startCameraActivity(); } catch (Exception e) { finish(); Toast.makeText(this, "Error occured. Please try again later.", Toast.LENGTH_SHORT).show(); } } Uri outputFileUri; protected void startCameraActivity() { outputFileUri = Uri.fromFile(sdImageMainDirectory); Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, 0); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { switch (resultCode) { case 0: finish(); break; case -1: try { if(intent != null) StoreImage(this, Uri.parse(intent.toURI()), sdImageMainDirectory); } catch (Exception e) { e.printStackTrace(); } Intent i = new Intent(this,Home.class); i.putExtra("url", outputFileUri); startActivity(i); finish(); } } public static void StoreImage(Context mContext, Uri imageLoc, File imageDir) { Bitmap bm = null; try { bm = Media.getBitmap(mContext.getContentResolver(), imageLoc); FileOutputStream out = new FileOutputStream(imageDir); bm.compress(Bitmap.CompressFormat.JPEG, 100, out); bm.recycle(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload