Note that there are some explanatory texts on larger screens.

plurals
  1. POtrying to save a file with the current date and the name that the user choose but i get ERROR: open failed :EACCES (Permission denied )
    primarykey
    data
    text
    <p>i am trying to save a file in the emulator with the name that choose it the user and the current date .</p> <p>but i get an error message that say :<strong>open failed :EACCES (Permission denied )</strong></p> <p>how to fix this error i will appreciate any help </p> <h1>SingInSActivity.java</h1> <pre><code>public class SignSoldgerActivity extends Activity { EditText edit_txt_note; final Context context = this; // attribute for the date picker public String fileName; Button btn_save_soldger; TextView txtatePicker; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_soldger); edit_txt_note = (EditText) findViewById(R.id.editTxtNote); txtatePicker = (TextView) findViewById(R.id.txtDate); btn_save_soldger = (Button) findViewById(R.id.btnSaveSoldger); btn_save_soldger.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // / for creating a dialog LayoutInflater li = LayoutInflater.from(context); View promptsView = li.inflate(R.layout.prompts, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( context); // set prompts.xml to alertdialog builder alertDialogBuilder.setView(promptsView); final EditText userInput = (EditText) promptsView .findViewById(R.id.editTextDialogUserInput); // set dialog message alertDialogBuilder .setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to result // edit text String userinputResult = userInput .getText().toString(); SimpleDateFormat formatter = new SimpleDateFormat( "yyyy/MM/dd_HH:mm:ss"); Date now = new Date(); fileName = formatter.format(now) + "__" + userinputResult; txtatePicker.setText(fileName); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); // / for saving the file on the SD try { String sdPath = Environment.getExternalStorageDirectory() .getAbsolutePath() + fileName + ".txt"; File myFile = new File(sdPath); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); OutputStreamWriter myOutWriter = new OutputStreamWriter( fOut); // append or write myOutWriter.append(edit_txt_note.getText()); myOutWriter.close(); fOut.close(); edit_txt_note.setText(""); Toast.makeText(getBaseContext(), "Done Writing SD" + fileName, Toast.LENGTH_SHORT) .show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } } }); } </code></pre> <p>the permission is added in the </p> <h1>manifest file</h1> <p><strong><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;</code></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload