archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Setting up a Kindle Fire Android Development Environment - Techotopia
    32 bit or 64 bit and click on the download button Installing the ADT Bundle The ADT Bundle is downloaded as a compressed ZIP archive file which must be unpacked to complete the installation process The exact steps to achieve this differ depending on the operating system Installation on Windows Locate the downloaded ADT Bundle zip file in a Windows Explorer window right click on it and select the Extract All menu option In the resulting dialog choose a suitable location into which to unzip the file before clicking on the Extract button When choosing a suitable location keep in mind that the extraction will create a sub folder in the chosen location named either adt bundle windows x86 or adt bundle windows x86 64 containing the bundle packages Once the extraction is complete navigate in Windows Explorer to the directory containing the ADT bundle move into the eclipse sub folder and double click on the eclipse executable to start the Eclipse IDE environment For easier future access right click on the eclipse executable and select Pin to Taskbar from the resulting menu It is possible that Windows will display a Security Warning dialog before Eclipse will launch stating that the publisher could not be verified In the event that this warning appears uncheck the Always ask before opening this file option before clicking the Run button Once invoked Eclipse will prompt for the location of the workspace All projects will be stored by default into this folder Browse for a suitable location or choose the default offered by Eclipse and click on OK Installation on Mac OS X On Mac OS X systems open a terminal window change directory to the location where Eclipse is to be installed and execute the following command unzip path to package package name zip For example assuming a package file named adt bundle mac x86 64 zip has been downloaded to home demo Downloads the following command would be needed to install Eclipse unzip home demo Downloads adt bundle mac x86 64 zip Note that the bundle will be installed into a sub directory named adt bundle mac x86 64 Assuming therefore that the above command was executed in Users demo the software packages will be unpacked into Users demo adt bundle mac x86 64 Within this directory the files comprising the Eclipse IDE are installed in a sub directory named eclipse Using the Finder tool navigate to the eclipse sub directory of the ADT bundle installation directory and double click on the eclipse executable to launch the application For future easier access to the tool simply drag the eclipse icon from the Finder window and drop it onto the dock Installation on Linux On Linux systems open a terminal window change directory to the location where Eclipse is to be installed and execute the following command unzip path to package package name zip For example assuming a package file named adt bundle linux x86 zip has been downloaded to home demo Downloads the following command would be needed to install Eclipse unzip home demo Downloads adt bundle linux x86 zip Note that the bundle will be installed into a sub directory named either adt bundle linux x86 or adt bundle linux x86 64 depending on whether the 32 bit or 64 bit edition was downloaded Assuming therefore that the above command was executed in home demo the software packages will be unpacked into home demo adt bundle linux x86 Within this directory the files comprising the Eclipse IDE are installed in a sub directory named eclipse To launch Eclipse open a terminal window change directory to the eclipse sub directory of the ADT bundle installation directory and execute the following command eclipse Once invoked Eclipse will prompt for the location of the workspace All projects will be stored by default into this folder Browse for a suitable location or choose the default offered by Eclipse and click on OK Having verified that the Eclipse IDE is installed correctly keep Eclipse running so that it can be used to install additional Android and Kindle specific SDK packages Installing the Correct Android and Kindle Fire SDK Packages The steps performed so far have installed Java the Eclipse IDE and the current set of default Android SDK packages In order to develop applications for the Kindle Fire family of devices particular versions of the Android SDK packages need to be installed along with some Kindle Fire specific SDK packages This task can be performed using the Android SDK Manager which may be launched from within the Eclipse tool by selecting the Window Android SDK Manager menu option Once invoked the SDK Manager tool will appear as illustrated in Figure 3 1 Figure 3 1 Once the SDK Manager is running return to the main Eclipse window and select the File Exit menu option to exit from the Eclipse environment This will leave the Android SDK Manager running whilst ensuring that the Eclipse session does not conflict with the installation process Begin by checking that the SDK Path setting at the top of the SDK Manager window matches the location into which the ADT Bundle package was unzipped If it does not relaunch Eclipse and select the Window Preferences option In the Preferences dialog select the Android option from the left hand panel and change the SDK Location setting so that it references the sdk sub folder of the directory into which the ADT Bundle was unzipped before clicking on Apply followed by OK The ultimate goal at this point is to download and install the SDK packages needed for Kindle Fire development Most of these will be downloaded from the standard Google repository servers A few packages however will need to be downloaded direct from Amazon In order to make this possible a new Add on Site needs to be added to the list of sites in the manager To achieve this select the Tools Manage Add on Sites menu option In the resulting window select the User Defined Sites tab as illustrated in Figure 3 2 Figure 3 2 Click on the New button and enter the following URL into the resulting dialog http kindle sdk s3 amazonaws com addon xml Click OK to close the dialog make sure the URL is now listed under User Defined Sites and then click Close The main SDK Manager window should now list Extras options to install the Kindle Fire Device Definitions and the Kindle Fire USB Driver packages At the time of writing Kindle Fire application development is performed using the Android 2 2 3 API Level 10 and Android 4 0 3 API level 15 SDKs The current versions supported by the Kindle Fire device family can be identified by referring to the following web page https developer amazon com sdk fire setup html For the purposes of this tutorial the assumption is made that Android 4 0 3 is still the current release for newer Kindle Fire models Within the Android SDK Manager make sure that the check boxes next to the following packages are selected Tools Android SDK Tools Rev 21 Tools Android SDK Platform tools Rev 16 SDK Platform Android 4 0 3 API 15 SDK Platform SDK Platform Android 4 0 3 API 15 ARM EABI v7a System Image SDK Platform Android 4 0 3 API 15 Kindle Fire 2nd Generation SDK Platform Android 4 0 3 API 15 Kindle Fire HD 7 SDK Platform Android 4 0 3 API 15 Kindle Fire HD 8 9 SDK Platform Android 2 3 3 API 10 SDK Platform SDK Platform Android 2 3 3 API 10 Kindle Fire Extras Kindle Fire USB Driver Not applicable for Mac OS X or Linux Extras Kindle Fire Device Definitions Extras Android Support Library With the appropriate package selections made click on the Install packages button to initiate the installation process In the resulting dialog accept the license agreements before clicking on the Install button The SDK Manager will then begin to download and install the designated packages As the installation proceeds a progress bar will appear at the bottom of the manager window indicating the status of the installation as illustrated in Figure 3 3 Figure 3 3 Once the installation is complete review the package list and make sure that the selected packages are now listed as Installed in the Status column If any are listed as Not installed usually the Kindle Fire specific packages need to be installed separately from the generic Android packages make sure they are selected and click on the Install packages button again Making the Android SDK Tools Command line Accessible Most of the time the underlying tools of the Android SDK will be accessed from within the Eclipse environment That being said however there will also be instances where it will be useful to be able to invoke those tools from a command prompt or terminal window In order for the operating system on which you are developing to be able to find these tools it will be necessary to add them to the system s PATH environment variable Regardless of operating system the PATH variable needs to be configured to include the following paths where path to adt installation represents the file system location into which the ADT bundle was installed path to adt installation sdk tools path to adt installation sdk platform tools The steps to achieve this are operating system dependent Windows 7 1 Right click on Computer in the desktop start menu and select Properties from the resulting menu 2 In the properties panel select the Advanced System Settings link and in the resulting dialog click on the Environment Variables button 3 In the Environment Variables dialog locate the Path variable in the System variables list select it and click on Edit Locate the end of the current variable value string and append the path to the android platform tools to the end using a semicolon to separate the path from the preceding values For example assuming the ADT bundle was installed into Users demo adt bundle windows x86 64 the following would be appended to the end of the current Path value C Users demo adt bundle windows x86 64 sdk platform tools C Users demo adt bundle windows x86 64 sdk tools 4 Click on OK in each dialog box and close the system properties control panel Once the above steps are complete verify that the path is correctly set by opening a Command Prompt window Start All Programs Accessories Command Prompt and at the prompt enter echo Path The returned path variable value should include the paths to the Android SDK platform tools folders Verify that the platform tools value is correct by attempting to run the adb tool as follows adb The tool should output a list of command line options when executed Similarly check the tools path setting by attempting to launch the Android SDK Manager android In the event that a message similar to following message appears for one or both of the commands it is most likely that an incorrect path was appended to the Path environment variable adb is not recognized as an internal or external command operable program or batch file Windows 8 1 On the start screen move the mouse to the bottom right hand corner of the screen and select Search from the resulting menu In the search box enter Control Panel When the Control Panel icon appears in the results area click on it to launch the tool on the desktop 2 Within the Control Panel use the Category menu to change the display to Large Icons From the list of icons select the one labeled System 3 Follow the steps outlined for Windows 7 starting from step 2 Adding the ADT Plugin to an Existing Eclipse Integration The steps outlined so far in this chapter have assumed that the Eclipse IDE is not already installed on your system In the event that you are already using Eclipse for Java based development the appropriate Android development tools and SDKs can be added to this existing Eclipse installation Eclipse editions with which the ADT Plugin is compatible are as follows Eclipse IDE for Java Developers Eclipse Classic versions 3 5 1 and higher Eclipse IDE for Java EE Developers Eclipse for Mobile Developers The ADT Plugin for Eclipse adds a range of Android specific features to what is otherwise a general purpose Java edition of the Eclipse environment To install this plugin launch Eclipse and select the Help Install New Software menu option In the resulting window click on the Add button to display the Add Repository dialog Enter ADT Plugin into the Name field and the following URL into the Location field https dl ssl google com android eclipse Click on the OK button and wait while Eclipse connects to the Android repository Once the information has been downloaded new items will be listed entitled Developer Tools and NDK Plugins as illustrated in Figure 3 4 Figure 3 4 Select the checkbox next to the Developer Tools entry and click on the Next button After requirements and dependencies have been calculated by the installer a more detailed list of the packages to be installed will appear Once again click on the Next button to proceed On the subsequent licensing page select the option to accept the terms of the agreements assuming that you do indeed agree and click on Finish to complete the installation During the download and installation process you may be prompted to confirm that you wish to install unsigned content In the event that this happens simply click on the option to proceed with the installation When the ADT Plugin installation is complete a dialog will appear providing the option to restart Eclipse in order to complete the installation Click on Yes and wait for the tool to exit and re launch Upon restarting the Welcome to Android Development dialog will appear as illustrated in Figure 3 5 Figure 3 5 At this stage there is no existing SDK installed so the Use Existing SDKs choice is not a viable option Unfortunately the ADT Plugin does not provide the option at this point to install the SDKs of our choice so we will need to install the latest available SDK versions and then manually install the ones we actually need for Kindle Fire development With this in mind select the option to install the latest available version of the Android APIs Make a note of the Target Location path and change it if you prefer the SDKs to be installed in a different location then click Next Choose whether to send usage information to Google accept all the licensing terms and click on Install The Android SDK Manager will now download and install the latest Android SDKs Once this process is complete follow the steps outlined in the earlier section entitled Installing the Correct Android and Kindle SDK Packages to install the appropriate Android and Amazon packages for Kindle development At this point the Eclipse environment is ready to begin the development of Android applications for the Kindle Fire family of devices Mac OS X A number of techniques may be employed to modify the PATH environment variable on Mac OS X Arguably the cleanest method is to add a new file in the etc paths d directory containing the paths to be added to PATH Assuming an installation location of Users demo adt bundle mac x86 64 the path may be configured by creating a new file named android sdk in the etc paths d directory containing the following lines Users demo adt bundle mac x86 64 sdk tools Users demo adt bundle mac x86 64 sdk platform tools Note that since this is a system directory it will be necessary to use the sudo command when creating the file For example sudo vi etc paths d android sdk Windows 8 1 On the start screen move the mouse to the bottom right hand corner of the screen and select Search from the resulting menu In the search box enter Control Panel When the Control Panel icon appears in the results area click on it to launch the tool on the desktop 2 Within the Control Panel use the Category menu to change the display to Large Icons From the list of icons select the one labeled System 3 Follow the steps outlined for Windows 7 starting from step 2 Adding the ADT Plugin to an Existing Eclipse Integration The steps outlined so far in this chapter have assumed that the Eclipse IDE is not already installed on your system In the event that you are already using Eclipse for Java based development the appropriate Android development tools and SDKs can be added to this existing Eclipse installation Eclipse editions with which the ADT Plugin is compatible are as follows Eclipse IDE for Java Developers Eclipse Classic versions 3 5 1 and higher Eclipse IDE for Java EE Developers Eclipse for Mobile Developers The ADT Plugin for Eclipse adds a range of Android specific features to what is otherwise a general purpose Java edition of the Eclipse environment To install this plugin launch Eclipse and select the Help Install New Software menu option In the resulting window click on the Add button to display the Add Repository dialog Enter ADT Plugin into the Name field and the following URL into the Location field https dl ssl google com android eclipse Click on the OK button and wait while Eclipse connects to the Android repository Once the information has been downloaded new items will be listed entitled Developer Tools and NDK Plugins as illustrated in Figure 3 4 Figure 3 4 Select the checkbox next to the Developer Tools entry and click on the Next button After requirements and dependencies have been calculated by the installer a more detailed list of the packages to be installed will appear Once again

    Original URL path: http://www.techotopia.com/index.php/Setting_up_a_Kindle_Fire_Android_Development_Environment (2016-02-13)
    Open archived version from archive


  • Creating an Example Kindle Fire Android Application - Techotopia
    the chapter entitled Creating a Kindle Fire Android Virtual Device AVD simply right click on the application name in the Package Explorer and select Run As Android Application from the resulting menu If at this point more than one AVD emulator has been configured on the system a window will appear providing the option to select which AVD environment the application will run in If multiple AVDs are listed select the Kindle Fire emulator created in the earlier chapter In the event that only one AVD is available Eclipse will automatically launch that virtual device The AVD window typically appears immediately but a delay may be encountered as the emulator starts up and loads the Android operating system Once the operating system has loaded the example application will run and appear within the emulator as shown in Figure 5 8 Figure 5 8 In the event that the activity does not automatically launch check to see if the launch icon has appeared on the emulator screen If it has simply click on it to launch the application When the application has launched an additional window may appear asking whether or not LogCat messages should be monitored When an application is running a range of diagnostic messages is output by the system In addition the application developer may have included diagnostic messages into the application code It is generally recommended therefore that monitoring of these messages be enabled Assuming that the application loads into the emulator and runs as expected we have safely verified that the Android development environment is correctly installed and configured Stopping a Running Application When building and running an application for testing purposes each time a new revision of the application is compiled and run the previous instance of the application running on the device or emulator will be terminated automatically and replaced with the new version It is also possible to manually stop a running application from within the Eclipse environment To stop a running application begin by displaying the Eclipse DDMS perspective DDMS stands for Dalvik Debug Monitor Server The default configuration for Eclipse is to launch showing the Java perspective and for a button to be located in the top right hand corner of the main Eclipse screen Figure 5 9 that allows the DDMS perspective to be displayed Figure 5 9 In the event that this button is not present the perspective may be displayed using the Window Open Perspective DDMS menu option Once selected the DDMS perspective will appear as illustrated in Figure 5 10 Figure 5 10 The left hand panel entitled devices lists any devices or emulators to which the development environment is attached Under each device is a list of processes currently running on that device or emulator instance Figure 5 11 for example shows the Devices panel with the KindleTest application running Figure 5 11 To terminate the KindleTest application select the process from the list and click on the red Stop button located in the Device panel toolbar To return to the main Java development perspective simply click on the Java button in the Eclipse toolbar Modifying the Example Application The next step in this tutorial is to modify the user interface of our application so that it displays a larger text view object with a different message to the one provided for us by Eclipse The user interface design for our activity is stored in a file named activity kindle test xml which in turn is located under res layout in the project workspace Using the Package Explorer panel locate this file as illustrated in Figure 5 12 Figure 5 12 Once located double click on the file to load it into the user interface builder tool which in turn will appear in the center panel of the Eclipse main window Figure 5 13 In the toolbar across the top of the layout editor panel is a menu that is currently set to Nexus One Since we are designing a layout for the screen of a Kindle Fire device change this menu to one of the Kindle Fire options For example click on the menu and select the Amazon Kindle Fire HD 7 800 x 1280 hdpi menu option The visual representation of the device screen will subsequently change to reflect the dimensions of the Kindle Fire HD 7 device To change the orientation between landscape and portrait simply use the drop down menu immediately to the right of the device selection menu In the center of the panel is the graphical representation of the user interface design now within the context of the Kindle Fire HD 7 device As can be seen this includes the label that displays the Hello World message Running down the left hand side of the panel is a palette containing different categories of user interface components that may be used to construct a user interface such as buttons labels and text fields It should be noted however that not all user interface components are obviously visible to the user One such category consists of layouts Android supports a variety of different layouts that provide different levels of control over how visual user interface components are positioned and managed on the screen Though it is difficult to tell from looking at the visual representation of the user interface the current design has been created using a RelativeLayout This can be confirmed by reviewing the information in the Outline panel that by default is located on the upper right hand side of the Eclipse main window and is shown in Figure 5 14 Figure 5 14 As we can see from the outline the user interface consists of a RelativeLayout parent that has as a child the TextView object The first step in modifying the application is to delete the TextView component from the design Begin by clicking on the TextView object within the user interface view so that it appears with a blue border around it Once selected press the Delete

    Original URL path: http://www.techotopia.com/index.php/Creating_an_Example_Kindle_Fire_Android_Application (2016-02-13)
    Open archived version from archive

  • Testing Android Applications on a Physical Kindle Fire Device - Techotopia
    SDK was installed in Setting up a Kindle Fire Android Development Environment cd sdk location extras amazon kindle fire usb driver Having changed directory execute the following command KindleDrivers After a short delay the Kindle Fire USB Drivers Setup tool will appear as shown in Figure 6 1 Figure 6 1 Verify that the default Destination Folder is acceptable before clicking on the Install button to initiate the driver installation process The installation wizard will subsequently perform the driver installation Once the installation is complete click Finish in the wizard dialog then close the setup window With the drivers installed attach the device to the computer Open the Control Panel change the Category menu to large icons and click on the Device Manager entry In the device manager there will be an entry listed as Kindle Fire which when unfolded will list Android Composite ADB Interface Figure 6 2 Within the Command Prompt window execute the following commands to restart the ADB server adb kill server adb start server Finally verify that the Kindle Fire device has been detected adb devices List of devices attached 74CE000600000001 device As long as the device is listed the environment is ready to test applications on the actual Kindle Fire device In the event that the device is not listed try executing the following command android update adb It may also be necessary to reboot the system Linux Kindle Fire adb Configuration For the purposes of this chapter we will once again use Ubuntu Linux as a reference example in terms of configuring adb on Linux to connect to a physical Kindle Fire device for application testing Begin by attaching the Kindle Fire device to a USB port on the Ubuntu Linux system Once connected open a Terminal window and execute the Linux lsusb command to list currently available USB devices lsusb Bus 001 Device 003 ID 1949 0006 Lab126 Bus 001 Device 001 ID 1d6b 0001 Linux Foundation 1 1 root hub The device we are interested in is the one listed as Lab126 which is the name of the Amazon com group originally set up to develop hardware devices Make a note of the vendor and product ID numbers in the above case these are 1949 and 0006 respectively Use the sudo command to edit the 51 android rules file located in the etc udev rules d directory For example sudo gedit etc udev rules d 51 android rules Within the editor add the appropriate entry for the Kindle Fire device referencing the vendor and product IDs returned previously by the lsusb command SUBSYSTEM usb ATTR idVendor 1949 ATTRS idProduct 0006 MODE 0660 OWNER root GROUP androidadb SYMLINK android n Once the entry has been added save the file and exit from the editor Next use an editor to modify or create if it does not yet exist the adb usb ini file gedit android adb usb ini Once the file is loaded into the editor add the following lines before saving

    Original URL path: http://www.techotopia.com/index.php/Testing_Android_Applications_on_a_Physical_Kindle_Fire_Device_with_ADB (2016-02-13)
    Open archived version from archive

  • An Overview of the Kindle Fire Android Architecture - Techotopia
    virtual machine was developed by Google and relies on the underlying Linux kernel for low level functionality It is more efficient than the standard Java VM in terms of memory usage and specifically designed to allow multiple instances to run efficiently within the resource constraints of a mobile device In order to execute within a Dalvik VM application code must be transformed from standard Java class files to the Dalvik executable dex format which has a 50 smaller memory footprint than standard Java bytecode Standard Java class files can usually though not always be converted to Dex format using the dx tool included with the Android SDK Android Runtime Core Libraries The Android Core Libraries also referred to as the Dalvik Libraries fall into three main categories each of which merits an individual description Dalvik VM Specific Libraries This is a set of libraries used predominantly for interacting directly with an instance of the Dalvik VM and are unlikely to be used by most Android application developers Java Interoperability Libraries Android applications are predominantly developed using the Java programming language The Standard Java development environment includes a vast array classes that are contained in the core Java runtime libraries These libraries provide support for tasks such as string handling networking and file manipulation to name but a few and are both familiar and widely used by Java developers regardless of platform The Java Interoperability Libraries are an open source implementation based on the Apache Harmony project of a subset of the standard Java core libraries that have been adapted and transformed for use by applications running within a Dalvik VM Android Libraries This category encompasses those Java based libraries that are specific to Android development Examples of libraries in this category include the application framework libraries in addition to those that facilitate user interface building graphics drawing and database access A summary of some key core Android libraries available to the Kindle Fire developer is as follows android app Provides access to the application model and is the cornerstone of all Android applications android content Facilitates the content access publishing and messaging between applications and application components android database Used to access data published by content providers and includes SQLite database management classes android graphics A low level 2D graphics drawing API including colors points filters rectangles and canvases android hardware Presents an API providing access to hardware such as the accelerometer and light sensor android opengl A Java interface to the OpenGL ES 3D graphics rendering API android os Provides applications with access to standard operating system services including messages system services and inter process communication android media Provides classes to enable playback of audio and video android net A set of APIs providing access to the network stack Includes android net wifi which provides access to the device s wireless stack android provider A set of convenience classes that provide access to standard Android content provider databases such as those maintained by the calendar and contact applications android

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_the_Kindle_Fire_Android_Architecture (2016-02-13)
    Open archived version from archive

  • Creating and Managing Android Overflow Menus on the Kindle Fire - Techotopia
    Menu Item Selections Once a menu has been implemented the question arises as to how the application receives notification when the user makes menu item selections All that an activity needs to do to receive menu selection notifications is to override the onOptionsItemSelected method Passed as an argument to this method is a reference to the selected menu item The getItemId method may then be called on the item to obtain the ID which may in turn be used to identify which item was selected For example Override public boolean onOptionsItemSelected MenuItem item switch item getItemId case R id menu red Red item was selected return true case R id menu green Green item was selected return true default return super onOptionsItemSelected item Creating Checkable Item Groups In addition to configuring independent menu items it is also possible to create groups of menu items This is of particular use when creating checkable menu items whereby only one out of a number of choices can be selected at any one time Menu items can be assigned to a group by wrapping then in the group tag The group is declared as checkable using the android checkableBehavior property setting the value to either single all or none The following XML declares that two menu items make up a group wherein only one item may selected at any given time menu xmlns android http schemas android com apk res android group android checkableBehavior single item android id id menu red android orderInCategory 1 android showAsAction never android title string red string item android id id menu green android orderInCategory 2 android showAsAction never android title string green string group menu When a menu group is configured to be checkable a small circle appears next to the item in the menu as illustrated in Figure 22 4 It is important to be aware that the setting and unsetting of this indicator does not take place automatically It is therefore the responsibility of the application to check and uncheck the menu item Figure 22 4 Continuing the color example used previously in this chapter this would be implemented as follows Override public boolean onOptionsItemSelected MenuItem item switch item getItemId case R id menu red if item isChecked item setChecked false else item setChecked true mainLayout setBackgroundColor android graphics Color RED return true case R id menu green if item isChecked item setChecked false else item setChecked true mainLayout setBackgroundColor android graphics Color GREEN return true default return super onOptionsItemSelected item Creating the Example Project To see the overflow menu in action begin by launching Eclipse and creating a new Android application project Name the application and project MenuExample with a package name of com example menuexample Create the project with a blank activity named MenuExampleActivity and a layout named activity menu example When the project has been created the Graphical Layout tool should appear with the user interface layout displayed Right click on the background of the layout the area representing the RelativeLayout view and

    Original URL path: http://www.techotopia.com/index.php/Creating_and_Managing_Android_Overflow_Menus_on_the_Kindle_Fire (2016-02-13)
    Open archived version from archive

  • Implementing an Android Content Provider - Techotopia
    all that needs to be performed is for an instance of the MyDBHandler class implemented in An Android SQLite Database Tutorial to be created Once this instance has been created it will need to be accessible from the other methods in the class so a declaration for the database handler also needs to be declared resulting in the following code changes to the ContentProvider java file package com example database provider import com example database MyDBHandler import android content ContentValues import android database Cursor import android net Uri import android content UriMatcher import android database sqlite SQLiteDatabase import android database sqlite SQLiteQueryBuilder import android text TextUtils public class ContentProvider extends android content ContentProvider private MyDBHandler myDB private static final String AUTHORITY com example database provider ContentProvider private static final String PRODUCTS TABLE products public static final Uri CONTENT URI Uri parse content AUTHORITY PRODUCTS TABLE public static final int PRODUCTS 1 public static final int PRODUCTS ID 2 Override public boolean onCreate myDB new MyDBHandler getContext null null 1 return false Implementing the Content Provider insert Method When a client application or activity requests that data be inserted into the underlying database the insert method of the content provider class will be called At this point however all that exists in the ContentProvider java file of the project is a stub method which reads as follows Override public Uri insert Uri arg0 ContentValues arg1 TODO Auto generated method stub return null Passed as arguments to the method are a URI specifying the destination of the insertion and a ContentValues object containing the data to be inserted This method now needs to be modified to perform the following tasks Use the sUriMatcher to identify the URI type Throw an exception if the URI is not valid Obtain a reference to a writable instance of the underlying SQLite database Perform a SQL insert operation to insert the data into the database table Notify the corresponding content resolver that the database has been modified Return the URI of the newly added table row Bringing these requirements together results in a modified insert method which reads as follows note also that the argument names have been changed from arg0 and arg1 to names that are more self explanatory Override public Uri insert Uri uri ContentValues values int uriType sURIMatcher match uri SQLiteDatabase sqlDB myDB getWritableDatabase long id 0 switch uriType case PRODUCTS id sqlDB insert MyDBHandler TABLE PRODUCTS null values break default throw new IllegalArgumentException Unknown URI uri getContext getContentResolver notifyChange uri null return Uri parse PRODUCTS TABLE id Implementing the Content Provider query Method When a content provider is called upon to return data the query method of the provider class will be called When called this method is passed some or all of the following arguments URI The URI specifying the data source on which the query is to be performed This can take the form of a general query with multiple results or a specific query targeting the ID of a single table row Projection A row within a database table can comprise multiple columns of data In the case of this application for example these correspond to the ID product name and product quantity The projection argument is simply a String array containing the name for each of the columns that is to be returned in the result data set Selection The where element of the selection to be performed as part of the query This argument controls which rows are selected from the specified database For example if the query was required to select only products named Cat Food then the selection string passed to the query method would read productname Cat Food Selection Args Any additional arguments that need to be passed to the SQL query operation to perform the selection Sort Order The sort order for the selected rows When called the query method is required to perform the following operations Use the sUriMatcher to identify the Uri type Throw an exception if the URI is not valid Construct a SQL query based on the criteria passed to the method For convenience the SQLiteQueryBuilder class can be used in construction of the query Execute the query operation on the database Notify the content resolver of the operation Return a Cursor object containing the results of the query With these requirements in mind the code for the query method in the ContentProvider java file should now read as outlined in the following listing Override public Cursor query Uri uri String projection String selection String selectionArgs String sortOrder SQLiteQueryBuilder queryBuilder new SQLiteQueryBuilder queryBuilder setTables MyDBHandler TABLE PRODUCTS int uriType sURIMatcher match uri switch uriType case PRODUCTS ID queryBuilder appendWhere MyDBHandler COLUMN ID uri getLastPathSegment break case PRODUCTS break default throw new IllegalArgumentException Unknown URI Cursor cursor queryBuilder query myDB getReadableDatabase projection selection selectionArgs null null sortOrder cursor setNotificationUri getContext getContentResolver uri return cursor Implementing the Content Provider update Method The update method of the content provider is called when changes are being requested to existing database table rows The method is passed a URI the new values in the form of a ContentValues object and the usual selection argument strings When called the update method would typically perform the following steps Use the sUriMatcher to identify the URI type Throw an exception if the URI is not valid Obtain a reference to a writable instance of the underlying SQLite database Perform the appropriate update operation on the database depending on the selection criteria and the URI type Notify the content resolver of the database change Return a count of the number of rows that were changed as a result of the update operation A general purpose update method and the one we will use for this project would read as follows public int update Uri uri ContentValues values String selection String selectionArgs int uriType sURIMatcher match uri SQLiteDatabase sqlDB myDB getWritableDatabase int rowsUpdated 0 switch uriType case PRODUCTS rowsUpdated sqlDB update MyDBHandler TABLE PRODUCTS values selection selectionArgs break case

    Original URL path: http://www.techotopia.com/index.php/Implementing_an_Android_Content_Provider (2016-02-13)
    Open archived version from archive

  • Video Recording and Image Capture on the Kindle Fire using Camera Intents - Techotopia
    38 1 will launch and provide the user the opportunity to record video Figure 38 1 Calling the Image Capture Intent In addition to the video capture intent the Android implementation running on the Kindle Fire also includes an intent designed for taking still photos using the built in camera This intent is launched by referencing MediaStore ACTION IMAGE CAPTURE private static final int IMAGE CAPTURE 102 Intent intent new Intent MediaStore ACTION IMAGE CAPTURE startActivityForResult intent IMAGE CAPTURE As with video capture the intent may be passed the location and file name into which the image is to be stored or left to use the default location and naming convention Creating an Example Video Recording Project In the remainder of this chapter a very simple application will be created to demonstrate the use of the video capture intent The application will consist of a single button which when touched by the user will launch the video capture intent Once video has been recorded and the video capture intent dismissed the application will simply display the path to the video file as a Toast message The VideoPlayer application created in the previous chapter will then be modified to play back the recorded video Begin the application creation process by launching Eclipse and creating a new Android Application project named CameraApp using the appropriate Android SDK versions and package name and including a blank activity named CameraAppActivity with a corresponding layout named activity camera app Designing the User Interface Layout Within the Graphical Layout tool delete the default Hello World text view and replace it with a Button view positioned in the center of the display canvas Change the text on the button to read Record Video and assign an onClick property to the button so that it calls a method named startRecording when selected by the user Figure 38 2 Finally change the ID of the button to recordButton The corresponding XML in the activity camera app xml file should approximately resemble the following listing RelativeLayout xmlns android http schemas android com apk res android xmlns tools http schemas android com tools android layout width match parent android layout height match parent android paddingBottom dimen activity vertical margin android paddingLeft dimen activity horizontal margin android paddingRight dimen activity horizontal margin android paddingTop dimen activity vertical margin tools context CameraAppActivity Button android id id recordButton android layout width wrap content android layout height wrap content android layout centerHorizontal true android layout centerVertical true android onClick startRecording android text string button string RelativeLayout Save the layout file before proceeding Checking for the Camera Before attempting to launch the video capture intent the application first needs to verify that the device on which it is running actually has a camera Given that this application is targeting the Kindle Fire family of devices this check needs to look for a front facing camera For the purposes of this example we will simply make use of the previously outlined hasCamera method In the event that

    Original URL path: http://www.techotopia.com/index.php/Video_Recording_and_Image_Capture_on_the_Kindle_Fire_using_Camera_Intents (2016-02-13)
    Open archived version from archive

  • Kindle Fire Audio Recording and Playback using MediaPlayer and MediaRecorder - Techotopia
    a very simple interface intended to allow the user to record and playback audio The recorded audio will need to be stored within an audio file on the device That being the case this tutorial will also briefly explore the mechanism for using SD Card storage Creating the AudioApp Project Launch Eclipse and create a new Android Application project named AudioApp using the appropriate Android SDK versions and package name and including a blank activity named AudioAppActivity with a corresponding layout named activity audio app Designing the User Interface Once the new project has been created Eclipse should display the user interface layout associated with the activity audio app xml file Within the Graphical Layout tool 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 39 1 shows a suggested layout Configure the buttons to display string resources that read Record Play and Stop and give them view IDs of recordButton playButton and stopButton respectively Figure 39 1 Right click on the Play button and select the Other Properties All by Name OnClick menu option to configure the button to call a method named playAudio when selected by the user Repeat these steps to configure the remaining buttons to call methods named recordAudio and stopRecording respectively Once the user interface design phase is complete save the file Checking for Microphone Availability Attempting to record audio on a device without a microphone will cause the Android system to throw an exception It is vital therefore that the code check for the presence of a microphone before making such an attempt There are a number of ways of doing this including checking for the physical presence of the device An easier approach and one that is more likely to work on different Android devices is to ask the Android system if it has a package installed for a particular feature This involves creating an instance of the Android PackageManager class and then making a call to the object s hasSystemFeature method In this case the feature of interest is PackageManager FEATURE MICROPHONE For the purposes of this example we will create a method named hasMicrophone that may be called upon to check for the presence of a microphone Within the Package Explorer panel locate and double click on the AudioAppActivity java file and modify it to add this method package com example audioapp import android os Bundle import android app Activity import android content pm PackageManager import android view Menu public class AudioAppActivity extends Activity Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity audio app protected boolean hasMicrophone PackageManager pmanager this getPackageManager return pmanager hasSystemFeature PackageManager FEATURE MICROPHONE Performing the Activity Initialization The next step is to modify the onCreate method of the activity to perform a number of initialization tasks Remaining within the AudioAppActivity java file modify the method as

    Original URL path: http://www.techotopia.com/index.php/Kindle_Fire_Audio_Recording_and_Playback_using_MediaPlayer_and_MediaRecorder (2016-02-13)
    Open archived version from archive



  •