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".
  • Making Runtime Permission Requests in Android 6.0 - Techotopia
    denied message Edit the AndroidManifest xml file located in the Project tool window under app manifests and add a line to request recording permission as follows xml version 1 0 encoding utf 8 manifest xmlns android http schemas android com apk res android package com ebookfrenzy permissiondemoactivity uses permission android name android permission RECORD AUDIO application android allowBackup true android icon mipmap ic launcher android label string app name android supportsRtl true android theme style AppTheme activity android name PermissionDemoActivity intent filter action android name android intent action MAIN category android name android intent category LAUNCHER intent filter activity application manifest Compile and run the app once again and note that this time the permission denial message does not appear Clearly everything that need to be done to request this permission on older versions of Android has been done Run the app on a device or emulator running Android 6 0 or later however and note that even though permission has been added to the manifest file the check still reports that permission has been denied This is because Android 6 requires that the app also request dangerous permissions at runtime Requesting Permission at Runtime A permission request is made via a call to the requestPermissions method of the ActivityCompat class When this method is called the permission request is handled asynchronously and a method named onRequestPermissionsResult called when the task is completed The requestPermissions method takes as arguments a reference to the current activity together with the identifier of the permission being requested and a request code The request code can be any integer value and will be used to identify which request has triggered the call to the onRequestPermissionsResult method Modify the PermissionDemoActivity java file to declare a request code and request recording permission in the event that the permission check failed package com ebookfrenzy permissiondemoactivity import android Manifest import android content pm PackageManager import android support v4 content ContextCompat import android support v7 app AppCompatActivity import android os Bundle import android util Log import android support v4 app ActivityCompat public class PermissionDemoActivity extends AppCompatActivity private static String TAG PermissionDemo private static final int RECORD REQUEST CODE 101 Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity permission demo int permission ContextCompat checkSelfPermission this Manifest permission RECORD AUDIO if permission PackageManager PERMISSION GRANTED Log i TAG Permission to record denied makeRequest protected void makeRequest ActivityCompat requestPermissions this new String Manifest permission RECORD AUDIO RECORD REQUEST CODE eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Next implement the onRequestPermissionsResult method so that it reads as follows Override public void onRequestPermissionsResult int requestCode String permissions int grantResults switch requestCode case RECORD REQUEST CODE if grantResults length 0 grantResults 0 PackageManager PERMISSION GRANTED Log i TAG Permission has been denied by user else

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


  • Android 6 Audio Recording and Playback using MediaPlayer and MediaRecorder - Techotopia
    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 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 Figure 56 1 Select the Play button and within the Properties panel configure the onClick property 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 stopAudio respectively 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 Project tool window locate and double click on the AudioAppActivity java file and modify it to add this method package com ebookfrenzy audioapp import android support v7 app AppCompatActivity import android os Bundle import android content pm PackageManager public class AudioAppActivity extends AppCompatActivity 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 follows package com ebookfrenzy audioapp import java io IOException import android support v7 app AppCompatActivity import android os Bundle import android content pm PackageManager import android media MediaRecorder import android os Environment import android widget Button import android view View import android media MediaPlayer public class AudioAppActivity extends AppCompatActivity private static MediaRecorder mediaRecorder private static MediaPlayer mediaPlayer private static String audioFilePath private static Button stopButton private static Button playButton private static Button recordButton private boolean isRecording false Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity audio app recordButton Button findViewById R id recordButton playButton Button findViewById R id playButton stopButton Button findViewById R id stopButton if hasMicrophone stopButton setEnabled false playButton setEnabled false recordButton setEnabled false else playButton setEnabled false stopButton setEnabled false audioFilePath Environment getExternalStorageDirectory getAbsolutePath myaudio 3gp eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters 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 The next line of code needs a little more explanation audioFilePath Environment getExternalStorageDirectory getAbsolutePath myaudio 3gp The purpose of this code is to identify the location of the SD card storage on the device and to use that to create a path to a file named myaudio acc into which the audio recording will be stored The path of the SD card which is referred to as external storage even though it is internal to the device on many Android devices is obtained via a call to the getExternalStorageDirectory method of the Android Environment class When working with external storage it is important to be aware that such activity by an application requires permission to be requested in the application manifest file For example uses permission android name android permission WRITE EXTERNAL STORAGE Implementing the recordAudio Method When the user touches the Record button the recordAudio method will be called This method will need to enable and disable the appropriate buttons configure the MediaRecorder instance with information about the source of the audio the output format and encoding and the location of the file into which the audio is to be stored Finally the prepare and start methods of the MediaRecorder object will need to be called Combined these requirements result in the following method implementation in the AudioAppActivity java file public void recordAudio View view throws IOException isRecording true stopButton setEnabled true playButton setEnabled false recordButton setEnabled false try mediaRecorder new MediaRecorder mediaRecorder setAudioSource MediaRecorder AudioSource MIC mediaRecorder setOutputFormat MediaRecorder OutputFormat THREE GPP mediaRecorder setOutputFile audioFilePath mediaRecorder setAudioEncoder MediaRecorder AudioEncoder AMR NB mediaRecorder prepare catch Exception e e printStackTrace mediaRecorder start Implementing the stopAudio Method The stopAudio method is responsible for enabling the Play button disabling the Stop button and then stopping and resetting the MediaRecorder instance The code to achieve this reads as outlined in the following listing and should be added to the AudioAppAcitivy java file public void stopAudio View view stopButton setEnabled false playButton setEnabled true if isRecording recordButton setEnabled false mediaRecorder stop mediaRecorder release mediaRecorder null isRecording false else mediaPlayer release mediaPlayer null recordButton setEnabled true Implementing the playAudio method

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

  • Working with the Google Maps Android 6 API in Android Studio - Techotopia
    get 0 getCountryName In this case the Geocoder object is initialized with latitude and longitude values via the getFromLocation method Once again only a single matching result is requested The text based address information is then extracted from the resulting Address object It should be noted that the geocoding is not actually performed on the Android device but rather on a server to which the device connects when a translation is required and the results subsequently returned when the translation is complete As such geocoding can only take place when the device has an active internet connection Adding a Map to an Application The simplest way to add a map to an application is to specify it in the user interface layout XML file for an activity The following example layout file shows the SupportMapFragment instance added to the activity map demo xml file created by Android Studio fragment 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 id id map tools context MapDemoActivity android name com google android gms maps SupportMapFragment eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Requesting Current Location Permission As outlined in the chapter entitled Making Runtime Permission Requests in Android 6 0 certain permissions are categorized as being dangerous and require special handing for Android 6 0 or later One such permission gives applications the ability to identify the user s current location By default Android Studio has placed a location permission request within the AndroidManifest xml Locate this file located under app manifests in the Project tool window and locate the following permission line uses permission android name android permission ACCESS FINE LOCATION This will ensure that the app is given the opportunity to provide permission for the app to obtain location information at the point that the app is installed on older versions of Android but to fully support Android 6 0 or later the app must also specifically request this permission at runtime To achieve this some code needs to be added to the MapDemoActivity java file Begin by adding some import directives and a constant to act as the permission request code package com ebookfrenzy mapdemo import android content pm PackageManager import android support v4 app FragmentActivity import android os Bundle import android support v4 content ContextCompat import android support v4 app ActivityCompat import android Manifest import android widget Toast import android content pm PackageManager import com google android gms maps CameraUpdateFactory import com google android gms maps GoogleMap import com google android gms maps OnMapReadyCallback import com google android gms maps SupportMapFragment import com google android gms maps model LatLng import com google android gms maps model MarkerOptions public class MapDemoActivity extends FragmentActivity implements OnMapReadyCallback private static final int LOCATION REQUEST CODE 101 private String TAG MapDemo private GoogleMap mMap Next a method needs to be added to the class the purpose of which is to request the location permission Remaining within the MapDemoActivity java class file implement this method as follows protected void requestPermission String permissionType int requestCode int permission ContextCompat checkSelfPermission this permissionType if permission PackageManager PERMISSION GRANTED ActivityCompat requestPermissions this new String permissionType requestCode When the user has responded to the permission request the onRequestPermissionsResult method will be called on the activity Remaining in the MapDemoActivity java file implement this method now so that it reads as follows Override public void onRequestPermissionsResult int requestCode String permissions int grantResults switch requestCode case LOCATION REQUEST CODE if grantResults length 0 grantResults 0 PackageManager PERMISSION GRANTED Toast makeText this Unable to show location permission required Toast LENGTH LONG show return Finally add a call to the requestPermission method within the onCreate method Override protected void onCreate Bundle savedInstanceState super onCreate savedInstanceState setContentView R layout activity map demo requestPermission Manifest permission ACCESS FINE LOCATION LOCATION REQUEST CODE SupportMapFragment mapFragment SupportMapFragment getSupportFragmentManager findFragmentById R id map mapFragment getMapAsync this Compile and run the app on a device or emulator session running Android 6 0 or later and tap on the Allow option when the permission request dialog appears Figure 57 3 Displaying the User s Current Location The user s current location may be displayed on the map by obtaining a reference to the GoogleMap object associated with the displayed map and calling the setMyLocationEnabled method of that instance passing through a value of true When the map is ready to display the onMapReady method of the activity is called By default Android Studio has implemented this method and added some code to orient the map over Australia with a marker positioned over the city of Sidney Locate and edit the onMapReady method in the MapDemoActivty java file to remove this template code and to enable display of the user s current location Override public void onMapReady GoogleMap googleMap mMap googleMap if mMap null mMap setMyLocationEnabled true When the app is now run a blue dot will appear on the map indicating the current location of the device Changing the Map Type The type of map displayed can be modified dynamically by making a call to the setMapType method of the corresponding GoogleMap object passing through one of the following values GoogleMap MAP TYPE NONE An empty grid with no mapping tiles displayed GoogleMap MAP TYPE NORMAL The standard view consisting of the classic road map GoogleMap MAP TYPE SATELLITE Displays the satellite imagery of the map region GoogleMap MAP TYPE HYBRID Displays satellite imagery with the road maps superimposed GoogleMap MAP TYPE TERRAIN Displays topographical information such as contour lines and colors The following code change to the onCreate method for example switches a map to Satellite mode public void onMapReady GoogleMap googleMap mMap googleMap if mMap null mMap setMyLocationEnabled true mMap setMapType GoogleMap MAP TYPE SATELLITE eBookFrenzy

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

  • Printing with the Android 6 Printing Framework - Techotopia
    Options are as follows SCALE MODE FIT The image will be scaled to fit within the paper size without any cropping or changes to aspect ratio This will typically result in white space appearing in one dimension SCALE MODE FILL The image will be scaled to fill the paper size with cropping performed where necessary to avoid the appearance of white space in the printed output In the absence of a scale mode setting the system will default to SCALE MODE FILL The following code for example sets scale to fit mode on the previously declared PrintHelper instance imagePrinter setScaleMode PrintHelper SCALE MODE FIT Similarly the color mode may also be configured to indicate whether the print output is to be in color or black and white This is achieved by passing one of the following options through to the setColorMode method of the PrintHelper instance COLOR MODE COLOR Indicates that the image is to be printed in color COLOR MODE MONOCHROME Indicates that the image is to be printed in black and white The printing framework will default to color printing unless the monochrome option is specified as follows imagePrinter setColorMode PrintHelper COLOR MODE MONOCHROME All that is required to complete the printing operation is an image to be printed and a call to the printBitmap method of the PrintHelper instance passing through a string representing the name to be assigned to the print job and a reference to the image in the form of either a Bitmap object or a Uri reference to the image Bitmap bitmap BitmapFactory decodeResource getResources R drawable oceanscene imagePrinter printBitmap My Test Print Job bitmap eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Once the print job has been started the Printing framework will display the print dialog and handle both the subsequent interaction with the user and the printing of the image on the user selected print destination Creating and Printing HTML Content The Android Printing framework also provides an easy way to print HTML based content from within an application This content can either be in the form of HTML content referenced by the URL of a page hosted on a web site or HTML content that is dynamically created within the application To enable HTML printing the WebView class has been extended in Android 4 4 to include support for printing with minimal coding requirements When dynamically creating HTML content as opposed to loading and printing an existing web page the process involves the creation of a WebView object and associating with it a WebViewClient instance The web view client is then configured to start a print job when the HTML has finished being loaded into the WebView With the web view client configured the HTML is then loaded into the WebView at which point the

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

  • An Android 6 HTML and Web Content Printing Example - Techotopia
    and change the ID of the view to myWebView Before proceeding to the next step of this tutorial an additional permission needs to be added to the project to enable the WebView object to access the internet and download a web page for printing Add this permission by locating the AndroidManifest xml file in the Project tool window and double clicking on it to load it into the editing panel Once loaded edit the XML content to add the appropriate permission line as shown in the following listing xml version 1 0 encoding utf 8 manifest xmlns android http schemas android com apk res android package com ebookfrenzy webprint uses permission android name android permission INTERNET application android allowBackup true android icon mipmap ic launcher android label string app name android theme style AppTheme activity android name WebPrintActivity android label string app name intent filter action android name android intent action MAIN category android name android intent category LAUNCHER intent filter activity application manifest Designing the User Interface Layout Load the content web print xml layout resource file into the Designer tool if it has not already been loaded and in Design mode select and delete the Hello World TextView object Switch to the XML view by clicking on the Text tab located along the lower edge of the Designer panel and remove the padding properties from the file so that the WebView will extend to the edges of the display when added to the layout 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 tools context WebPrintActivity RelativeLayout Switch back to Design mode and from the Widgets section of the palette drag and drop a WebView object onto the center of the device screen layout Using either the Properties panel or the Designer toolbar buttons change the layout width and layout height properties of the WebView to match parent so that it fills the entire layout canvas as outlined in Figure 59 3 Figure 59 3 Double click on the newly added WebView instance and change the ID of the view to myWebView Before proceeding to the next step of this tutorial an additional permission needs to be added to the project to enable the WebView object to access the internet and download a web page for printing Add this permission by locating the AndroidManifest xml file in the Project tool window and double clicking on it to load it into the editing panel Once loaded edit the XML content to add the appropriate permission line as shown in the following listing xml version 1 0 encoding utf 8 manifest xmlns android http schemas android com apk res android package com ebookfrenzy webprint uses permission android name android permission INTERNET application android allowBackup true android icon mipmap ic launcher android label string app name android theme style AppTheme activity android name WebPrintActivity android label string app name intent filter action android

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

  • A Guide to Android 6 Custom Document Printing - Techotopia
    if totalpages 0 PrintDocumentInfo Builder builder new PrintDocumentInfo Builder print output pdf setContentType PrintDocumentInfo CONTENT TYPE DOCUMENT setPageCount totalpages PrintDocumentInfo info builder build callback onLayoutFinished info true else callback onLayoutFailed Page count is zero Clearly this method is performing quite a few tasks each of which requires some detailed explanation To begin with a new PDF document is created in the form of a PdfDocument class instance One of the arguments passed into the onLayout method when it is called by the Printing framework is an object of type PrintAttributes containing details about the paper size resolution and color settings selected by the user for the print output These settings are used when creating the PDF document along with the context of the activity previously stored for us by our constructor method myPdfDocument new PrintedPdfDocument context newAttributes The method then uses the PrintAttributes object to extract the height and width values for the document pages These dimensions are stored in the object in the form of thousandths of an inch Since the methods that will use these values later in this example work in units of 1 72 of an inch these numbers are converted before they are stored pageHeight newAttributes getMediaSize getHeightMils 1000 72 pageWidth newAttributes getMediaSize getWidthMils 1000 72 Although this example does not make use of the user s color selection this property can be obtained via a call to the getColorMode method of the PrintAttributes object which will return a value of either COLOR MODE COLOR or COLOR MODE MONOCHROME When the onLayout method is called it is passed an object of type LayoutResultCallback This object provides a way for the method to communicate status information back to the Printing framework via a set of methods The onLayout method for example will be called in the event that the user cancels the print process The fact that the process has been cancelled is indicated via a setting within the CancellationSignal argument In the event that a cancellation is detected the onLayout method must call the onLayoutCancelled method of the LayoutResultCallback object to notify the Print framework that the cancellation request was received and that the layout task has been cancelled if cancellationSignal isCanceled callback onLayoutCancelled return When the layout work is complete the method is required to call the onLayoutFinished method of the LayoutResultCallback object passing through two arguments The first argument takes the form of a PrintDocumentInfo object containing information about the document to be printed This information consists of the name to be used for the PDF document the type of content in this case a document rather than an image and the page count The second argument is a Boolean value indicating whether or not the layout has changed since the last call made to the onLayout method if totalpages 0 PrintDocumentInfo Builder builder new PrintDocumentInfo Builder print output pdf setContentType PrintDocumentInfo CONTENT TYPE DOCUMENT setPageCount totalpages PrintDocumentInfo info builder build callback onLayoutFinished info true else callback onLayoutFailed Page count is zero In the event that the page count is zero the code reports this failure to the Printing framework via a call to the onLayoutFailed method of the LayoutResultCallback object eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters The call to the onLayoutFinished method notifies the Printing framework that the layout work is complete thereby triggering a call to the onWrite method Implementing the onWrite Callback Method The onWrite callback method is responsible for rendering the pages of the document and then notifying the Printing framework that the document is ready to be printed When completed the onWrite method reads as follows package com ebookfrenzy customprint import java io FileOutputStream import java io IOException import android support v7 app AppCompatActivity import android os Bundle import android os CancellationSignal import android os ParcelFileDescriptor import android print PageRange import android print PrintAttributes import android print PrintDocumentAdapter import android content Context import android print PrintDocumentInfo import android print pdf PrintedPdfDocument import android graphics pdf PdfDocument import android graphics pdf PdfDocument PageInfo Override public void onWrite final PageRange pageRanges final ParcelFileDescriptor destination final CancellationSignal cancellationSignal final WriteResultCallback callback for int i 0 i totalpages i if pageInRange pageRanges i PageInfo newPage new PageInfo Builder pageWidth pageHeight i create PdfDocument Page page myPdfDocument startPage newPage if cancellationSignal isCanceled callback onWriteCancelled myPdfDocument close myPdfDocument null return drawPage page i myPdfDocument finishPage page try myPdfDocument writeTo new FileOutputStream destination getFileDescriptor catch IOException e callback onWriteFailed e toString return finally myPdfDocument close myPdfDocument null callback onWriteFinished pageRanges The onWrite method starts by looping through each of the pages in the document It is important to take into consideration however that the user may not have requested that all of the pages that make up the document be printed In actual fact the Printing framework user interface panel provides the option to specify that specific pages or ranges of pages be printed Figure 60 2 for example shows the print panel configured to print pages 1 4 pages 8 and 9 and pages 11 13 of a document Figure 60 2 When writing the pages to the PDF document the onWrite method must take steps to ensure that only those pages specified by the user are printed To make this possible the Printing framework passes through as an argument an array of PageRange objects indicating the ranges of pages to be printed In the above onWrite implementation a method named pagesInRange is called for each page to verify that the page is within the specified ranges The code for the pagesInRange method will be implemented later in this chapter for int i 0 i totalpages i if pageInRange pageRanges i For each page that is within any specified ranges a new PdfDocument Page object is created When creating a new page the height and width values previously

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

  • Handling Different Android 6 Devices and Displays - Techotopia
    category This involves identifying the smallest width qualifier value of each display and creating an XML layout file for each one The smallest width value of a display indicates the minimum width of that display measured in dp units Display specific layouts are implemented by creating additional sub directories under the res directory of a project The naming convention for these folders is layout smallest width For example layout resource folders for a range of devices might be configured as follows res layout The default layout file res layout sw200dp res layout sw600dp res layout sw800dp Alternatively more general categories can be created by targeting small normal large and xlarge displays res layout The default layout file res layout small res layout normal res layout large res layout xlarge Each folder must in turn contain a copy of the layout XML file adapted for the corresponding display all of which must have matching file names Once implemented the Android runtime system will automatically select the correct layout file to display to the user to match the device display Providing Different Images User interface layouts are not the only area of concern when adapting an application for different screen densities dimensions and aspect ratios Another area to pay attention to is that of images An image that appears correctly scaled on a large tablet screen for example might not appear correctly scaled on a smaller phone based device As with layouts however multiple sets of images can be bundled with the application each tailored for a specific display This can once again be achieved by referencing the smallest width value In this case drawable folders need to be created in the res directory For example res drawable The default image folder res drawable sw200dp res drawable sw600dp res drawable sw800dp Having created the folders simply place the display specific versions of the images into the corresponding folder using the same name for each of the images Alternatively the images may be categorized into broader display densities using the following directories based on the pixel density of the display res drawable ldpi Images for low density screens approx 120 dpi res drawable mdpi Images for medium density screens approx 160 dpi res drawable hdpi Images for high density screens approx 240 dpi res drawable xhdpi Images for extra high density screens approx 320 dpi res drawable tvdpi Images for displays between medium and high density approx 213 dpi res drawable nodpi Images that must not be scaled by the system eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Checking for Hardware Support By now it should be apparent that not all Android devices were created equal An application that makes use of specific hardware features such as a microphone or camera should include code to gracefully handle the

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

  • Signing and Preparing an Android 6 Application for Release - Techotopia
    Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters The New Key Store dialog is now divided into two sections The top section relates to the keystore file In this section enter a strong password with which to protect the keystore file into both the Password and Confirm fields The lower section of the dialog relates to the release key that will be stored in the key store file Figure 62 4 Generating a Private Key The next step is to generate a new private key which will be used to sign the application package Within the Key section of the New Key Store dialog enter the following details An alias by which the key will be referenced This can be any sequence of characters though only the first 8 are used by the system A suitably strong password to protect the key The number of years for which the key is to be valid Google recommends a duration in excess of 27 years In addition information must be provided for at least one of the remaining fields for example your first and last name or organization name Figure 62 5 Once the information has been entered click on the Next button to proceed with the package creation Creating the Application APK File The next task to be performed is to instruct Android Studio to build the application APK package file in release mode and then sign it with the newly created private key At this point the Generate Signed APK Wizard dialog should still be displayed with the keystore path passwords and key alias fields populated with information Figure 62 6 eBookFrenzy com Purchase the full edition of this Android Studio Development Essentials Android 6 Edition Book in eBook 9 99 or Print 38 99 format Android Studio Development Essentials Android 6 Edition Print and eBook ePub PDF Kindle editions contain 65 chapters Assuming that the settings are correct click on the Next button to proceed to the APK generation screen Figure 62 7 Within this screen review the Destination APK path setting to verify that the location into which the APK file will be generated is acceptable In the event that another location is preferred click on the button to the right of the text field and navigate to the desired file system location and click Finish Figure 62 7 The Gradle system will now compile the application in release mode Once the build is complete a dialog will appear providing the option to open the folder containing the APK file in an explorer window Figure 62 8 At this point the application is ready to be submitted to the Google Play store The private key generated as part of this process should be used when signing and releasing future applications and as such should be kept in a safe place and securely backed up The final step in the process of bringing an Android application to market involves submitting it

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



  •