Changes

Jump to: navigation, search
m
Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">"
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
Create a new project in Android Studio, entering AudioApp into the Application name field and ebookfrenzy.com as the Company Domain setting before clicking on the Next button.
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
On the form factors screen, enable the Phone and Tablet option and set the minimum SDK setting to API 8: Android 2.2 (Froyo). Continue to proceed through the screens, requesting the creation of an empty activity named AudioAppActivity with a corresponding layout resource file named activity_audio_app.
== Designing the User Interface ==
<googlehtmlet>ADSDAQBOX_FLOWadsdaqbox_flow</googlehtmlet>
Once the new project has been created, select the activity_audio_app.xml file from the Project tool window and, with the Designer tool in Design mode, select the “Hello world!” TextView and delete it from the layout. Drag and drop three Button views onto the layout. The positioning of the buttons is not of paramount importance to this example, though Figure 56-1 shows a suggested layout.
Configure the buttons to display string resources that read Play, Record and Stop and give them view IDs of recordButton, playButton, and stopButton respectively.
}
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
The added code begins by obtaining references to the three button views in the user interface. Next, the previously implemented hasMicrophone() method is called to ascertain whether the device includes a microphone. If it does not, all the buttons are disabled, otherwise only the Stop and Play buttons are disabled.
.
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
Next, a method needs to be added to the class, the purpose of which is to take as arguments the permission to be requested and the corresponding request identification code. Remaining with the AudioAppActivity.java class file, implement this method as follows:
}
</pre>
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
The above code checks the request identifier code to identify which permission request has returned before checking whether or not the corresponding permission was granted. In the event that permission was denied, a message is displayed to the user indicating the app will not function. In both instances, the record button is also disabled.
All that remains prior to testing the app is to call the newly added requestPermission() method for each of the required permissions when the app launches. Remaining in the AudioAppActivity.java file, modify the onCreate() method as follows:
<googlehtmlet>BUY_ANDROID_STUDIO6androidstudio_a6</googlehtmlet>
 
<htmlet>ezoicbottom</htmlet>
<hr>
<table border="0" cellspacing="0" width="100%">

Navigation menu