I am trying to password protect my application so that the main activity allows the user to enter a password and then submit it by pressing a button.
I have copied the code from another question Password protecting my android app (the simple way)
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class PasswordMenu extends Activity {
MediaPlayer mpbuttonclick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.activity_password_menu);
mpbuttonclick = MediaPlayer.create(this, R.raw.keypress);
Button sumbitButton = (Button) findViewById(R.id.button_enterpassword);
sumbitButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText passwordEditText = (EditText) findViewById(R.id.text_enterpassword);
if (passwordEditText.getText().toString().equals("Test")) {
startActivity(new Intent("com.berry.intro"));
mpbuttonclick.start();
}
}
});
}
public void openMenu(View view) {
Intent intent = new Intent(this , MainMenu.class);
startActivity(intent);
}
/*@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.password_menu, menu);
return true;
}*/
}
However after making some small changes so that it fits my application, I got an error message at the line
mpbuttonclick = MediaPlayer.create(this, R.raw.keypress);
where raw "cannot be resolved or is not a field". Can someone let me know why I am getting this error?