0

I have an activity called MainActivity and a Service called CameraService which binds to a socket port. Whenever the socket receives the string "camera" the Service broadcast to MainActivity to launch camera.

Intent launchIntent = new Intent(MainActivity._LAUNCH_CAMERA_ACTION);
sendBroadcast(launchIntent);

MainActivity registers _LAUNCH_CAMERA_ACTION and a BroadcastReceiver.

IntentFilter filter = new IntentFilter();
filter.addAction(_LAUNCH_CAMERA_ACTION);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
       if (_LAUNCH_CAMERA_ACTION.equalsIgnoreCase(intent.getAction())) {
         Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     MainActivity.this.startActivityForResult(cameraIntent, REQUEST_CAMERA);
       }
}
}, filter);

Whenever the camera intent is called the program presents an unhandled exception and it terminates because of the exception.

Any ideas why this happens?

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
Ioannis
  • 509
  • 2
  • 6
  • 12

1 Answers1

0

Referencing this post you can do:

     Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");  
     startActivityForResult(intent, 0);

And add Camers Uses Permission in your manifest file.

 <uses-permission android:name="android.permission.CAMERA"></uses-permission>
Community
  • 1
  • 1
Nick
  • 9,285
  • 33
  • 104
  • 147