Mobile application Development-UNIT-V (1).pptx

JayasimhaThummala1 146 views 30 slides Sep 09, 2024
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

mobile


Slide Content

UNIT-V SYLLABUS : Using Common Android APIs: Using Android Data and Storage APIs, managing data using SQLite, Sharing Data between Applications with Content Providers, Using Android Networking APIs, Using Android Web APIs, Using Android Telephony APIs, Deploying Android Application to the World .

Using Android Data and Storage APIs: Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs, such as whether the data should be private to your application or accessible to other applications (and the user) and how much space your data requires. Data Storage Options are the following : Shared Preferences Store private primitive data in key-value pairs. Internal Storage Store private data on the device memory. External Storage Store public data on the shared external storage. SQLite Databases Store structured data in a private database. Network Connection Store data on the web with your own network server.

Using Shared Preferences: The  Shared Preferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use  Shared Preferences to save any Primitive Data : Booleans, floats, ints , longs, and strings. This data will persist across user sessions (even if your application is killed). User Preferences Shared preferences are not strictly for saving “ user preferences ,” such as what ringtone a user has chosen . If you’re interested in creating user preferences for your application, see  Preference Activity , which provides an Activity framework for you to create user preferences, which will be automatically persisted (using shared preferences).

Using the Internal Storage You can save files directly on the device’s internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed. Using the External Storage Every Android-compatible device supports a shared “external storage” that you can use to save files. This can be a removable storage media (such as an SD card) or an internal (non-removable) storage . Files saved to the external storage are world-readable and can be modified by the user when they enable USB mass storage to transfer files on a computer.

Hiding your files from the Media Scanner Include an empty file named  .no media in your external files directory (note the dot prefix in the filename). This will prevent Android’s media scanner from reading your media files and including them in apps like Gallery or Music . Saving files that should be shared If you want to save files that are not specific to your application and that should  not  be deleted when your application is uninstalled, save them to one of the public directories on the external storage. These directories lay at the root of the external storage, such as Music/ ,  Pictures/ ,  Ringtones/ , and others.

use  getExternalStorageDirectory () to open a  File that represents the root of the external storage,then save your shared files in one of the following directories: Music/  – Media scanner classifies all media found here as user music. Ringtones/   – Media scanner classifies all media found here as a ringtone. Alarms/  – Media scanner classifies all media found here as an alarm sound. Notifications/  – Media scanner classifies all media found here as a notification sound. Pictures /  – All photos (excluding those taken with the camera). Movies/  – All movies (excluding those taken with the camcorder). Download/  – Miscellaneous downloads.

Android SQLite Tutorial: SQLite is a open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC,ODBC e.t.c Database – Package. The main package is android.database.sqlite that contains the classes to manage your own databases. Database – Creation. In order to create a database you just need to call this method open Or Create Database with your database name and mode as a parameter.

Sr.No Method & Description 1 openDatabase (String path, SQLite Database.CursorFactory factory, int flags, Database ErrorHandler error Handler ) This method only opens the existing database with the appropriate flag mode. The common flags mode could be OPEN_READWRITE OPEN_READONLY 2 openDatabase (String path, SQLite Database.CursorFactory factory, int flags): It is similar to the above method as it also opens the existing database but it does not define any handler to handle the errors of databases. 3 openOrCreateDatabase (String path, SQLite Database.CursorFactory factory): It not only opens but create the database if it not exists. This method is equivalent to openDatabase method . 4 openOrCreateDatabase ( File,SQLite Database.CursorFactory factory )This method is similar to above method but it takes the File object as a path rather then a string. It is equivalent to file.getPath ()

Database – Insertion: we can create table or insert data into table using execSQL method defined in SQLite Database class. Its syntax is given below mydatabase.execSQL ("CREATE TABLE IF NOT EXISTS TutorialsPoint (Username VARCHAR,Password VARCHAR);");   mydatabase.execSQL ("INSERT INTO TutorialsPoint VALUES(' admin','admin ');"); Database – Fetching: We can retrieve anything from database using an object of the Cursor class. We will call a method of this class called raw Query and it will return a resultset with the cursor pointing to the table. We can move the cursor forward and retrieve the data.

