"Camera Permission in Android" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "Camera Permission in Android" answered properly. Developers are finding an appropriate answer about Camera Permission in Android related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like Camera Permission in Android. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on Camera Permission in Android.
camera permission android
<uses-permission android:name="android.permission.CAMERA" />
Camera Permission in Android
package edu.gvsu.cis.masl.camerademo;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MyCameraActivity extends Activity
{
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
private static final int MY_CAMERA_PERMISSION_CODE = 100;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.imageView = (ImageView)this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
photoButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
{
requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_CAMERA_PERMISSION_CODE);
}
else
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == MY_CAMERA_PERMISSION_CODE)
{
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
else
{
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on Camera Permission in Android can get a collection of related answers to their query. Programmers need to enter their query on Camera Permission in Android related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Camera Permission in Android for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of Camera Permission in Android while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "Camera Permission in Android". Visit this developer's friendly online web community, CodeProZone, and get your queries like Camera Permission in Android resolved professionally and stay updated to the latest Whatever updates.