Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name=".RecipeActivity"></activity>
- </application>
- File dir = Environment.getExternalStorageDirectory();
- File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "receip.txt");
- if(file.exists()) // check if file exist
- {
- //Read text from file
- StringBuilder text = new StringBuilder();
- try {
- BufferedReader br = new BufferedReader(new FileReader(file));
- String line;
- while ((line = br.readLine()) != null) {
- text.append(line);
- text.append("n");
- }
- }
- catch (IOException e) {
- //You'll need to add proper error handling here
- }
- //Set the text
- Log.d("File text:", text.toString() );
- Toast.makeText(getApplicationContext(),"File Found", Toast.LENGTH_SHORT);
- }
- else
- {
- Log.d("Romek file:", "File not found" );
- Toast.makeText(getApplicationContext(),"File not Found", Toast.LENGTH_SHORT);
- }
- public boolean isExternalStorageWritable() {
- String state = Environment.getExternalStorageState();
- if (Environment.MEDIA_MOUNTED.equals(state)) {
- Log.d("Romek", "External Storage is writable");
- return true;
- }
- Log.d("Romek", "External Storage is not writable");
- return false;
- }
- /* Checks if external storage is available to at least read */
- public boolean isExternalStorageReadable() {
- String state = Environment.getExternalStorageState();
- if (Environment.MEDIA_MOUNTED.equals(state) ||
- Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
- Log.d("Romek", "External Storage is readable");
- return true;
- }
- Log.d("Romek", "External Storage is not readable");
- return false;
- }
Add Comment
Please, Sign In to add comment