Guest User

Untitled

a guest
Jan 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  4. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  5.  
  6. <application
  7. android:allowBackup="true"
  8. android:icon="@mipmap/ic_launcher"
  9. android:label="@string/app_name"
  10. android:supportsRtl="true"
  11. android:theme="@style/AppTheme">
  12. <activity android:name=".MainActivity">
  13. <intent-filter>
  14. <action android:name="android.intent.action.MAIN" />
  15.  
  16. <category android:name="android.intent.category.LAUNCHER" />
  17. </intent-filter>
  18. </activity>
  19. <activity android:name=".RecipeActivity"></activity>
  20. </application>
  21.  
  22. File dir = Environment.getExternalStorageDirectory();
  23.  
  24. File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "receip.txt");
  25. if(file.exists()) // check if file exist
  26. {
  27. //Read text from file
  28. StringBuilder text = new StringBuilder();
  29.  
  30. try {
  31. BufferedReader br = new BufferedReader(new FileReader(file));
  32. String line;
  33.  
  34. while ((line = br.readLine()) != null) {
  35. text.append(line);
  36. text.append("n");
  37. }
  38. }
  39. catch (IOException e) {
  40. //You'll need to add proper error handling here
  41. }
  42. //Set the text
  43. Log.d("File text:", text.toString() );
  44. Toast.makeText(getApplicationContext(),"File Found", Toast.LENGTH_SHORT);
  45. }
  46. else
  47. {
  48. Log.d("Romek file:", "File not found" );
  49. Toast.makeText(getApplicationContext(),"File not Found", Toast.LENGTH_SHORT);
  50. }
  51.  
  52. public boolean isExternalStorageWritable() {
  53. String state = Environment.getExternalStorageState();
  54. if (Environment.MEDIA_MOUNTED.equals(state)) {
  55. Log.d("Romek", "External Storage is writable");
  56. return true;
  57. }
  58. Log.d("Romek", "External Storage is not writable");
  59. return false;
  60. }
  61.  
  62. /* Checks if external storage is available to at least read */
  63. public boolean isExternalStorageReadable() {
  64. String state = Environment.getExternalStorageState();
  65. if (Environment.MEDIA_MOUNTED.equals(state) ||
  66. Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
  67. Log.d("Romek", "External Storage is readable");
  68. return true;
  69. }
  70. Log.d("Romek", "External Storage is not readable");
  71. return false;
  72. }
Add Comment
Please, Sign In to add comment