Sr. No Method & Description 1 getColumnCount () This method return the total number of columns of the table. 2 getColumnIndex (String columnName ) This method returns the index number of a column by specifying the name of the column 3 getColumnName ( int columnIndex ) This method returns the name of the column by specifying the index of the column

4 getColumnNames () This method returns the array of all the column names of the table. 5 getCount () This method returns the total number of rows in the cursor 6 getPosition () This method returns the current position of the cursor in the table 7 isClosed () This method returns true if the cursor is closed and return false otherwise

Sharing Data between Applications with Content Providers: Content Providers are a very important  component  that serves the purpose of a relational database to store the data of applications. The role of the content provider in the android system is like a central repository in which data of the applications are stored, and it facilitates other applications to securely access and modifies that data based on the user requirements. Android system allows the content provider to store the application data in several ways. Users can manage to store the application data like images, audio, videos, and personal contact information by storing them in  SQLite Database , in files ,  or even on a network . In order to share the data, content providers have certain permissions that are used to grant or restrict the rights to other applications to interfere with the data.

Content URI: Content URI (Uniform Resource Identifier)  is the key concept of Content providers. To access the data from a content provider, URI is used as a query string.  Details of different parts of Content URI: content:// –  Mandatory part of the URI as it represents that the given URI is a Content URI. authority –   Signifies the name of the content provider like contacts, browser, etc. This part must be unique for every content provider. optionalPath –  Specifies the type of data provided by the content provider. It is essential as this part helps content providers to support different types of data that are not related to each other like audio and video files. optionalID –  It is a numeric value that is used when there is a need to access a particular record.

Operations in Content Provider : Four fundamental operations are possible in Content Provider Namely  Create ,  Read ,  Update , and  Delete . These operations are often termed as  CRUD operations .  Create:   Operation to create data in a content provider . Read:  Used to fetch data from a content provider . Update:   To modify existing data . Delete:  To remove existing data from the storage.

Working of the Content Provider UI components of android applications like  Activity  and  Fragments  use an object  Cursor Loader   to send query requests to  Content Resolver .  The Content Resolver object sends requests (like create, read, update, and delete) to the  Content Provider   as a client . After receiving a request, Content Provider process it and returns the desired result. Below is a diagram to represent these processes in pictorial form.

Contend Provider classes: Abstract Method Description query() A method that accepts arguments and fetches the data from the desired table. Data is retired as a cursor object. insert() To insert a new row in the database of the content provider.  It returns the content URI of the inserted row.  update() This method is used to update the fields of an existing row.  It returns the number of rows updated. delete() This method is used to delete the existing rows.  It returns the number of rows deleted. getType() This method returns the Multipurpose Internet Mail Extension (MIME) type of data to the given Content URI. onCreate () As the content provider is created, the android system calls  This method immediately to initialize the provider.

Using Android Networking APIs: Android lets your application connect to the internet or any other local network and allows you to perform network operations. A device can have various types of network connections. Checking Network Connection Before you perform any network operations, you must first check that are you connected to that network or internet e.t.c . For this android provides  ConnectivityManager  class. You need to instantiate an object of this class by calling  getSystemService ()  method. Its syntax is given below − ConnectivityManager check = ( ConnectivityManager ) this.context.getSystemService ( Context.CONNECTIVITY_SERVICE );

Sr.No State 1 Connecting 2 Disconnected 3 Disconnecting 4 Suspended 5 Unknown Apart from this connected states, there are other states a network can achieve. They are listed below −

Apart from this connect method, there are other methods available in Http URL Connection class. They are listed below − Sr.No Method & description 1 disconnect (): This method releases this connection so that its resources may be either reused or closed 2 getRequestMethod (): This method returns the request method which will be used to make the request to the remote HTTP server 3 getResponseCode (): This method returns response code returned by the remote HTTP server 4 setRequestMethod (String method ): This method Sets the request command which will be sent to the remote HTTP server 5 usingProxy (): This method returns whether this connection uses a proxy server or not

