For that you need to declare a background service to capture the event when camera application is opened by the user. Background service will have onReceive() method. In that method, you can get the list of running applications processes and match that if the camera is in the foreground. If the camera is clicked by the user, it will appear in the list of the running applications. Then you intercept that event and show the dialog fragment you intend to show to the user.
You can implement a custom DialogFragment class which has required field for asking user the password.
In the Custom dialog class you declare an interface, something like this:
public interface CustomAddressDialogListener{
public void onDialogPositiveClick(DialogFragment dialog, String enteredPassword);
public void onDialogNegativeClick(DialogFragment dialog);
}
Custom DialogFragment will have its own layout for entering the password and you can set Positive actions and negative actions.
Positive action: user enters password and hits submit.
Negative action: user doesn't want to enter password and clicks cancel.
Your parent activity can implement this interface to capture positive and negative click.
@Override
public void onDialogPositiveClick(DialogFragment dialog, String enteredPassword) {
// Here you can check if the password is correct or wrong and take the action accordingly to open the camera.
}
While handling the negative action you can kill the camera process using kill the camera process: android.os.Process.sendSignal(pid, android.os.Process.SIGNAL_KILL);
Here pid is the process id of the camera application. You can obtain pid when you obtains information of running application processes.
For details you can refer to: http://developer.android.com/reference/android/app/DialogFragment.html