I am having difficulty opening the camera with my code and I would appreciate some help... Basically the app will display and when I click on the text, the app closes straight away... I feel I am not linking the two correctly.
Here is the code from activity_main.xml:
<TextView
android:id="@+id/textView4"
android:clickable="true"
android:onClick="onClick"
android:text="@string/openCamera" />
And here is my Java:
public class MainActivity extends AppCompatActivity {
static final int REQUEST_IMAGE_CAPTURE = 1;
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView) findViewById(R.id.textView4);
if (!hasCamera()) {
txt.setEnabled(false);
}
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
});
}
private boolean hasCamera() {
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
}
Logcat mentions the following:
FATAL EXCEPTION: main
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE cmp=com.sec.android.app.camera/.Camera launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } } from ProcessRecord{29106f2 12844:com.example.xxxxxxxxxx} (pid=12844, uid=10188) with revoked permission android.permission.CAMERA