Using Android Web APIs: Enable the API To use the Tuning Fork library in your own app, enable the Android Performance Parameters API in the Google Cloud Console. You need a Google developer account to create a Google Cloud Console project. You can use an existing Google Cloud Console project  (for example, the one you created for the demo app). Follow the steps below to  add the proper API key restrictions  to your existing project

Steps Follow these steps to enable the API: 1. In the Google Cloud Console, go to the  Projects  page. Select an existing project or create a new project. Go to the Projects Page For more information on creating a Google Cloud Console project, see the  Cloud API documentation . 2. Enable the Android Performance Parameters API on the project you selected. Enable the API If it has not been enabled, click  ENABLE . 3. Select the  Credentials  tab on the left. 4. If the project does not have an existing API key, click  CREATE CREDENTIALS  and select  API Key

5 . Copy the API key into the  api_key  field in the game project tuningfork_settings.txt file. 6. Restrict the API key to Android apps only: You should see a  Key restrictions  section. If not, double-click the API key. Under  Application restrictions , select  Android apps . Click  ADD AN ITEM . Enter your app's package name. Enter the SHA-1 certificate fingerprint to  authenticate your app . Use the release certificate fingerprint: keytool - exportcert -list -v \ -alias your-key-name - keystore path-to-production- keystore

Using Android Telephony APIs: The telephony API is  used to among other things monitor phone information including the current states of the phone, connections, network etc . In this example, we want to utilize the telephone manager part of the Application Framework and use phone listeners (Phone State Listener) to retrieve various phone states. Telephony app used for: Telephony Application Programming Interface is primarily used in  controlling telephone system handsets or modems . It is also used to control voice-enabled telephony equipment like voice modems or voice-dedicated hardware.

The telephony API is used to among other things monitor phone information including the current states of the phone, connections, network etc. In this example, we want to utilize the telephone manager part of the Application Framework and use phone listeners (Phone State Listener) to retrieve various phone states. This is a simple tutorial utilizing the telephony API and its associated listener which can be good before implementing other application functions related to a phone state like connecting the Call. Android Telephony Manager Example: Let's see the simple example of Telephony Manager that prints information of the telephony services. activity_main.xml

Best Telephony Platforms and Services Fastcall . Nextiva . Vonage for Service-Cloud Voice & Contact Center. Cisco Webex . Ooma . Dialpad . Fuze . Phone.com.

Deploying Android Application to the World: Publishing is the general process that makes your Android applications available to users. When you publish an Android application you perform two main tasks: You prepare the application for release. During the preparation step you build a release version of your application, which users can download and install on their Android-powered devices. You release the application to users. During the release step you publicize, sell, and distribute the release version of your application to users. This page provides an overview of the process you should follow as you prepare to publish your app. If you plan to publish on Google Play, you should also read the  Google Play launch checklist .

Releasing your app to users You can release your Android applications several ways. Usually, you release applications through an application marketplace such as Google Play, but you can also release applications on your own website or by sending an application directly to a user. Releasing through an app marketplace If you want to distribute your apps to the broadest possible audience, releasing through an app marketplace such as Google Play is ideal. Google Play is the premier marketplace for Android apps and is particularly useful if you want to distribute your applications to a large global audience. However, you can distribute your apps through any app marketplace you want or you can use multiple marketplaces.

Releasing your apps on Google Play Google Play is a robust publishing platform that helps you publicize, sell, and distribute your Android applications to users around the world. When you release your applications through Google Play you have access to a suite of developer tools that let you analyze your sales, identify market trends, and control who your applications are being distributed to. You also have access to several revenue-enhancing features such as  in-app billing  and  application licensing . Releasing through a website If you do not want to release your app on a marketplace like Google Play, you can make the app available for download on your own website or server, including on a private or enterprise server. To do this, you must first prepare your application for release in the normal way.