How to create a file and check if it is there. I attach the code. (If you have already reached this point, you do not need to reach it, if it is the first time, then an achievement should appear accordingly)
public void showToast(View view) { String fileDir = "file"; File f = new File(fileDir); if (f.exists()) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); }else{ try { new File(fileDir).createNewFile(); } catch (IOException e) { e.printStackTrace(); } Toast toast = Toast.makeText(getApplicationContext(), "Получена первая награда!", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastContainer = (LinearLayout) toast.getView(); ImageView RewardImage = new ImageView(getApplicationContext()); RewardImage.setImageResource(R.drawable.reward); toastContainer.addView(RewardImage, 0); toast.show(); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } Does not work. Tell me what to do. Thank you in advance.
context.getFilesDir(). For this, no permissions are needed and this file will not be visible to other applications. - eugeneek