Changes

Jump to: navigation, search

An Android Studio Storage Access Framework Example

83 bytes removed, 18:37, 20 January 2015
no edit summary
Create a new project in Android Studio, entering StorageDemo into the Application name field and ebookfrenzy.com as the Company Domain setting before clicking on the Next button.
On the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting to API 19: Android 4.4 (KitKat). Continue to proceed through the screens, requesting the creation of a blank activity named StorageDemoActivity with a corresponding layout named activity_storage_demoand a menu resource file named menu_storage_demo.
== Designing the User Interface ==
The user interface will need to be comprised of three Button views and a single EditText view. Within the Project tool window, navigate to the activity_storage_demo.xml layout file located in StorageDemo -> app -> src -> main -> res -> layout and double click on it to load it into the Designer tool. With the tool in Design mode, select and delete the Hello World! TextView object.
Switch the Designer tool to Text mode and remove the padding elements from the file so that it now reads as outlined in the following listing:
[[Image:android_studio_storage_framework_uiandroid_studio_storage_framework_ui2.png|The user interface for an Android Studio Storage Access Framework tutorial]]
Figure 47-1
[[Image:android_studio_storage_framework_saveandroid_studio_storage_framework_save2.png|Saving a file using the the Android Storage Access Framework picker]]
Figure 47-2
From this menu select the Drive option followed by My Drive and navigate to a suitable location on your Google Drive storage into which to save the file. In the text field at the bottom of the picker interface change the name from “newfile.txt” to a suitable name (but keeping the .txt extension) before selecting the Save option.
Once the new file has been created, the app should return to the main activity and a notification will appear along within the top of the screen that notifications panel which reads “Uploading 1 file”“1 file uploaded”:
[[Image:android_studio_storage_uploadingandroid_studio_storage_uploading2.png|The Android Storage Access Framework uploading a file to a storage service]]
Figure 47-3
 
Once the upload is complete, a second notification will appear confirming that the file has been uploaded.
At this point it should be possible to log into your Google Drive account in a browser window and find the newly created file in the requested location (in the event that the file is missing, make sure that the Android device on which the application is running has an active internet connection). Access to Google Drive on the device may also be verified by running the Google Drive app which is installed by default on many Android devices and available for download from the Google Play store.

Navigation menu