Download as pdf or txt
Download as pdf or txt
You are on page 1of 261

. .

१ १ - ११
(Android and its tools)

२ Android १२-३३
(Installation and Configuration Of Android)

३ घटक आणि म ां डिी ३४-६१


(Components and Layouts)

४ ६२-१०५
(Designing User Interface With View)

५ ह १०६-२०२
(Activity and Multimedia with Databases)

६ २०३-२५५
(Security and Application Deployment)
Mobile Application Development (22617) (२२६१७)

घटक १

(Android and its tools)


गु ण (०४)
विषय वनष्पत्ती (Course Outcome):

 अँडरॉइड

घटक वनष्पत्ती (Unit Outcome):

 अँडरॉइड सिस्टमशी िंबंसधत सदलेल्या मूलभूत िंज्ञा स्पष्ट

 आकृतीिह

 अँडरॉइड आसकिटे क्चरमध्ये सदलेल्या घटकाचे महत्त्व स्पष्ट


१.१ (Indroduction to Android)

(display)

(Android Inc)
२००५

(Google younger audience)

२०१३

1 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

१ .१ .१ ट Open Handset Allance(OHA))

Motorol Q ८०

क API

- १ .० १ २३ िप्टेंबर २००८

- १ .१ २ ९ फेब्रुवारी २००९

कपकेक(cup cake) १ .५ ३ ३० एसिल २००९

डोनट(Donut) १ .६ ४ १ ५ िप्टेंबर २००९

इक्लेअर(Éclair) २.० – २.१ ५-७ २६ऑक्टोबर २००९

फ्रोयो(Froyo) २.२ – २.२.३ ८ २० मे २०१०

सजंजरब्रेड(Gingerbread) २.३ – २.३. ४ ९ -१ ० ६ सडिेंबर २०१०

(Honeycomb) ३.०.x – ३.२.x ११ – १३ २२ फेब्रुवारी २०११

आइस्क्रीम िँडसवच ४.० – ४.०.४ १४ – १ ५ १८ ऑक्टोबर २०११


(Ice Cream Sandwich)
जेली बीन(Jelly Bean) ४.१ – ४.१ .२ १६ – १ ८ ९ जुलै २०१२

सकटकॅट(KitKat) ४.४ – ४.४.४ १९ ९ जुलै २०१२

2 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

लॉलीपॉप(Lollipop) ५.० – ५.१ २१ – २२ १७ ऑक्टोबर २०१४

माशिमॅलो(Marshmallow) ६.० – ६.०.१ २३ ५ ऑक्टोबर २०१५

नौगट(Nougat) ७ .० – ७ .१ २ ४ – २५ २२ ऑगस्ट २० १६

ओररओ(Oreo) ८ .० २६ २१ ऑगस्ट २०१७

पाई (Pie) ९ .० २७ ६ ऑगस्ट २० १८

Q १० .० २९ ३ िप्टेंबर २०१९

११ ११ .० ३० ८ िप्टेंबर २०२०

स्नो कोन(Snow Cone) १२.० –१२.१ ३१ -३२ ४ ऑक्टोबर २०२१

ट १

१.१.२ क (Android Ecosystem)



१ क –


-

 ट -

3 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क १.१

 – : - -
-

- -

-
-

 ट :

4 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

३.

कट:
कट

१.२

 कट

.
 क Device diversity):

 क (Customization)

5 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

 ट (Rooting)

 (Android Community)

 क क (Powerful development framework)


’‖‖

 क Global partnership)

१५ (Google

१.२.१
 -

 -

 -

 -

6 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

 AVI, MKV, FLV, MPEG


 JPEG, PNG, GIF, BMP, MP३

 HTML५ CSS३

 -

 २D/३

 ट ट

१.३ क क क

(Androd Development Softwares and Tools)


२ १० ५ ८
३ (Linux ) GNU C Librar २ ७

१ ५
२. (Android Studio )

envoiurnment)
ट कट क टक
-

JAVA_HOME

7 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

‗ ‖ ‗‖‘

‗ ‖ ‗‖‘ .
‗ ‖ ‗‖‘

‗ ‖ ‗‖‘

setenv PATH /usr/local/jdk1.8.0_102/bin:$PATH


setenv JAVA_HOME /usr/local/jdk1.8.0_102

Integrated Development Enviournment (IDE)

 (Android Studio)
 Eclipse IDE(

१.४ कट

१.
२. ( )
३.
४.
५.

8 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क १.२ कट

१. क


9 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

 P oce

 ट क क

 (Driver Model):

२. ट

.


 - - ‘


 SQLit

 -

३. ट

10 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४. क

.
५. क क

(Bibliography)

https://www.geeksforgeeks.org/android-architecture/

https://www.tutorialspoint.com/android/android_overview.htm

11 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

घटक २
Android क
Installation and Configuration Of Android

(Course Outcome):

घटक (Unit Outcome):

➢ IDE

➢ .
➢ .


➢ .

२.१ ट , क, क(Operating system,Java JDK,Android SDK)

SDK (Android Software Development Kit)

Google . SDK , Apps

SDK
. Google ,

SDK . SDK ,
. SDK

२.२ Android Development tools

12 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

(SDK)
, .

SDK .

ADT Bundle .
SDK ADT (Android Developer

Tools) Eclipse IDE .

SDK ट

SDK
. SDK , .

ट ट

SDK : .
.

२. ३. क ( Android Virtual Devices)

( ) .

, .
.

, , , , .
- . ,

13 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

,
.AVD .

टक

1: Tools —-> AVDManager .


AVD .

क २.३.१

14 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

2: , "Create Virtual Device" . ,


.

क २.३.२

3: , .

Pixel 2 XL . , .

15 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क २.३.३

4: , . ,

क २.३.४

5: , R ( 11) .
, .

, , .

16 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क २.३.५

6: , , Finish .

क २.३.६

17 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क २.३ .७

7: , AVD

. AVD , ,
“ Y ”

Finish AVD .

8: ,

२ .४ ट Emulators

API
.

२.५ क (Dalvik Virtual Machine)

Dalvik Virtual Machine (DVM) .

, .

18 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

. . .dex
Dalvik VM . dex .

क २.५.१

javac java .

dx .dex . -

(aapt) .

२.५.१ JVM DVM क Difference between JVM and DVM

Srno क

JVM(Java Virtual Machine) DVM(Dalvik Virtual Machine)

..

19 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Compiled bytecode size is compact Compiled bytecode size is larger as


because the location of the operand is each instruction needs all implicit

implicitly on the operand stack. operands.

VM VM
.

More information is required to the VM Instruction size is larger as it needs to


for data loading and manipulation as encode the source and destination

well as method loading in the stack register of the VM.


data structure.

3 .jar .apk

. .
The executable file for the device is .jar The executable file for the device is

file. .apk file.

4 JVM
Java bytecode

. , DEX (dx )

Java bytecode Dalvik


(. ) bytecode(classes.dex)

.apk
Java source code is compiled into Java .

bytecode format(.class file) that further Source code files are first of all
translates into machine code. compiled into Java bytecode format

like JVM. Further, the DEX


compiler(dx tool) converts the Java

bytecode into Dalvik

20 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

bytecode(classes.dex) file that will be


used to create the .apk file.

5 - VM - VM

CPU
. .

. Register-based VM that uses registers


Stack-based VM that performs located in the CPU to perform

arithmetic and logic operations through arithmetic and logic operations.


push and pop operands. The result of

operations is stored in stack memory.

JVM
. DVM

A single instance of JVM is configured .


with shared processes and memory The device runs multiple DVM

space in order to run all deployed instances with a separate process in


applications. shared memory space to deploy the

code of each application.

7 Linux, Windows Mac OS


.

Supports multiple operating systems Support only the Android operating


like Linux, Windows, and Mac OS system.

२.६ SDK क क

Steps to install and configure Android studio and SDK

21 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Google IDE
. IntelliJ IDEA , Apache

. .

● .
● TV Wear .

● - .
● .

● .
● APK .

● C++ NDK .

1. क (System Requirements)

Google , . .
,

Microsoft® Windows® 7/8/10 (64 )

4 GB RAM , 8 GB RAM

2 GB , 4 GB (IDE 500 MB 1.5 GB SDK

1280 x 800

2. क

22 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

1 -

2 , ट … , DOWNLOAD ANDROID STUDIO FOR WINDOWS

२.६.१

3 , . ,

3. क (Install Android Studio)

1 ( ,

). , -Next

23 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२.६.२

2 ,

२.६.३

3 , .

24 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२.६.४

4 , SDK . , .

२.६.५

25 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२.६.६

6 ,

२.६.७

7 , .
26 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२.६.८

8 ,

२.६.९

27 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

. . Start Android Studio


, . ,

SDK

, SDK .
4. ट

1 , /

२.६.१०

. 2
. sdk , . ,

. .

28 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२.६.११

, . ,

२.६.१२

29 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

. ,
. .

२.६.१३

, . .

, .

२.६.१४
30 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

, . .

२.६.१५

5. SDK घटक क .

SDK
SDK, ,

. -

API

OS

SDK ( ) . SDK
. . Lollipop SDK ,

Lollipop . ,
31 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

SDK .
, ,

, SDK .
SDK

SDK -
.

Mac , Android Studio -> Preferences . ,


.

, Appearance

२.६.१६

, .

. , ,
.

32 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२.६.१७

(Bibliography)

https://www.geeksforgeeks.org/android-architecture/

https://www.javatpoint.com/dalvik-virtual-machine

https://source.android.com/docs/setup/create/avd

https://developer.android.com/studio/install

33 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

घटक –३ (Unit –III)

घटक आवण म ांडणी (Components and Layouts)

(Course Outcome): गु ण ८
विषय वनष्पत्ती (Course Outcome):

 घटक आसण लेआउट वापरून ररच यूजर इं टरफेि सवकसित करा. ( Develop Rich user

Interface using components and Layout.)

घटक वनष्पत्ती (Unit Outcome):

 सदलेल्या सनदे सशकेची रचना िंबंसधत िादृश्याने स्पष्ट करा.(Explain with relevent analogy the given
directory Structure.)

 सदलेले ररच UI घटक वापरण्याच्या चरणां चे वणिन करा. (Describe the steps to use the given
Android rich UI Componets.)

 सदलेल्या लेआउटचा िकार वापरण्यािाठी चरणां चे वणिन करा.( Describe the steps to use the given type
of layout.)

 सदलेले मूलभूत Application सवकसित करा.

३.१ - ऍप्लिकेशन घटक(Components)

ऍप्लिकेशन घटक हे ऍप्लिकेशनचे आवश्यक सबप्लडंग ब्लॉक्स आहे त. हे घटक ऍप्लिकेशन मॅसनफेस्ट फाइल

AndroidManifest.xml द्वारे िहज जोडलेले आहे त जे ऍप्लिकेशनच्या ित्येक घटकाचे आसण ते किे परस्परिंवाद
करतात याचे वणिन करतात.ज्या क्लािला इतरां च्या गुणधमाा चा वारिा समोतो तो उपक्लाि ्युतुपन्न क क्लाि, चाइड क्लाि)

म्हणून ओोखला जातो आसण ज्या वगाि च्या गुणधमाा ना वारिा समोतो तो िुपरक्लाि ्बेि क्लाि, पॅरेंट क्लाि) म्हणून
ओोखला जातो.

आां डरॉइड ऍप्लिकेशनमध्ये ि परलेले मुख्य कॉम्पोनेन्ट्स मर ठीतून:

अॅप्लिविटी (Activity): अॅप्लक्टसवटी हे एक एकमेक यूजर इं टरफेि िसहत सिं गल स्क्रीन दशिवते. ते वापरकत्याि शी िंवाद
स्थासपत करण्याच्या लक्षात घेतले जाते.

सेि (Service): िेवा हे अॅ प्लक्टसवटीच्या बाहे रील चालू ठे वलेले काये करते , जी लॉन्ग रसनंग ऑपरे शन्सिाठी वापरली जाते.
34 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

प्रदशशन (Broadcast Receiver): ब्रॉडकास्ट ररसिव्हर हे एवढे िमुख निताना प्लस्थतीत ब्रॉडकास्ट मेिेज िु सनसित करते
आसण त्यां चे उत्तर दे ते.

प्रद न (Content Provider): कंटें ट िोव्हायडर हे ऍप्लिकेशनमध्ये अिलेल्या डे टाचे इतर ऍप्लिकेशनमध्ये िामासयक
करण्याची क्षमता पुरवते.

फ्रैग्मेंट (Fragment): फ्रैग्मेंट हे अॅप्लक्टसवटीमध्ये आपली स्थाने ठरसवणारे आहे , ज्यामुोे मधुर आसण मॉड्युलर सडझाइन

तयार करू शकतात.

इां टेंट (Intent): इं टेंट्ि अॅप्लिकेशनच्या सवभागां मध्ये िंवाद स्थासपत करण्याचा माध्यम पुरवते , ज्यामुोे एप्लक्टसवटीि,

िेवां ि, सकंवा इतर कंपोनेन्ट्ििोबत िंवाद स्थासपत करू शकतो.

बन िट (Layouts): आं डरॉइड ऍप्लिकेशनमध्ये UI तयार करण्यािाठी वापरलेले लेआउट् ि, ज्यामुोे आपली UI िंरचना
िुसनसित करू शकतो.

सांस धन (Resources): ऍप्लिकेशनमध्ये वापरलेले िं िाधन, ज्यामुोे त्यातील सचरे, प्लस्टरंग्स, आसण इतर आवश्यक मासहती

िंग्रसहत केली जाते.

एकाच ऍप्लिकेशनमध्ये ही िवि कॉम्पोनेन्ट्ि समसितपणे काम करतात आसण वापरकत्याा ना िुिभावी आसण उपयुक्त

अॅप्लिकेशन िदान करतात.

१.अॅप्लिविटी (Activities)

"अॅप्लक्टसवटी ्Activity)" अॅप्लिकेशनमध्ये एक महत्त्वपूणि कंपोनेंट आहे , ज्याच्या माध्यमातून वापरकताि िंवाद
स्थासपत करतो. यामुोे एप्लक्टसवटी हे एक अनुियोगाचे िवेशद्वार ्entry point) अिते. येथे त्याच्या िंरचनेची महत्त्वाची
मासहती आहे :

आिृत्ती (Lifecycle): एप्लक्टसवटीने सवसवध आवृत्तीची प्लस्थती दशिवते , ज्यामुोे ती कधीही िसहृय सकंवा सनप्लस्क्रय होते.

यामुोे तुमच्या अॅप्लिकेशनला त्याचे सवसवध चरररे होतात, जिे की िुरुवातीला, िसहृय, बंद, सकंवा पुनरारं भ.

UI तय र करणे (UI Creation): एप्लक्टसवटीमध्ये वापरकत्याा िाठी दृश्य कंपोनेंट्ि तयार करणे , त्यां ची स्थाने ठरवणे आसण
त्यां ना सवन्याि करणे.

यूजरसोबत तय र करणे (Interaction with User): एप्लक्टसवटीने वापरकत्याा िोबत िंवाद स्थासपत करण्यािाठी इवेंट्ि
िुरू करते , जिे की बटनसकंवा मेनू वापरकत्याा िोबत एक्शन िुरू करणे.

इां टेंट्स (Intents): एप्लक्टसवटीने इं टेंट्ि वापरून इतर एप्लक्टसवटी सकंवा िेवा िुरू करू शकते.

35 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

मेवनफेस्ट फ इलमध्ये म वहती (Manifest File Information): मॅसनफेस्ट फाइलमध्ये एप्लक्टसवटीिाठी मुख्य मासहती
दे णे, जिे की त्याचं नाव, इं टेंट सफल्टर, आसण िुरू केलेल्या इं टेंटिाठी वणिन.

स्थ नीय डे ट सांग्रहण (Local Data Storage): एप्लक्टसवटीने स्थानीय डे टाबेि सकंवा इतर स्थानीय िं ग्रहणां मध्ये डे टा
िंग्रसहत करण्यािाठी कोड िमासवष्ट करू शकते.

फ्रैग्मेंट्स सोडिणे (Managing Fragments): एप्लक्टसवटीमध्ये फ्रैग्मेंट्ि वापरकताा िोबत मधुर िंवाद स्थासपत

करण्यािाठी वापरले जाते .

स्क्रीन वकांि लेआउट बदलणे (Changing Screen or Layout): सवसवध पररप्लस्थतीत एप्लक्टसवटीने स्क्रीन सकंवा

लेआउट बदलू शकते , ज्यामुोे एप्लक्टसवटीची उपयुक्तता बनते.

एप्लक्टसवटी म्हणजेच अॅप्लिकेशनच्या वापरकत्याा िोबत िंवाद स्थासपत करणारी मुख्य यूजर इं टरफेि पृष्ठभूमी आहे . ती एक
मोबाइल अॅप्लिकेशन सवकसित करण्यािाठी वापरकताि इं टरफेििह सिंगल स्क्रीनचे िसतसनसधत्व करते , थोडक्यात

सहृयाकलाप स्क्रीनवर सहृया करते. उदाहरणाथि , ईमेल अॅप्लिकेशनमध्ये नवीन ईमेलची िूची दाखवणारी एक अॅप्लक्टप्लव्हटी,
ईमेल तयार करण्यािाठी दु िरी अॅप्लक्टप्लव्हटी आसण ईमेल वाचण्यािाठी दु िरी अॅप्लक्टप्लव्हटी अिू शकते. जर एखाद्या

अॅप्लिकेशनमध्ये एकापेक्षा जास्त सहृयाकलाप अितील, तर त्यापैकी एक अॅप्लिकेशन लॉन्च केल्यावर िादर केलेल्या
सहृयाकलाप म्हणून सचन्ां सकत केले जावे.

An activity is implemented as a subclass of Ac −

public class MainActivity extends Activity

अॅप्लिकेशनमध्ये एप्लक्टसवटी एक महत्त्वाचं घटक आहे , ज्यामुोे वापरकताा ना अॅप्लिकेशनमध्ये नेप्लव्हगेट करण्यात

मदत केली जाते. येथे मराठीत एक अॅप्लक्टसवटीचा उदाहरण सदला जातो:

// तुमची एप्लक्टसवटी जावा कोड

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

36 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

setContentView(R.layout.activity_main);

// इतर एप्लक्टसवटी लाइफिायिल इवेंट्ि ्जिे onCreate, onStart, onResume, onPause, onStop, onDestroy)

येथे सलसहता येतात. उदाहरणाथि , onPause इवेंटमध्ये काही कोड करण्यािाठी:

@Override

protected void onPause() {

super.onPause();

// आपली एप्लक्टसवटी पॉज होत्यानंतर केलेले काम इथे सलहा.

}}

इतक्यात नकारात्मकी पाहूनही, आपली एप्लक्टसवटी चां गली दृष्टीने स्थासपत केली जाते , जी वापरकताा ना आपल्या
अॅप्लिकेशनमध्ये नेप्लव्हगेट करण्यात मदत करते.

२.सेि (Services)

िेवा हा एक घटक आहे जो दीघिकाो चालणाऱ्या ऑपरे शन्स करण्यािाठी पार्श्िभूमीत चालतो. उदाहरणाथि , वापरकताि
वेगळ्या अॅप्लिकेशनमध्ये अिताना िेवा पार्श्िभूमीत िंगीत िे करू शकते सकं वा एखाद्या सहृयाकलापािह वापरकत्याि च्या

परस्परिंवादाला अवरोसधत न करता नेटवकिवरून डे टा आणू शकते. िेवा ्Services) अॅप्लिकेशनमध्ये एक


महत्त्वाचं घटक आहे , ज्यामुोे लॉन्ग रसनंग ऑपरे शन्सिाठी वापरले जाते. या िेवेच्या कामां िाठी वापरकताि इं टरफेि सदले

जाते सकंवा वेररएं टि तयार करण्यात आलेली आहे .

अशा िेवेचे काम सनम्नसलप्लखत आहे :

बॅकग्राऊंड िोिेिेि ्Background Processes): िेवां ची एक मुख्य वापर म्हणजे च लॉन्ग रसनंग िसहृया िुरू करणे आहे ,
ज्यामुोे वापरकताि ऍप्लिकेशन बाहे रीला जाऊनिुद्धा त्याच्या ऍप्लिकेशनमध्ये काम करवू शकतो.
37 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

समसडया स्टर ीसमंग ्Media Streaming): िेवां चा वापर ध्वसन, प्लव्हसडओ सकंवा इतर समसडया डे टा स्टर ीसमंगिाठी केला जातो.
उदाहरणाथि , इं टरनेट रे सडयो ऍप्लिकेशन.

नेटवकि कॉल्स ्Network Calls): वापरकताि ऍप्लिकेशनमध्ये िेवेचे उपयोग नेटवकि कॉल्सिाठी होते , ज्यामुोे दू रस्थ
िेवां िह िंवाद स्थासपत करण्यात मदत करते.

पुष नोसटसफकेशन्स ्Push Notifications): िेवेचे वापर पुष नोसटसफकेशन स्थासपत करण्यात येते, ज्यामुोे वापरकत्याा ना

नवीन आपडे ट्ि सकंवा िुचना समोते.

अवकाशी डे टा सिं हृोनायझ ्Background Data Sync): िे वां मध्ये डे टा सिंहृोनायझ करणे , ज्यामुोे अवकाशी

ऍप्लिकेशनला ताजेतवार सकंवा नवीन डे टा िाप्त होते.

िंग्रसहत डे टा िबंधन ्Data Management): िेवें डे टाचे िंग्रहण करून वापरकत्याा ना एकाच स्थानी इतर ऍप्लिकेशनिह
िामासयक करण्याची क्षमता पुरवतात.

िेवां चे उपयोग अने क िकारे केले जाते आसण त्यां मध्ये काही िेवा स्थासनक ऍप्लिकेशनिाठी अितात त्यातील िेवा स्थासनक

डे टा अॅक्सेििाठी वापरले जाते. आपल्याला वापरकताि इं टरफेििह वापरकताा िाठी एक आपल्याच्या ऍप्लिकेशनमध्ये
िेवां ना िुरु करण्याची क्षमता पुरसवणारी िंिेषण एका महत्त्वाच्या घटकाची मान्यता आहे .

public class MyService extends Service {

िेवा ्Services) अॅप्लिकेशनमध्ये लॉन्ग रसनं ग ऑपरे शन्सिाठी वापरली जाते. या िेवेच्या उपयोगां िाठी Marathi

मध्ये एक उदाहरण सदलेले जाते:

सेिेची वडवफवनशन (Service Definition):

public class MyService extends Service {

// िेवेची आसण िंबंसधत लॉसजक स्थासपत करण्यािाठी खाि एप्लक्टसवटीने येईल.

@Override

public IBinder onBind(Intent intent) {

// यसद िेवेची बाइं सडं ग आवडते तर तु म्ही इथे IBinder िदान करू शकता.

38 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

return null;

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

// िेवेचे लॉसजक स्थासपत करण्यािाठी onStartCommand वापरा.

return START_STICKY;

@Override

public void onDestroy() {

super.onDestroy();

// िेवेचे दु लिक्ष केल्यानंतर केलेले काम.

}}

सेिेचे लॉवजक स्थ वपत करणे (Implementing Service Logic):

public class MyService extends Service {

private static final String TAG = "MyService";

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

// उदाहरणाथि , िेवेचे लॉसजक स्थासपत करा.

Log.d(TAG, "िेवा िुरू करत आहे ...");

// डे टा सिंहृोनायझ सकंवा इतर लॉसजक अिल्याि त्या तुम्हाला येथे सलहावं शकतं.

return START_STICKY;

39 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override

public void onDestroy() {

super.onDestroy();

Log.d(TAG, "िेवा िंपली आहे .");

// िेवेच्या बंद केल्यानंतर केलेले काम.

public IBinder onBind(Intent intent) {

// बाइं सडं ग केल्यानंतर तुम्ही काही परत दे ऊ इप्लिता अिल्याि त्यािाठी आणखी लॉसजक अिणे शकते.

return null;

}}

सेिेची शुरूआत आवण बांद करणे (Starting and Stopping the Service):

// िेवा िुरू करणे

Intent serviceIntent = new Intent(context, MyService.class);

context.startService(serviceIntent);

// िेवा बंद करणे

Intent serviceIntent = new Intent(context, MyService.class);

context.stopService(serviceIntent);

अशा िकारे , तुम्ही आपली िेवा िुरू करू शकता आसण बंद करू शकता. जर तुम्ही िेवेच्या द्वारे सकंवा त्याच्या िाथी

आपली ऍप्लिकेशनिाठी दु लिक्ष ऑपरे शन्स काढण्याची इिा निली तर तु म्ही startService() आसण stopService()
वापरू शकता.

३.ब्रॉडक स्ट ररसीव्हसश(Broadcast Receivers)

ब्रॉडकास्ट ररिीव्हिि इतर ऍप्लिकेशन्स सकंवा सिस्टमवरून ििाररत िंदेशां ना िसतिाद दे तात. उदाहरणाथि , ॲप्लिकेशन

इतर ऍप्लिकेशन्सना हे कोवण्यािाठी ब्रॉडकास्ट िुरू करू शकतात की काही डे टा सडव्हाइिवर डाउनलोड केला गेला
40 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

आहे आसण त्यां च्यािाठी वापरण्यािाठी उपलब्ध आहे , म्हणून हा ब्रॉडकास्ट ररिीव्हर आहे जो या िंिेषणात अडथोा
आणेल आसण योग्य कारवाई िुरू करे ल.

ब्रॉडकास्ट ररिीव्हर ब्रॉडकास्ट ररिीव्हर क्लािच्या िबक्लाि म्हणून अं मलात आणला जातो आसण ित्ये क िंदेश इं टेंट
ऑब्जेक्ट म्हणून ििाररत केला जातो.

public class MyReceiver extends BroadcastReceiver {

public void onReceive(context,intent){}

ब्रॉडकास्ट ररिीव्हर ्Broadcast Receiver) अॅप्लिकेशनमध्ये एक महत्त्वाचं घटक आहे , ज्यामुोे ऍप्लिकेशनमध्ये
घडणाऱ्या सवसशष्ट घटनां चे िुचना समोते. त्याचे मराठीतून एक उदाहरण दे खील सदले जाते.

// तुमचे ब्रॉडकास्ट ररिीव्हर जावा कोड

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.widget.Toast;

public class MyBroadcastReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

// ब्रॉडकास्ट िुचना समोल्यानंतर काही काम करण्यािाठी onReceive वापरा. उदाहरणाथि , एक "बॅटरी लाईफ लो

आहे " ब्रॉडकास्ट िुचना समोल्याि वापरकताा ना िूसचत करा.

String action = intent.getAction();

if (action != null && action.equals(Intent.ACTION_BATTERY_LOW)) {

// बॅटरी लाईफ लो आहे , त्या वापरकताा ना िूसचत करा.

showToast(context, "बॅटरी लाईफ लो आहे !");

41 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

} }

private void showToast(Context context, String message) {

Toast.makeText(context, message, Toast.LENGTH_SHORT).show();

}}

ब्रॉडकास्ट ररिीव्हरचे उपयोग केल्यानंतर, तुम्ही तो तुमच्या मनापािून लायब्ररीमध्ये तो नोंदवून, त्याची नोंदणी करू शकता.
त्यामुोे तो ऍप्लिकेशन चालसवण्यात येईल आसण त्याच्या ब्रॉडकास्ट िुचनां मध्ये तुम्हाला वाचण्यात येईल <!--

AndroidManifest.xml फाइलमध्ये ब्रॉडकास्ट ररिीव्हर नोंदवणे -->

<receiver

android:name=".MyBroadcastReceiver"

android:enabled="true"

android:exported="false">

<intent-filter>

<action android:name="android.intent.action.BATTERY_LOW" />

<!-- इतर आवश्यक ब्रॉडकास्ट िुचनां िाठी इथे तुमची नोंदणी करा -->

</intent-filter>

</receiver>

. उपरी कोडमध्ये , तुम्ही MyBroadcastReceiver नावाचं ब्रॉडकास्ट ररिीव्हर तयार केलं आहे . त्याचे काम onReceive
सवधीमध्ये केलं जातं. त्याचे एक उदाहरण म्हणून , तुम्ही बॅटरी लाईफ लो आहे अिल्याि वापरकताा ना िूसचत करण्यािाठी

ब्रॉडकास्ट ररिीव्हर तयार केलं आहे .

४.स मग्री प्रद ते(Content Providers)

िामग्री िदाता घटक सवनंतीनुिार एका अनुियोगावरून इतरां ना डे टा पुरवतो. अशा सवनंत्या ContentResolver वगाि च्या
पद्धती ंद्वारे हाताोल्या जातात. डे टा फाइल सिस्टीममध्ये , डे टाबेिमध्ये सकंवा इतरर पूणिपणे िंग्रसहत केला जाऊ शकतो.

42 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

िामग्री िदाता िामग्री िदाता वगाि चा उपवगि म्हणून कायाि प्लित केला जातो आसण त्याने API चा मानक िंच लागू करणे
आवश्यक आहे जे इतर अनुियोगां ना युतवहार करण्याि िक्षम करते. िामग्री िदाते ्Content Providers)

अॅप्लिकेशनमध्ये एक महत्त्वाचं घटक आहे , ज्यामुोे ऍप्लिकेशन्स एकमेकां चे डे टा िामासयक करू शकतात. त्यां चे मुख्य

कायि इतर अॅप्लिकेशन्सिोबत डे टा िामासयक करणे आहे , ज्यामुोे ते अॅप्लिकेशन्स एकमेकां ना डे टािह िंवाद स्थासपत
करू शकतात.

येथे िामग्री िदाते तयार करण्यािाठी एक उदाहरण आहे :

public class MyContentProvider extends ContentProvider {

public void onCreate(){}

// तुमचे िामग्री िदाते जावा कोड

import android.content.ContentProvider;

import android.content.ContentValues;

import android.content.UriMatcher;

import android.database.Cursor;

import android.net.Uri;

import android.util.Log;

public class MyContentProvider extends ContentProvider {

// एक यूसनक कोड िाठी उदाहरणाथि URI_MATCHER तयार करा

private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);

private static final int DATA_URI_CODE = 1;

private static final String AUTHORITY = "com.example.myapp.provider";

private static final String PATH_DATA = "data";

public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + PATH_DATA);

43 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

static {

URI_MATCHER.addURI(AUTHORITY, PATH_DATA, DATA_URI_CODE);

@Override

public boolean onCreate() {

// िामग्री िदाते तयार केल्यानंतर केलेले काम.

return true;

@Override

public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String
sortOrder) {

// डे टा िदान करण्यािाठी query मेथड वापरा. तुम्ही इथे तुमचे डे टाबेि क्वेरीि सलहू शकता.

Log.d("MyContentProvider", "Query: " + uri.toString());

return null;

@Override

public String getType(Uri uri) {

// MIME टाइप िदान करण्यािाठी getType मेथड वापरा.

return null;

@Override

public Uri insert(Uri uri, ContentValues values) {

44 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

// डे टा अंतभूित करण्यािाठी insert मेथड वापरा. तुम्ही इथे तुमचे डे टाबेिमध्ये डे टा इन्झेक्ट करू शकता.

Log.d("MyContentProvider", "Insert: " + uri.toString());

return null;

@Override

public int delete(Uri uri, String selection, String[] selectionArgs) {

// डे टा हटसवण्यािाठी delete मेथड वापरा. तुम्ही इथे तुमचे डे टाबेिमध्ये डे टा हटवू शकता.

Log.d("MyContentProvider", "Delete: " + uri.toString());

return 0;

@Override

public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {

// डे टा अद्यसतत करण्यािाठी update मेथड वापरा. तुम्ही इथे तुमचे डे टाबेिमध्ये डे टा अद्यसतत करू शकता.

Log.d("MyContentProvider", "Update: " + uri.toString());

return 0;

}}

िामग्री िदाते तयार केल्यानंतर, तुम्ही तो AndroidManifest.xml फाइलमध्ये नोंदवून घेऊ शकता आसण इतर
अॅप्लिकेशन्स तु मच्या िामग्रीिह िंवाद स्थासपत करू शकता.

<!-- AndroidManifest.xml फाइलमध्ये िामग्री िदाते नोंदवणे -->

<provider
android:name=".MyContentProvider"

android:authorities="com.example.myapp.provider"

android:exported="false" />

45 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

उपरील कोडमध्ये , MyContentProvider नावाचं िामग्री िदाते तयार केलं आहे . त्याचे मुख्य काम डे टा िदान करणे आहे .
तुम्ही इथे तुमचे डे टाबेि क्वेरीि वापरू शकता, आसण आपली िामग्री िदाते

content://com.example.myapp.provider/data URI सकंवा इतर अॅप्लिकेशन्सने त्याची िामग्री िुचवू शकतात.

अवतररक्त घटक

लेआउट (Layouts): लेआउटिाठी सवसवध लेआउट क्लािेि वापरतो, ज्यातील िामासयक व युतवप्लस्थत UI घटक

िमासहत केले जाते. िामान्य लेआउट क्लािेिेि म्हणजे च:

LinearLayout (सलसनअर लेआउट): घटकां चे एकच अनुहृम सकंवा पंक्तीत रचतो.

RelativeLayout (ररलेसटवलेआउट): घटके एकमेकां ि अथवा मूो आवकाशां सकंवा स्थानां तर करतो.

ConstraintLayout (कन्स्ट्रेंटलेआउट): िं घसटत UI सडझाइनिाठी िुचले लेआउट मॅनेजर.

सवजेट / दृश्य ्Widgets/Views): हे त्या वैयप्लक्तक UI कंपोनेंटि आहे त, ज्यामुोे वापरकते िंवाद स्थासपत करू शकतो.
िामान्य सवजेट्ि म्हणजेच:

TextView (टे क्स्टयुतू): टे क्स्ट दशिवतो.

EditText (एसडटटे क्स्ट): वापरकत्याा ना टे क्स्ट इनपुट करण्याची परवाह आहे .

Button (बटण): प्लक्लक केल्याि सहृया िुरू होईल.

ImageView (इमेजयुतू): इमेजेि दशिवतो.

CheckBox, RadioButton (चेकबॉक्स, रे सडओबटन): सनवडक करण्याचे कंटर ोल्स.

Spinner (प्लस्पनर): सनवडलेल्या आयटममधून एका सनवडणुकीिाठी डरॉप-डाउन मेनू.

RecyclerView (रीिायक्लरयुतू): स्क्रॉल करण्याची सकंमत आहे सकंवा सग्रडिाठी दशिसवण्याची सकंमत.

फ्रग्मेंट ्Fragment): फ्रग्में ट हे एप्लक्टसवटीचे एक भाग दशिवतात. ते िामान्यत: लचील आसण मॉड्युलर UI सडझाइन तयार
करण्यात वापरते.

इं टेंट ्Intent): इं टेंट्ि अॅप्लिकेशनमध्ये कंपोनेंट्िदरम्यान िंवाद िाधण्यािाठी वापरतात. ते एप्लक्टसवटीज,

िसवििेि, आसण ब्रॉडकास्ट िंदेशां िाठी िुरू करण्यािाठी वापरतात.

स्त्रोते ्Resources): हे लेआउट, प्लस्टरंग, सडमेंशन, रं ग आसण इतर िंिाधनां ची िामग्रीिाठी आहे , ज्यामुोे कोडपािून
िसतस्थानां तर वापरकत्याि ला दशिसवता येते.
46 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

डरॉयबल स्त्रोते ्Drawable Resources): इमेज, आकारे आसण इतर डरॉयबल पदाथाा िाठी वापरतात.

मॅसनफेस्ट फाइल ्Manifest File): AndroidManifest.xml फाइल ही अॅप्लिकेशनबद्दल िणालीला महत्त्वाची

मासहती दे ते, ज्यात एप्लक्टसवटीज, िसवििेि, परवाहने आसण इतर कॉप्लिगरे शनिह िंबंसधत मासहती आहे .

मध्ये वनदे वशक रचन (Directory structure in android)

सनदे सशका िंरचना कोणत्याही िकल्पाचा पाया आहे . हे एका कंटे नरिारखे कायि करते ज्यामध्ये आवश्यक

तकिशास्त्र, िसतमा, िानुकूलन त्याच्या वास्तसवक स्वरूपात अिते. एखाद्या िकल्पाच्या सनसमिती ्िंकलन) दरम्यान,
त्याला आवश्यक अिलेल्या ित्येक िकारच्या मालमत्ता शोधण्यािाठी या फोडरमध्ये पाहतो.

अँडरॉइड स्टु सडओ हा JetBrains िमुदायाने सवकसित केलेला असधकृत IDE (इं सटग्रेटेड डे व्हलपमेंट एन्व्हायनि मेंट) आहे जो

अॅप डे व्हलपमेंटिाठी Google द्वारे सवनामूल्य िदान केला जातो. अँडरॉइड आसकिटे क्चरचा िेटअप पू णि केल्यानंतर
आम्ही स्टु सडओमध्ये अँडरॉइड अॅप्लिकेशन तयार करू शकतो. आम्हाला ित्येक नमुना अनुियोगािाठी एक नवीन िकल्प

तयार करणे आवश्यक आहे आसण आम्हाला फोडरची रचना िमजली पासहजे. हे अिे सदिते:

आकृती १-Directory Structure

47 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

मध्ये लेआउट व्यिस्थ पक(Layout Manager in android)

१.LinearLayoutManager:

 ि पर:

 LinearLayoutManager हे एक पंप्लक्तबद्ध ्linear) लेआउट मॅनेजर आहे .

 त्यामुोे तुम्ही आपली घड्याोातील घटके एक ओोीत स्थानां तररत करू शकता.

 त्यात RecyclerView वापरल्याि िवोत्तम आहे .

सवकिन क्षेरात, LinearLayout हा एक महत्त्वाचा लेआउट मॉड्यूल आहे , ज्याने सवचारायला आपल्याला आपल्या

घड्याोात एक िोपं स्थान दे ते. यामध्ये आपल्याला आपल्या घड्याोात आपल्या घड्याोात घड्याोाचं स्थान समोतं.

या एका उदाहरणात, एक LinearLayout आहे ज्यामध्ये आपल्या घड्याोात दोन बटणे अितील. एका
activity_main.xml नावाच्या फाइलमध्ये तुम्हाला या कोडमध्ये आपले आपले XML फाइल अिावे लागेल:

LinearLayout उद हरण

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".MainActivity">

<!-- Add vertical in the android:orientation-->

48 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<Button

android:layout_width="match_parent"

android:layout_margin="10dp"

android:layout_height="wrap_content"/>

<Button

android:layout_width="match_parent"

android:layout_margin="10dp"

android:layout_height="wrap_content"/>

<Button

android:layout_width="match_parent"

android:layout_margin="10dp"

android:layout_height="wrap_content"/>

</LinearLayout>

Ouput:

आकृती 2-Output Linear Layout

49 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२. Absolute Layout

सवकिनातील Absolute Layout हे एक लेआउट मॅनेजर आहे , परं तु त्या वापरल्यामुोे अिा लेआउट तयार

करणे िवोत्तम नितं. Absolute Layout अनेक िमस्या दे ऊ शकतो आसण अन्य सडवाइिेििाठी िुिंगत नितो.

हे एक उदाहरण आहे की, तुम्ही एक Absolute Layout वापरता येथे किं आहे :

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical"

tools:context=".MainActivity">

<!--Creating a text view for heading on below line-->

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="90dp"

android:layout_y="350dp"

android:text="Absolute Layout in Android"

android:textColor="@android:color/black"

android:textSize="20sp"

android:textStyle="bold" />

50 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<!-- creating a text view for sub heading on below line-->

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_x="150dp"

android:layout_y="400dp"

android:text="Hello World"

android:textColor="@android:color/black"

android:textSize="18sp"

android:textStyle="bold" />

</AbsoluteLayout>

आकृती 3-Output Absolute Layout

३.Frame layout

51 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

अॅप्लिकेशन सवकिनातील एक इतर महत्त्वाचं लेआउट मॅनेजर आहे तो हा FrameLayout आहे . या लेआउटमध्ये ,
घटके ्जिे की बटणे , छायासचरे) एकमेकां चं वतिनीस्थान सकंवा प्लस्तसथस्थान घे तलं जातं. त्यामुोे , जेव्हा तुम्ही एक घटक

वापरता, तो इतर घटकां वर पररणाम होतो.

Example:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<ImageView

android:id="@+id/imgvw1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:scaleType="centerCrop"

android:src="@drawable/flimg" />

<TextView

android:id="@+id/txtvw1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="40dp"

android:background="#4C374A"

android:padding="10dp"

52 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="Grand Palace, Bangkok"

android:textColor="#FFFFFF"

android:textSize="20sp" />

<TextView

android:id="@+id/txtvw2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right|bottom"

android:background="#AA000000"

android:padding="10dp"

android:text="21/Aug/2017"

android:textColor="#FFFFFF"

android:textSize="18sp" />

Output:

आकृती 4-Output Frame Layout


53 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

वापरकताि िंगणकाच्या आकारानुिार, आसण त्यामुोे घटकां चं स्थान बदलून पहा. जर तु म्हाला एकमेकां चं स्थान वापरायचं
आहे तर FrameLayout एक चां गलं सवकल्प आहे . परं तु , त्याचं वापर केवो अवश्यक अिल्याि हे वापरा; अन्यथा

ConstraintLayout सकंवा RelativeLayout हे उत्तम आहे .

४.Table Layout:

सवकिनातील एक इतर महत्त्वाचं लेआउट मॅनेजर हे आहे "TableLayout". यातून तुम्ही एक टे बल स्वरुपाचं

लेआउट तयार करू शकता. टे बलमध्ये पंप्लक्तंतर, स्तंभ, आसण त्यां चं िमासवष्ट करण्याि िुगमता आहे .

खालील उदाहरणात तु म्ही TableLayout वापरून एक िाधा टे बल तयार करू शकता:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginTop="100dp"

android:paddingLeft="10dp"

android:paddingRight="10dp" >

<TableRow android:background="#0079D6" android:padding="5dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="UserId" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"
54 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_weight="1"

android:text="User Name" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Location" />

</TableRow>

<TableRow android:background="#DAE8FC" android:padding="5dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="1" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Suresh Dasari" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

55 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_weight="1"

android:text="Hyderabad" />

</TableRow>

<TableRow android:background="#DAE8FC" android:padding="5dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="2" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Rohini Alavala" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Guntur" />

</TableRow>

<TableRow android:background="#DAE8FC" android:padding="5dp">

<TextView

56 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="3" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Trishika Dasari" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Guntur" />

</TableRow>

</TableLayout>

57 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Output:

आकृती 5-Output Table Layout

५.Relative Layout:

अॅप्लिकेशन सवकिनातील एक इतर महत्त्वाचं लेआउट मॅनेजर हे "RelativeLayout" आहे . या लेआउटमध्ये ,

घटके एकमेकां चं स्थान आसण िंबंध सनमाि ण करण्यािाठी वापरतात. तुम्ही या लेआउटमध्ये सवसवध घटकां ना एकमेकां चं
िंबंध सदल्याने स्थान आसण अिलेलं युताि तयार करू शकता.

खालील उदाहरणात तु म्ही RelativeLayout वापरून एक िाधा लेआउट तयार करू शकता:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android">

<Button android:id="@+id/button1"

android:layout_width="wrap_content"
58 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_height="wrap_content"

android:text="Top Left Button"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Top Right Button"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"/>

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Bottom Left Button"

android:layout_alignParentLeft="true"

android:layout_alignParentBottom="true"/>

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

59 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="Bottom Right Button"

android:layout_alignParentRight="true"

android:layout_alignParentBottom="true"/>

<Button

android:id="@+id/button5"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Middle Button"

android:layout_centerVertical="true"

android:layout_centerHorizontal="true"/>

</RelativeLayout>

Output:

आकृती 6-Output Relative Layout

60 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

सांदभशसूची(Bibliography)

१ https://www.tutorialspoint.com/android/android_user_interface_layouts.htm

२ https://www.geeksforgeeks.org/components-android-application/
३ https://www.tutorialspoint.com/android/android_application_components.htm

४ https://www.tutlane.com/tutorial/android/android-application-components-activities-intents-
views-layouts-services

५ https://www.tutorialspoint.com/android/android_fragments.htm
६ https://info448-s17.github.io/lecture-notes/fragments.html

७ https://www.geeksforgeeks.org/android-ui-layouts/

61 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

घटक – IV (Unit –IV)


ट क (Designing User Interface With View)

गुण (12)

विषय वनष्पत्ती (Course Outcome):

 .

घटक वनष्पत्ती (Unit Outcome):

 .
 .


 (Date Picker) (Time Picker)

४.१.

४.१.१ ट ट (TextView):

(TextView )
. (TextView ) ,

. (XML )
( ) .

XML TextView

<TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Amrutvahini " />

ट ट (Attributes)

1. (id) : id .
.

<TextView android:id="@+id/simpleTextView"
62 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_width="wrap_content"
android:layout_height="wrap_content" />

2. ट (gravity):

(left), (right), (centre),


(top), (bottom), _ (center_vertical), _

(center_horizontal) .
<TextView android:id="@+id/simpleTextView"

android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:gravity="center_horizontal"/>
3. ट ट(text):

<TextView android:id="@+id/simpleTextView"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:text="Amrutvahini"

android:gravity="center_horizontal"/>
4. ट टक (textColor): textColor .

“― ” “― ” “― ” “― ” .
<TextView android:id="@+id/simpleTextView"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Amrutvahini"
android:layout_centerInParent="true"

android:textColor="#f00"/>
5. ट (textSize): textSize .

sp ( ) dp ( ) .
<TextView android:id="@+id/simpleTextView"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

63 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text=" Amrutvahini "


android:layout_centerInParent="true"

android:textSize="40sp" />

6. ट (textStyle): textStyle .
(Bold), (italic) (normal) .

“|” .
<TextView android:id="@+id/simpleTextView"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text=" Amrutvahini "


android:layout_centerInParent="true"

android:textSize="40sp"
android:textStyle="bold|italic"/>

7. क (background): (background)
. (drawable) .

<TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text=" Amrutvahini "

android:layout_centerInParent="true"
android:textSize="40sp"

android:textStyle="bold|italic"
”―‖‖‖” >

8. (padding): (padding) (left), (right), (top)


(bottom) .

<TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text=" Amrutvahini "

64 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_centerInParent="true"
android:textSize="40sp"

android:textStyle="bold|italic"

”―‖‖‖”
”‗‖ ”>

Example:

<TextView
android:id="@+id/simpleTextView"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="AbhiAndroid"
android:layout_centerInParent="true"

android:textSize="40sp"
android:padding="10dp"

android:textColor="#fff"
android:background="#000"/>

क ४.१

65 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४.१.२ टट ट (EditText)
, EditText .

.EditText TextView

. : EditText
.

(XML ) ( )
.

<EditText android:id="@+id/simpleEditText"

android:layout_height="wrap_content"
android:layout_width="match_parent"/>

ट ट (Attributes)
1. (id) : id .

.
< EditText android:id="@+id/simpleEditText"

android:layout_height="wrap_content"
android:layout_width="match_parent"/>

2. ट (gravity):
(left), (right), (centre),

(top), (bottom), _ (center_vertical), _ (center_horizontal)


.

< EditText android:id="@+id/simpleEditText"


android:layout_height="wrap_content"

android:layout_width="match_parent"
android:gravity="center_horizontal"/>

3. ट ट(text):
<EditText android:id="@+id/simpleEditText"

android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:text="Enter Email"
66 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

“ >

क ४.२

4. (hint): hint ,
.

.
<EditText android:id="@+id/simpleEditText"

android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:layout_centerInParent="true"
android:hint="Enter Your Name Here" />

क ४.३

5. ट टक (textColor): textColor .
“― ” “― ” “― ” “― ” .

6. ट (textSize): textSize .
sp ( ) dp ( ) .
67 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

7. ट (textStyle): textStyle .
(Bold), (italic) (normal) .

“|” .

8. ट क textColorHint: textColorHint
.

9. क (background): (background)
. (drawable) .

10. (padding): (padding) (left), (right), (top)


(bottom) .

11. टट (inputType): InputType

<EditText android:layout_width="match_parent"
android:layout_height="wrap_content" android:inputType="text"/>

क ४.४

<EditText android:layout_width="match_parent"

android:layout_height="wrap_content" and oid inputType=“numbe "/>

68 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ४.५

<EditText android:layout_width="match_parent"

android:layout_height="wrap_content" and oid inputType=“textpa wo d"/>

क ४.६

४.१.३ ट (Button)

, .
. , , .
69 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

TextView . ,
.

<Button android:id="@+id/simpleButton"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Submit"/>
ट ट (Attributes)

1. (id) : id .
2. ट (gravity): (left), (right),

(centre), (top), (bottom), _ (center_vertical), _


(center_horizontal) .

3. ट ट(text):
4. ट टक (textColor): textColor .

“― ” “― ” “― ” “― ” .
5. ट (textSize): textSize .

sp ( ) dp ( ) .
6. ट (textStyle): textStyle .

(Bold), (italic) (normal) .


“|” .

7. क (background): (background)
. (drawable) .

8. (padding): (padding) (left), (right), (top)


(bottom) .

9. ट drawableBottom: drawableBottom
.

<Button android:id="@+id/simpleButton"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:layout_centerInParent="true"

70 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:background="#147D03"
android:text="Download Code"

android:textSize="20sp"

android:padding="15dp"
android:textStyle="bold|italic"

android:drawableBottom="@drawable/ic_launcher"/>

क ४.७

drawableTop, drawableRight drawableLeft: drawableBottom

, .

४.१.४ ट ImageButton
, ImageButton .

.
.

ट ट (Attributes)
1. (id) : id .

2. src: src
.

<ImageButton android:id="@+id/simpleImageButton" android:layout_width="wrap_content"


android:layout_height="wrap_content"

android:src="@drawable/home" />

71 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ४.८

3. क (background): (background)

. (drawable) .
4. (padding): (padding) (left), (right), (top)

(bottom) .
5. ट paddingRight : .

6. paddingLeft : .
7. ट paddingTop : .

8. ट paddingBottom : .
<ImageButton android:id="@+id/simpleImageButton" android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:background="#000"

android:src="@drawable/home"
android:padding="30dp"/>

क ४.९
72 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४.१. ५ ट ट ToggleButton
, ToggleButton

/ .ToggleButton
, , , . / . .

ट ट (Attributes)
1. (id) : id

2. ट (gravity): (left), (right),


(centre), (top), (bottom), _ (center_vertical), _

(center_horizontal) .
3. ट ट textOn And textOff:

/ .
/ textOff .

.
4. क Checked:

(Checked) .
(true or false) (true)

(false) . (false) .
5. (padding): (padding) (left), (right), (top)

(bottom) .
6. ट paddingRight : .

7. paddingLeft : .
8. ट paddingTop : .

9. ट paddingBottom : .
10. ट टक (textColor): textColor .

“― ” “― ” “― ” “― ” .
11. ट (textSize): textSize .

sp ( ) dp ( ) .

73 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

12. ट (textStyle): textStyle .


(Bold), (italic) (normal) .

“|” .

13. क (background): (background)


. (drawable) .

<ToggleButton android:id="@+id/simpleToggleButton" android:layout_width="wrap_content"


android:layout_height="wrap_content"

android:checked="true"
android:layout_centerHorizontal="true"

android:textOff="Disable"
android:textOn="Enable"/>

क ४.१०

४.१. ६ ट RadioButton & RadioGroup:

, RadioButton .
.

. RadioButon

74 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

.
.

ट ट (Attributes)
1. (id) : id

2. क Checked:
(Checked) .

(true or false) (true)


(false) . (false)

.
3. ट ट(text):

4. ट टक (textColor): textColor .
“― ” “― ” “― ” “― ” .

5. ट (textSize): textSize
. sp ( ) dp ( ) .

6. ट (textStyle): textStyle .
(Bold), (italic) (normal) .

“|” .
7. ट drawableBottom: drawableBottom

.
8. ट drawableTop, ट drawableRight

drawableLeft: drawableBottom ,
.

Example of RadioButton
<RadioButton

android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:checked="true"

75 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_centerHorizontal="true"
android:text="Radiobutton1" />

क ४.११

Example of RadioGroup
<RadioGroup

android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/India"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"

android:checked="true"
android:text="India"

android:textColor="#154"
android:textSize="20sp"

android:textStyle="bold" />

76 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<RadioButton
android:id="@+id/US"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginLeft="20dp"

android:layout_marginTop="10dp"
android:checked="false"

android:text="US"
android:textColor="#154"

android:textSize="20sp"
android:textStyle="bold" />

<RadioButton

android:id="@+id/aus"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginLeft="20dp"

android:layout_marginTop="10dp"
android:checked="false"

android:text="Australlia"
android:textColor="#154"

android:textSize="20sp"
android:textStyle="bold" />

</RadioGroup>

77 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ४.१२

४.१ .७ क CheckBox
Android , .

/ .
CompoundButton .

ट ट (Attributes)
1. (id) : id

2. क Checked: (Checked)
. (true or false) (true)

(false) . (false)
.

3. ट ट(text):
4. ट टक (textColor): textColor .

“― ” “― ” “― ” “― ” .
5. ट (textSize): textSize .

sp ( ) dp ( ) .

78 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

6. ट (textStyle): textStyle .
(Bold), (italic) (normal) .

“|” .

7. ट drawableBottom: drawableBottom
.

8. ट drawableTop, ट drawableRight
drawableLeft: drawableBottom ,

.
<LinearLayout

android:layout_width="match_parent"
android:layout_height="match_parent" >

<CheckBox
android:id="@+id/India"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"

android:checked="true"
android:text="India"

android:textColor="#154"
android:textSize="20sp"

android:textStyle="bold" />
<CheckBox

android:id="@+id/US"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginLeft="20dp"

android:layout_marginTop="10dp"
android:checked="true"

79 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="US"
android:textColor="#154"

android:textSize="20sp"

android:textStyle="bold" />
<CheckBox

android:id="@+id/aus"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginLeft="20dp"

android:layout_marginTop="10dp"
android:checked="false"

android:text="Australlia"
android:textColor="#154"

android:textSize="20sp"
android:textStyle="bold" /></LinearLayout>

क ४.१३

४.१ .८ ProgressBar

,
. , (spinning wheel
80 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

) (horizontal bar )
(style) .

“ B ” . (indeterminate ) .

(cyclic animation ) .
.

:
1. getMax() – (maximum value)

. (Integer) .
ProgressBar simpleProgressBar=(ProgressBar) findViewById(R.id.simpleProgressBar);

int maxValue=simpleProgressBar.getMax();
2. getProgress() - (progress value) .

(progress value) . .
ProgressBar simpleProgressBar=(ProgressBar)findViewById(R.id.simpleProgressBar);

progressValue=simpleProgressBar.getProgress();
ट ट (Attributes)

1. (id) : id .
2. max: max

. 100, 200 .
3. (progress): 0

. .

Example
<ProgressBar

android:layout_width="match_parent"
android:layout_height="300dp"

style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:max="100"

android:progress="30" />

81 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ४.१४

(Spinning progressbar )

<ProgressBar
android:layout_width="match_parent"

android:layout_height="300dp"
android:max="100" />

4. indeterminate: indeterminate
indeterminate .

. .
.

<ProgressBar
android:layout_width="match_parent"

android:layout_height="300dp"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"

android:max="100"

82 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:progress="30"
android:indeterminate="true" />

क ४.१५
5. क (background): (background)

. (drawable) .
6. (progressDrawable): (progressDrawable)

.
Step 1: activity_main.xml main.xml .

<ProgressBar
android:id="@+id/simpleProgressBar"

android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:max="100"
android:progress="60"

android:layout_marginTop="100dp"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"

android:progressDrawable="@drawable/custom_progress"/>
Step 2: drawable folder drawable resource xml

custom_progress .
83 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

( drawable folder->new->drawable resource file)

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
<shape>

<gradient
― “

―‗ “
android:useLevel="true" />

</shape>
</item>

</layer-list>

क ४.१६

84 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४.२
४.२.१ List View:

ListView .

.
.ListView

ListView .
ListView .ListView

, ListView
.

ट ट (Attributes)

1. (id) : id .
2. divider: .

3. ट dividerHeight : . (
), ( ) ( ) .

4. listSelector: listSelector listView


.

.
:

Activity_main.xml
<?xml version="1.0"encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:orientation="vertical">

<ListView
android:id="@+id/simpleListView"

android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:divider="@color/material_blue_grey_800"
85 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:dividerHeight="1dp"/>
</LinearLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {


String fruits[]={"apple","banana","watermelon", “ ,"orange"};

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
ListView l=findViewById(R.id.simpleListView ) ;

ArrayAdapter arr=new ArrayAdapter(this,


android.R.layout.simple_spinner_dropdown_item,fruits);

l.setAdapter(arr);
}}

क ४. १७

४.२.२ Grid view


GridView - ( )

, ListAdapter
. .GridView

86 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

GridView ScrollView
. . GridView

, .

ट ट (Attributes)

1. (id) : id .
2. क numColumns: numColumns .

, “5” auto_fit.
3. horizontalSpacing: horizontalSpacing

. ( ), ( )
( ) .

4. टक verticalSpacing: verticalSpacing
. px, dp sp .

5. क columnWidth: columnWidth . px, dp


sp

6. strechMode
, .


none - .

spacingWidth - .
columnWidth - .

U − ..
:

Activity_main.xml
<GridView

android:id="@+id/grid"
android:layout_width="fill_parent"

android:layout_height="fill_parent"
android:numColumns="3"

android:verticalSpacing="3dp"
87 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:horizontalSpacing="3dp"
android:stretchMode="columnWidth"/>

MainActivity.java

public class MainActivity extends AppCompatActivity {


String fruits[]={"apple","banana","watermelon","Mango","orange"};

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GridView l=findViewById(R.id.grid) ;
ArrayAdapter arr=new ArrayAdapter(this,

android.R.layout.simple_spinner_dropdown_item,fruits);
l.setAdapter(arr);

}}

क ४. १८

88 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४.२.३ Image View


, .

. UI

UI
.

ट ट (Attributes)

1. (id) : id .
2. क (background): (background)

. (drawable) .
3. src: src

.
4. (padding): (padding) (left), (right), (top)

(bottom) .
5. ट paddingRight : .

6. paddingLeft : .
7. ट paddingTop : .

8. ट paddingBottom : .
:

<ImageView
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:src="@drawable/android"

android:background="#000"
android:padding="10dp"/>

89 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ४.१८

9. ट (scaleType):

. fit_xy,
center_crop, fitStart .

” ” ” Y”

क ४. १९ क ४.२०

४.२.४ Scroll view


ListView ( )

. ScrollView

90 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

(HorizontalScrollView) .

<ScrollView
android:id="@+id/scrollView"

android:layout_width="fill_parent"
android:layout_height="fill_parent">

<!-- ’ -->
</ScrollView>

<HorizontalScrollView

android:id="@+id/horizontalscrollView"
android:layout_width="fill_parent"

android:layout_height="fill_parent">
<-- ’ -->

</HorizontalScrollView >

ट ट (Attributes)
1. (id) : id .

2. (scrollbars): , scrollbars
. (vertical), (horizontal)

(none). HorizontalScrollView
.

४.२.५ ट क ट Toast and Custom toast alert

, .
.

. .
. .

91 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)


1. makeText(Context context, CharSequence text, int duration):

. ,

.
(constants):

.
1. LENGTH_LONG: .

.
2. LENGTH_SHORT: .

.
2. show(): . makeText()

.
3. setGravity(int,int,int): .

: , x y .
4. setText(CharSequences): .

makeText()
.

5. setDuration(int duration): .
makeText()

.
6. inflate(int, ViewGroup): xml .

.
7. setView(View): .

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

92 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainActivity">

<Button
android:id="@+id/showToastButton"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="showtoast"
android:layout_centerInParent="true"/>

</RelativeLayout>
MainActivity.java

import android.os.Bundle;
import android.view.View;

import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button showToastButton = findViewById(R.id.showToastButton);


showToastButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Hello Toast Alert!",


Toast.LENGTH_SHORT).show();

}});}}

93 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ट (Custom Toast)

, .

Step1: getLayoutInflater() inflate(int,


ViewGroup) XML .

Step 2: ( ) ,

Step 3: (setView) .

Step 4: show() .

क ट ट

<?xml version="1.0" encoding="utf-8"?>


<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=".MainActivity">
<Button

android:id="@+id/customToast"
android:layout_width="200dp"

android:layout_height="wrap_content"
android:layout_below="@+id/simpleToast"

android:layout_centerHorizontal="true"
android:layout_margin="50dp"

android:background="#0f0"
android:text="Custom Toast"

android:textColor="#fff"
94 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:textSize="20sp" />
</RelativeLayout>

res/layout -> New -> Layout Resource File xml


custom.xml .

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"

android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:background="#DAAA"
android:orientation="horizontal"

android:padding="8dp">
<ImageView

android:id="@+id/toastImageView"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_marginRight="8dp"

android:src="@drawable/a3"/>
<TextView

android:id="@+id/toastTextView"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:textColor="#FFF" />

</LinearLayout>

Mainactivity.java
package com.example.customtoast;

import androidx.appcompat.app.AppCompatActivity;
import android.view.Gravity;

95 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.view.LayoutInflater;
import android.view.View;

import android.widget.ImageView;

import android.widget.TextView;
import android.widget.Toast;

import android.widget.Button;
import android.view.ViewGroup;

import android.os.Bundle;
public class MainActivity extends AppCompatActivity {

Button customToast;
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
customToast = (Button) findViewById(R.id.customToast);

customToast.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


LayoutInflater in = getLayoutInflater();

View layout = in.inflate(R.layout.custom, (ViewGroup) findViewById(R.id.layout_root));


Toast toast = new Toast(getApplicationContext());

toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);

toast.show();
} }); }}

96 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४.३.

४.३.१ ट क TimePicker

क ४ .२१

, TimePicker AM/PM 24
. , .

TimePickerDialog .

ट ट (Attributes)
1. (id): id .

2. ट क timePickerMode:
.

ट क
1. setCurrentHour(integer currenthour):

. API 23
. api 23 setHour(Integer hour) .

.
2. setCurrentMinute(integer currentminute):

.
setMinute(Integer minute): setCurrentMinute() API 23 .

api 23 setMinute( ) .
.

3. getCurrentHour():

97 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

. getCurrentHour(): getCurrentHour()
API 23 . api 23 getHour() .

4. getCurrentMinute():

.getMinute(): getCurrentMinute() API 23 . api 23


getMinute() . .

5. setIs24HourView(boolean is24HourView):
24 AM/PM .

(true) (false) . 24
AM/PM

क ४.२२
6. is24HourView():

. 24
AM/PM .

7. setOnTimeChangedListener(TimePicker.OnTimeChangedListener
onTimeChangedListener):

.
onTimeChanged(TimePicker view, int hourOfDay, int minute)

,
.

Activity_main.xml
98 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<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=".MainActivity">

<TimePicker android:id="@+id/simpleTimePicker"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_centerHorizontal="true"

android:layout_marginTop="50dp"
android:background="#090"

android:padding="20dp"
android:timePickerMode="spinner" />

<TextView
android:id="@+id/time"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_centerHorizontal="true"
android:text="Time Is ::"

android:textColor="#090"
android:textSize="20sp"

android:textStyle="bold" />
</RelativeLayout>

99 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

MainActivity.java
import android.app.TimePickerDialog;

import android.graphics.Color;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.Menu;
import android.view.MenuItem;

import android.view.View;
import android.widget.TextView;

import android.widget.TimePicker;
import android.widget.Toast;

import java.util.Calendar;
public class MainActivity extends AppCompatActivity {

TextView time;
TimePicker simpleTimePicker;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

time = (TextView) findViewById(R.id.time);


simpleTimePicker = (TimePicker) findViewById(R.id.simpleTimePicker);

simpleTimePicker.setIs24HourView(false);
simpleTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {

@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {

Toast.makeText(getApplicationContext(), hourOfDay + " " + minute, Toast.LENGTH_SHORT).show();


time.setText("Time is :: " + hourOfDay + " : " + minute); // set the current time in text view

} }); }}

100 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

४.३.२ ट क DatePicker

, . UI ,

.
DatePickerDialog .

ट ट (Attributes)

1. (id): id .
2. ट क (datePickerMode): (spinner) (calendar)

क ४ .२३

3. (padding): (padding) (left), (right), (top)


(bottom) .

4. ट paddingRight : .
5. paddingLeft : .

6. ट paddingTop : .
7. ट paddingBottom : .

8. क (background): (background)

. (drawable) .

101 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

ट क
1. setSpinnersShown(boolean shown):

(true) (false) . ,
. .

क ४ .२४

2. getDayOfMonth(): .
.

3. getMonth(): .
.

4. getYear(): .
.

5. getFirstDayOfWeek(): .
.

Activity_main.xml

<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"

102 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity">

<DatePicker

android:id="@+id/simpleDatePicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#150"

android:datePickerMode="spinner" />

<Button

android:id="@+id/submitButton"

android:layout_width="200dp" android:layout_height="wrap_content"

android:layout_below="@+id/simpleDatePicker" android:layout_centerHorizontal="true"

android:layout_marginTop="50dp" android:background="#150"

android:text="SUBMIT" android:textColor="#fff"

android:textSize="20sp" android:textStyle="bold" />

</RelativeLayout>

MainActivity.java

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Menu;

103 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.view.MenuItem;

import android.view.View;

import android.widget.DatePicker;

import android.widget.Button;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

DatePicker simpleDatePicker;

Button submit;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

simpleDatePicker = (DatePicker) findViewById(R.id.simpleDatePicker);

submit = (Button) findViewById(R.id.submitButton);

submit.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// get the values for day of month , month and year from a date picker

String day = "Day = " + simpleDatePicker.getDayOfMonth();

String month = "Month = " + (simpleDatePicker.getMonth() + 1);

String year = "Year = " + simpleDatePicker.getYear();

// display the values by using a toast

104 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Toast.makeText(getApplicationContext(), day + "\n" + month + "\n" + year,


Toast.LENGTH_LONG).show(); } }); }}

(Bibliography)

https://abhiandroid.com/ui/datepicker

https://www.javatpoint.com/android-timepicker-example

https://www.javatpoint.com/android-ui-widgets-tutorial

https://www.tutorialspoint.com/android/android_widgets.htm

105 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

घटक – V (Unit –V)


ट ट (Activity and Multimedia with Databases)

गुण (20)

विषय वनष्पत्ती (Course Outcome):

घटक वनष्पत्ती (Unit Outcome):

 .

 .
 .

 .

५.१.

५.१.१ Intent

.
.

. ट
. ,

ट टट(Intent for Activity):

startActivity() . Intent
.startActivity()

टट(Intent for service):

106 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

. - ( : )

startService() .

startService()

क टट(Intent for BroadcastReceiver):

, .( ,

). , ,

. sendBroadcast()
.

1. ट (Explicit Intent)

.
(component) . :

.
.

Intent in = new Intent(getApplicationContext(), SecondActivity.class);


startActivity(in);

SecondActivity JAVA .

107 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ५.१

2. ट (Implicit Intent)

, .
. , (App Chooser

) . .
.

Syntax-

Intent i =new Intent(Intent.ACTION_VIEW);


-OR-

Intent i =new Intent(Intent.ACTION_SEND);

ACTION_VIEW .

ACTION_SEND
.

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

108 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_height="match_parent"

android:layout_width="match_parent"
android:orientation="vertical">

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:id="@+id/btn1"

android:text="Explicit Intent" />


<Button

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/btn2"
android:text="Implicit Intent" />

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Activity_second.xml

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"

109 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_height="match_parent">
<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent">
<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/t1"
android:text="second Activity"/>

</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

package com.example.intentdemo;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.content.Intent;

import android.net.Uri;
import android.view.View;

import android.widget.Button;
public class MainActivity extends AppCompatActivity {

Button explicit_btn,implicit_btn;
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
explicit_btn = (Button)findViewById(R.id.btn1);

implicit_btn = (Button) findViewById(R.id.btn2);


explicit_btn.setOnClickListener(new View.OnClickListener() {

110 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
public void onClick(View v) {

Intent intent = new Intent(MainActivity.this,SecondActivity.class);

startActivity(intent);
} });

implicit_btn.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse("https://www.amrutpoly.com"));
startActivity(intent);

} }); }}
AndroidMainfest.xml

<application
android:allowBackup="true" android:icon="@mipmap/ic_launcher"

android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:theme="@style/Theme.Intentdemo">

<activity android:name=".MainActivity">
<intent-filter>

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
</activity>

<activity android:name=".SecondActivity"></activity>
</application>

</manifest>

secondActivity.java
package com.example.intentdemo;

111 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;

import android.widget.Toast;
import android.widget.TextView;

import android.widget.Button;
public class SecondActivity extends AppCompatActivity {

Button b;
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_second);
Toast.makeText(getApplicationContext(), "We are moved to second

Activity",Toast.LENGTH_LONG).show();
}}

५.१.२ Intent-Filter

, (ActivityMainfest.xml)
.

,
. .

, .

ट ट (Attributes)

(icon): . @drawable/image_name.
(label): / .

(priority):
. AndroidManifest.xml .

,
:

112 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<action>
, . ,

<category>
, . , .

<data>
URI ( , , , ) MIME

, .
<activity android:name="ShareActivity"

<intent-filter>
<action android:name="android.intent.action.SEND"/>

<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>

</intent-filter></activity>
.

, .
, . ,

, .

५.२ ट

. .

.
.

. , MainActivity
.

.
(AndroidMainfest.xml)

.
113 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५.२.१ ट क Activity Life Cycle

OS .

. (created), (started), (restart),


(pause), (stop) (destroy) .

क ५.२

ट क (Activity created:onCreate()):

OS onCreate() .

onCreate(Bundle b) .
onCreate(Bundle b) .

, . onCreate(Bundle b)

114 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

. onStart( ) .
onCreate(Bundle b) .

ट क : Activity Started: onStart():

onStart() .
onStart() , onStart()

.onStart() onResume()
onStop() . onStart()

OS . , A
B , A

. A
A .

ट क : Activity Resumed onResume():

, .onResume() onStart( )
.

.
onResume()

onResume() .

ट Activity paused onPause()

, OS

onPause() ( )
. .

ट Activity Stopped: onStop():

. .
, 1 2 .

1 .

ट क Activity Restarted: onRestart():

115 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

.
onRestart() . ,

onRestart() .

onRestart() .

ट क Activity Destroyed: onDestroy():

.
.

. ,
.

import android.app.Activity;
import android.os.Bundle;

import android.util.Log;
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Log.d("lifecycle","onCreate invoked"); }
@Override

protected void onStart() {


super.onStart();

Log.d("lifecycle","onStart invoked"); }
@Override

protected void onResume() {


super.onResume();

Log.d("lifecycle","onResume invoked"); }
@Override

protected void onPause() {

116 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

super.onPause();
Log.d("lifecycle","onPause invoked"); }

@Override

protected void onStop() {


super.onStop();

Log.d("lifecycle","onStop invoked"); }
@Override

protected void onRestart() {


super.onRestart();

Log.d("lifecycle","onRestart invoked"); }
@Override

protected void onDestroy() {


super.onDestroy();

Log.d("lifecycle","onDestroy invoked"); }}

५.२.२ क क Broadcast Lifecycle

क Broadcast Receivers
.

(events . ,

,
. ,

. , .
. ,

(BroadcastReceiver) (BroadcastReceiver)

117 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

1 . Creating the Broadcast Receiver.

2 Registering Broadcast Receiver

क ५.३

क क . Creating the Broadcast Receiver

BroadcastReceiver
onReceive() .

public class MyReceiver extends BroadcastReceiver { @Override

public void onReceive(Context context, Intent intent) {


Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
}}
क क Registering Broadcast Receiver

AndroidManifest.xml
. ACTION_BOOT_COMPLETED MyReceiver

, .

<application android:icon="@drawable/ic_launcher"android:label="@string/app_name"
android:theme="@style/AppTheme" >

<receiver android:name="MyReceiver">
<intent-filter>

<action android:name="android.intent.action.BOOT_COMPLETED">
118 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

</action>
</intent-filter>

</receiver> </application>

System Broadcasts
1. and oid.intent.action.BATTERY_CHANGED

2. and oid.intent.action.BATTERY_LOW

3. and oid.intent.action.BATTERY_OKAY

.
4. and oid.intent.action.BOOT_COMPLETED

5. and oid.intent.action.BUG_REPORT
.

6. android.intent.action.CALL
.Perform a call to someone specified by the data.

7. android.intent.action.CALL_BUTTON
UI " " .

The user pressed the "call" button to go to the dialer or other appropriate UI for placing a call.
8. android.intent.action.DATE_CHANGED

.The date has changed.


9. android.intent.action.REBOOT

. Have the device reboot.

sendBroadcast() .

119 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Hello World!"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.broadcast;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
}}

120 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

androidmainifest.xml
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
package="com.example.broadcast">

<application
android:allowBackup="true"

android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"

android:theme="@style/Theme.Broadcast">
<activity android:name=".MainActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>

</activity>
<receiver android:name=".AirplaneModeChangeReceiver">

<intent-filter>
<action android:name="android.intent.action.AIRPLANE_MODE_CHANGED">

</action>
</intent-filter>

</receiver> </application></manifest>
AirplaneModeChangeReceiver.java

package com.example.broadcast;
import android.content.BroadcastReceiver;

import android.content.Context;
import android.content.Intent;

121 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.os.Build;
import android.provider.Settings;

import android.widget.Toast;

import androidx.annotation.RequiresApi;
public class AirplaneModeChangeReceiver extends BroadcastReceiver {

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override

public void onReceive(Context context, Intent intent) {


int value = 0;

try {
value = Settings.Global.getInt(context.getContentResolver(),

Settings.Global.AIRPLANE_MODE_ON);
} catch (Settings.SettingNotFoundException e) {

e.printStackTrace();
}

if (value==1) {
Toast.makeText(context, "AirPlane mode is on", Toast.LENGTH_SHORT).show();

} else {
Toast.makeText(context, "AirPlane mode is off", Toast.LENGTH_SHORT).show();

} }}
५.३

५.३.१ क Content Provider

. ContentResolver
.

, .
.

, , insert(),

122 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

update(), delete(), query() . SQlite


.

ContentProvider

API .
public class My Application extends ContentProvider { }

क ५.४

५.३.२ Fragments

क ५.५

123 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

.
- . . UI

.
. Fragment

Fragment
Fragment . ,

.
.

.
. API

11 . ,
. xml

. .

124 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

ट क

क ५.६

1. onAttach Activity ग्न

2. onC eate Bundle z

3. onC eateView LayoutInflate ,ViewG oup, Bundle

4. onActivityC eated Bundle

125 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

5. onViewStateRe to ed Bundle

6. onSta t
7. onRe ume

8. onPau e

9. onStop

10. onDe t oyView

11. onDe t oy

12. onDetach

Simple fragment example

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="fill_parent"
android:layout_height="fill_parent"

tools:context="com.example.fragment.MainActivity">
<fragment

android:id="@+id/fragment1"
android:name="com.example.fragment.Fragment1"

android:layout_width="0px"
126 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_height="match_parent"
android:layout_weight="1" />

<fragment

android:id="@+id/fragment2"
android:name="com.example.fragment.Fragment2"

android:layout_width="0px"
android:layout_height="match_parent"

android:layout_weight="1" />
</LinearLayout>

Mainactivity.java

package com.example.fragment;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}}

Fragment1.java
package com.example.fragment;

import android.os.Bundle;
import android.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;

import android.view.ViewGroup;
public class Fragment1 extends Fragment {

127 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

}
@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,


Bundle savedInstanceState) {

return inflater.inflate(R.layout.fragment1_view, container, false);


}}

fragment2.java

package com.example.fragment;
import android.os.Bundle;

import android.app.Fragment;
import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;

public class Fragment2 extends Fragment {


@Override

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

}
@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,


Bundle savedInstanceState) {

return inflater.inflate(R.layout.fragment2_view, container, false);


}}

128 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

fragment1_view.xml
<FrameLayout 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:background="#F5F5DC"
tools:context="com.example.fragment.Fragment1">

<TextView
android:layout_width="match_parent"

android:layout_height="match_parent"
android:text="fragment1" />

</FrameLayout>

Fragment2_view.xml
<FrameLayout 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:background="#F5F5DC"

tools:context="com.example.fragment.Fragment2">
<TextView

android:layout_width="match_parent"
android:layout_height="match_parent"

android:text="fragment2" />
</FrameLayout>

129 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५.४ Service

. ,
, .

UI ( ) .

५.४.१ Features of Service

1. UI

2. .

3. . -

4. stopSelf() stopService()
.

5. .
6. android.app.Service ContextWrapper

५.४.२ ट Android Platform service

. (Manager)

. getSystemService() .

Foreground Service

. ,
.

क Background Service

130 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

.
.

Bound Service

.
. bindService()

. ,
. ,

. ,
, .

५.४.३ क Defining new services

1.
<manifest ..>

<!-- other permissions go here -->


<application ...>

< ” ”>
...

</application>
</manifest>

2.
3. startService()

Intent i=new Intent(this,Myservice.class)


startService(i)

4. stopService()

131 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५.४.४ क Service Life cycle

. :

१) ट (Started service)

( ) startService() ,

. stopService() .

2) (Bound Service)

( . ) bindService() .
unbindService() .

. .
.

. . , (Activtiy <-> Service).


(Service -> Activtiy)

. : .

132 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ५ .७

onCreate() .
.

onStartCommand() startService()
. .

onBind() onBind
onUnbind()

onRebind() .. onUnbind

133 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

onDestroy() . . ,
, .

५.४.५ permission

. startService(),bindService(),stopService()

५.४.६ example of service

wifi service example

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">

<Button
android:id="@+id/button1"

android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_x="155dp"

android:layout_y="183dp"
android:text="Enable Wifi" />

<Button android:id="@+id/button2"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_x="155dp"

android:layout_y="246dp"
android:text="Disable Wifi" />

134 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

</AbsoluteLayout>
Mainactivity.java

package com.example.wifiservice;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;

import android.net.wifi.WifiManager;
import android.os.Bundle; import

android.view.View; import
android.widget.Button;

public class MainActivity extends AppCompatActivity {


Button enableButton,disableButton;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
enableButton=(Button)findViewById(R.id.button1);

disableButton=(Button)findViewById(R.id.button2);
WifiManager wifi = (WifiManager)

getApplicationContext().getSystemService(Context.WIFI_SERVICE);
enableButton.setOnClickListener(new View.OnClickListener(){

public void onClick(View v){


wifi.setWifiEnabled(true);

} });
disableButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

wifi.setWifiEnabled(false); }
});

}}

135 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.wifiservice">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />


<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"
android:theme="@style/Theme.Wifiservice">

<activity android:name=".MainActivity">
<intent-filter>

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
</activity>

</application>
</manifest>

Simple service example

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"

136 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

tools:context=".MainActivity">
<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:text="Start Service"

android:id="@+id/startservice"/>
<Button

android:id="@+id/stopservice"
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:layout_x="4dp"

android:layout_y="95dp"
android:text="Stop Service" />

</AbsoluteLayout>

MainActivity.java
package com.example.services;

import androidx.appcompat.app.AppCompatActivity;
import android.app.Service;

import android.content.Intent;
import android.os.Bundle;

import android.os.IBinder;
import android.view.View;

import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

137 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Button start = (Button) findViewById(R.id.startservice);


Button stop = (Button) findViewById(R.id.stopservice);

start.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

startService(new Intent(MainActivity.this, Myservice.class));


}

});
stop.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

stopService(new Intent(MainActivity.this, Myservice.class));


}

}); }}

MyService.java
package com.example.services;

import android.app.Service;
import android.content.Intent;

import android.os.IBinder;
import android.widget.Toast;

public class Myservice extends Service {


@Override

public IBinder onBind(Intent intent) {


return null;

}
public void onCreate() {

Toast.makeText(this, " MyService Created ", Toast.LENGTH_LONG).show();


}

138 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
public void onStart(Intent intent, int startId) {

Toast.makeText(this, " Service Started", Toast.LENGTH_LONG).show();

}
@Override

public void onDestroy() {


Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();

}
}

AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.services">
<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"
android:theme="@style/Theme.Services">

<activity android:name=".MainActivity">
<intent-filter>

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
</activity>

<service android:name=".Myservice" />


</application>

139 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

</manifest>

Playing Music using service

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"

tools:context=".MainActivity">
<Button

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:text="Start Service"
android:id="@+id/startservice"/>

<Button
android:id="@+id/stopservice"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_x="4dp"
android:layout_y="95dp"

android:text="Stop Service" />


</AbsoluteLayout>

MainActivity.java

package com.example.music_service;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

140 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.view.View;
public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
}

// Start the service


public void startService(View view) {

startService(new Intent(this, MyService.class));


}

// Stop the service


public void stopService(View view) {

stopService(new Intent(this, MyService.class));


}

}
MyService.java

package com.example.music_service;
import android.app.Service;

import android.content.Intent;
import android.media.MediaPlayer;

import android.os.IBinder;
import android.provider.Settings;

import android.widget.Toast;
public class MyService extends Service {

private MediaPlayer player;


public IBinder onBind(Intent intent) {

return null;
}

141 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

public void onCreate() {


Toast.makeText(this, "Service was Created", Toast.LENGTH_LONG).show();

public int onStartCommand(Intent intent, int flags, int startId) {


player = MediaPlayer.create(this, Settings.System.DEFAULT_RINGTONE_URI);

player.setLooping(true);
player.start();

Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();


return START_STICKY;

}
@Override

public void onDestroy() {


super.onDestroy();

player.stop();
Toast.makeText(this, "Service Stopped", Toast.LENGTH_LONG).show();

}}
AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.music_service">
<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"
android:theme="@style/Theme.Music_service">

<activity android:name=".MainActivity">
<intent-filter>

142 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>
<service android:name=".MyService" />

</application>
</manifest>

५.५

५.५.१ कट Android system architecture

१. ४ Refer 1.4 topic

५.५.२ क Multimedia framework

, , ,

/ h/w .
.

libmediajni, libmedia, libmediaplayservice, .


. Libmedia /

क ५ .८
143 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५.५.३ क play audio and video

Android / .

MediaPlayer .MediaPlayer .
MediaPlayer / . . MediaPlayer (pause) ,

. MediaPlayer (ms ),
.MediaPlayer (ms )

, , .
MediaPlayer , create() . MediaPlayer

. –

mediaPlayer.start();
mediaPlayer.pause();

start() , . pause ()

, .

mediaPlayer.reset()

, reset() . .

MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.song);

. MediaPlayer
.

MediaPlayer

1. isPlaying()

2. seekTo(position)

3. getCurrentPosition()
144 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

4. getDuration()

5. reset()

6. release()

7. setVolume(float leftVolume, float rightVolume)

8. setDataSource(FileDescriptor fd)

9. selectTrack(int index)

10. getTrackInfo()

<?xml version="1.0" encoding="utf-8"?>

<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=".MainActivity"

tools:ignore="HardcodedText">
<TextView

android:id="@+id/headingText"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_centerHorizontal="true"

android:layout_marginTop="32dp"
145 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="MEDIA PLAYER"
android:textSize="18sp"

android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:layout_below="@id/headingText"

android:layout_marginTop="16dp"
android:gravity="center_horizontal">

<Button
android:id="@+id/stopButton"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="STOP" />
<Button

android:id="@+id/playButton"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="PLAY" />

<Button
android:id="@+id/pauseButton"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="PAUSE" />
</LinearLayout>

</RelativeLayout>

package com.example.mediaplayer;
import android.media.MediaPlayer;

146 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import android.widget.Button;

import android.os.Bundle;
import android.provider.Settings;

import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

Button bPlay,bPause,bStop;
MediaPlayer mediaPlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mediaPlayer = MediaPlayer.create(this, Settings.System.DEFAULT_RINGTONE_URI);


bPlay = findViewById(R.id.playButton);

bPause= findViewById(R.id.pauseButton);
bStop = findViewById(R.id.stopButton);

bPlay.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View view) {


mediaPlayer.start();

Toast.makeText(getApplicationContext(),"PLaying song",Toast.LENGTH_SHORT).show();
} });

bPause.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View view) {


mediaPlayer.pause();

Toast.makeText(getApplicationContext(),"song paused",Toast.LENGTH_SHORT).show();
} });

147 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

bStop.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View view) {

mediaPlayer.stop();
Toast.makeText(getApplicationContext(),"song stopped",Toast.LENGTH_SHORT).show();

} }); }}

५.५.४ ट ट Text to Speech

.
. TextToSpeech

. , initListener
.initListener TextToSpeech ,

, . TextToSpeech

TextToSpeech tts=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener()


{ @Override

public void onInit(int status)

{
//specify properties of TextToSpeech

} });
setLanguage() . setLanguage

. U Y Y .
, TextToSpeech speak() .

TextToSpeech

1. addSpeech St ing text, St ing filename

2. getLanguage

3. i Speaking

148 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

4. setPitch(float pitch)

TextToSpeech .

5. setSpeechRate(float speechRate)
.

6. shutdown()
TextToSpeech .

7. stop()
.

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<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=".MainActivity"

android:transitionGroup="true">
<TextView android:text="Text to Speech" android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:id="@+id/textview"

android:textSize="35dp"
android:layout_alignParentTop="true"

android:layout_centerHorizontal="true" />
<EditText

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/editText"
android:layout_below="@+id/textview"

android:layout_marginTop="46dp"
android:hint="Enter Text"

149 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"
android:textColor="#ff7aff10"

android:textColorHint="#ffff23d1" />
<Button

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Text to Speech"
android:id="@+id/button"

android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"

android:layout_marginTop="46dp" />
</RelativeLayout>

MainActivity.java
package com.example.texttospeech;

import android.app.Activity;
import android.os.Bundle;

import android.speech.tts.TextToSpeech;
import android.view.View;

import android.widget.Button;
import android.widget.EditText;

import java.util.Locale;
import android.widget.Toast;

public class MainActivity extends Activity {


TextToSpeech t1;

EditText ed1;
Button b1;

150 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);

b1=(Button)findViewById(R.id.button);
t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {

@Override
public void onInit(int status) {

if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);

}
} });

b1.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


String toSpeak = ed1.getText().toString();

Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);

}
}); }

public void onPause(){


if(t1 !=null){

t1.stop();
t1.shutdown();

}
super.onPause();

}}

151 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५.५.५ Sensor

. - (motion),

(orientation ) (environmental conditions ) .


- (light),

(proximity), (rotation), (movements), (magnetic fields)


. .

(Motion Sensors)

. (accelerometers ),
(gravity sensors), (gyroscopes) (rotational vector

sensors) .

(Environmental sensors)

, (temperature)

(pressure), (illumination) (humidity). (barometers),


(photometers ) (thermometers) .

(Position sensors)

. (orientation sensors )
ग्न (magnetometers) .

API

(SensorManager) :
.

(Sensor) : , , .

ट (SensorEvent) : .

152 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

ट (SensorEventListener) ट :
. , SensorManager

. .

SensorManager sMgr;

sMgr = (SensorManager)this.getSystemService(SENSOR_SERVICE);

SensorManager getDefaultSensor()
.

Sensor light;

light = sMgr.getDefaultSensor(Sensor.TYPE_LIGHT);

, onAccuracyChanged and
onSensorChanged .

sMgr.registerListener(this, light,SensorManager.SENSOR_DELAY_NORMAL);

public void onAccuracyChanged(Sensor sensor, int accuracy)


{

// Do something here if the sensor accuracy changes.


}

public void onSensorChanged(SensorEvent event)


{

// Do something here if sensor data changes


}

getSensorList
. .

<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=".MainActivity"

153 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:transitionGroup="true">
<TextView android:text="Sensor " android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/textview"
android:textSize="35dp"

android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<TextView
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text=""

android:id="@+id/textView2"
android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"

android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

</RelativeLayout>

package com.example.sensor;
import android.app.Activity;

import android.hardware.SensorManager;
import android.os.Bundle;

import android.util.Log;
import android.view.Menu;

import android.view.MenuItem;
import android.view.View;

import android.widget.TextView;
import java.util.List;

154 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.hardware.Sensor;
import android.hardware.SensorManager;

public class MainActivity extends Activity {

TextView tv1;
private SensorManager mSensorManager;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv1 = (TextView) findViewById(R.id.textView2);


mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

List<Sensor> mList= mSensorManager.getSensorList(Sensor.TYPE_ALL);


for (int i = 1; i < mList.size(); i++) {

tv1.append("\n" + mList.get(i).getName() + "\n" + mList.get(i).getVendor() + "\n" +


mList.get(i).getVersion());

} }}

Program to print x y z axis


<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainActivity">
<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"

155 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"

android:id="@+id/textview2"/>
</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.sensorxyz;

import androidx.appcompat.app.AppCompatActivity;
import android.hardware.Sensor;

import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;

import android.hardware.SensorManager;
import android.os.Bundle;

import android.widget.TextView;
import java.util.List;

public class MainActivity extends AppCompatActivity implements SensorEventListener {


TextView tv1;

SensorManager mSensorManager;
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.textview2);

mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

List<Sensor> mList= mSensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);

mSensorManager.registerListener(this,mList.get(0),SensorManager.SENSOR_DELAY_NORMAL); }
@Override

156 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

public void onSensorChanged(SensorEvent sensorEvent) {


float value[]=sensorEvent.values;

tv1.setText("x="+value[0]+"y="+value[1]+"z="+value[2]);

}
@Override

public void onAccuracyChanged(Sensor sensor, int i) {


}}

Program to change background color when device is shuffled

package com.example.sensor;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.hardware.Sensor;

import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;

import android.hardware.SensorManager;
import android.os.Bundle;

import android.view.View;
import android.widget.RelativeLayout;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements SensorEventListener {


private SensorManager sensorManager;

private boolean isColor = false;


private long lastUpdate;

RelativeLayout c;
@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

157 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

setContentView(R.layout.activity_main);
//view.setBackgroundColor(Color.GREEN);

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

lastUpdate = System.currentTimeMillis();
c=findViewById(R.id.main);

}
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}
@Override

public void onSensorChanged(SensorEvent event) {


if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {

float[] values = event.values;


// Movement

float x = values[0];
float y = values[1];

float z = values[2];
float accelationSquareRoot = (x * x + y * y + z * z) / (SensorManager.GRAVITY_EARTH *

SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();

if (accelationSquareRoot >= 2) //it will be executed if you shuffle


{

if (actualTime - lastUpdate < 200) {


return; }

lastUpdate = actualTime; //updating lastUpdate for next shuffle


if (isColor) {

c.setBackgroundColor(Color.GREEN);
} else {

c.setBackgroundColor(Color.RED);
Toast.makeText(this, "shuffled", Toast.LENGTH_SHORT).show();

158 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

}
isColor = !isColor;

} } }

protected void onResume() {


super.onResume();

// register this class as a listener for the orientation and accelerometer sensors
sensorManager.registerListener((SensorEventListener)

this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);

}
protected void onPause() {

// unregister listener
super.onPause(); sensorManager.unregisterListener((SensorEventListener) this); }}

५.५.६ Async क Async tasks

AsyncTask
. .asynctask

.AsyncTasks
( ).

क ५ .९

159 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

,
. /

. AsyncTasks

.AsyncTask doInBackground()
GUI . onPostExecute()

UI .doInBackground
.

AsyncTask

onPreExecute() -
.

doInBackground() ,
asyncTask .

doInBackground(Params) – .
.

onP og e Update p og e … − , UI
, .

onPostExecute(Result) – ui .

Async ट क क
TypeOfVarArgParams – .

ProgressValue – .
onProgressUpdate() UI .

ResultValue – .

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"

160 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"
android:orientation="horizontal"

tools:context=".MainActivity">
<TextView

android:id="@+id/tv_time"
android:layout_width="wrap_content"

andr ”
android:textSize="10pt"

android:textColor="#444444"
android:layout_alignParentLeft="true"

android:layout_marginRight="9dip"
android:layout_marginTop="20dip"

android:layout_marginLeft="10dip"
android:text="Sleep time in Seconds:"/>

<EditText
android:id="@+id/in_time"

android:layout_width="150dip"
android:layout_height="wrap_content"

android:background="@android:drawable/editbox_background"
android:layout_toRightOf="@id/tv_time"

android:layout_alignTop="@id/tv_time"
android:inputType="number"/>

<Button
android:id="@+id/btn_run"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

161 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="Run Async task"


android:layout_below="@+id/in_time"

android:layout_centerHorizontal="true"

android:layout_marginTop="64dp" />
<TextView

android:id="@+id/tv_result"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:textSize="7pt"

android:layout_below="@+id/btn_run"
android:layout_centerHorizontal="true" />

</RelativeLayout>
MainActivity.java

package com.example.asynctaskdemo;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.os.AsyncTask;

import android.os.Bundle;
import android.view.View;

import android.widget.Button;
import android.widget.EditText;

import android.widget.TextView;
public class MainActivity extends AppCompatActivity {

private Button button;


private EditText time;

private TextView finalResult;


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

162 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

setContentView(R.layout.activity_main);
time = (EditText) findViewById(R.id.in_time);

button = (Button) findViewById(R.id.btn_run);

finalResult = (TextView) findViewById(R.id.tv_result);


button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

AsyncTaskRunner runner = new AsyncTaskRunner();


String sleepTime = time.getText().toString();

runner.execute(sleepTime); } });
private class AsyncTaskRunner extends AsyncTask<String, String, String> {

private String resp;


ProgressDialog progressDialog;

@Override
protected String doInBackground(String... params) {

publishProgress("Sleeping...");
try {

int time = Integer.parseInt(params[0])*1000;


Thread.sleep(time);

resp = "Slept for " + params[0] + " seconds";


} catch (InterruptedException e) {

e.printStackTrace();
resp = e.getMessage();

} catch (Exception e) {
e.printStackTrace();

resp = e.getMessage();
}

return resp;
}

163 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
protected void onPostExecute(String result) {

progressDialog.dismiss();

finalResult.setText(result);
}

@Override
protected void onPreExecute() {

progressDialog = ProgressDialog.show(MainActivity.this,"ProgressDialog","Wait for


"+time.getText().toString()+ " seconds");

}
@Override

protected void onProgressUpdate(String... text) {


finalResult.setText(text[0]);

}}}
५.६.१ क Audio capture

. MediaRecorder
. MediaRecorder .MediaRecorder

, MediaRecorder . .
MediaRecorder myAudio = new MediaRecorder();

(source), (output) (encoding)


. .

myAudio.setAudioSource(MediaRecorder.AudioSource.MIC);

myAudio.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myAudio.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);

myAudio.setOutputFile(outputFile);

,
(prepare) .
164 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

myAudioRecorder.prepare();
myAudioRecorder.start();

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools=http://schemas.android.com/tools

android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="horizontal"
tools:context=".MainActivity">

<TextView
android:id="@+id/txthead"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_centerHorizontal="true"
android:text="media recorder"

android:textAlignment="center"
android:textColor="@color/black"

android:textSize="30sp"
android:layout_gravity="center_horizontal" />

<TextView
android:id="@+id/idTVstatus"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_marginTop="150dp"
android:text="status"

165 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:textAlignment="center"
android:textSize="18sp"

android:gravity="center_horizontal" />

<LinearLayout
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:layout_centerInParent="true"

android:layout_marginTop="30dp"
android:orientation="horizontal"

android:weightSum="4">
<TextView

android:id="@+id/btnRecord"
android:layout_width="0dp"

android:layout_height="wrap_content"
android:layout_margin="5dp"

android:layout_weight="1"
android:background="@color/purple_500"

android:padding="5dp"
android:text="start_recording"

android:textAlignment="center"
android:textColor="@color/white"

android:gravity="center_horizontal" />
<TextView

android:id="@+id/btnStop"
android:layout_width="0dp"

android:layout_height="wrap_content"
android:layout_margin="5dp"

android:layout_weight="1"
android:background="@color/purple_500"

166 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:padding="5dp"
android:text="stop_recording"

android:textAlignment="center"

android:textColor="@color/white"
android:gravity="center_horizontal" />

<TextView
android:id="@+id/btnPlay"

android:layout_width="0dp
android:layout_height="wrap_content"

android:layout_margin="5dp"
android:layout_weight="1"

android:background="@color/purple_500"
android:padding="5dp"

android:text="play_recording"
android:textAlignment="center"

android:textColor="@color/white"
android:gravity="center_horizontal" />

<TextView
android:id="@+id/btnStopPlay"

android:layout_width="0dp"
android:layout_height="wrap_content"

android:layout_margin="5dp"
android:layout_weight="1"

android:background="@color/purple_500"
android:lines="2"

android:padding="5dp"
android:text="stop_playing"

android:textAlignment="center"
android:textColor="@color/white"

167 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:gravity="center_horizontal" />
</LinearLayout></RelativeLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="com.example.audio_capture">

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.STORAGE"/>
<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"
android:theme="@style/Theme.Audio_capture">

<activity android:name=".MainActivity">
<intent-filter>

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
</activity>

</application>
</manifest>

MainActivity.java

package com.example.audio_capture;
import android.content.pm.PackageManager;

168 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.media.MediaPlayer;
import android.media.MediaRecorder;

import android.os.Bundle;

import android.os.Environment;
import android.util.Log;

import android.view.View;
import android.widget.TextView;

import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import java.io.IOException;
import static android.Manifest.permission.RECORD_AUDIO;

import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;


public class MainActivity extends AppCompatActivity {

private TextView startTV, stopTV, playTV, stopplayTV, statusTV;


private MediaRecorder mRecorder;

private MediaPlayer mPlayer;


private static String mFileName = null;

public static final int REQUEST_AUDIO_PERMISSION_CODE = 1;


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
statusTV = findViewById(R.id.idTVstatus);

startTV = findViewById(R.id.btnRecord);
stopTV = findViewById(R.id.btnStop);

playTV = findViewById(R.id.btnPlay);
stopplayTV = findViewById(R.id.btnStopPlay);

169 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

stopTV.setBackgroundColor(getResources().getColor(R.color.gray));
playTV.setBackgroundColor(getResources().getColor(R.color.gray));

stopplayTV.setBackgroundColor(getResources().getColor(R.color.gray));

startTV.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


startRecording();

} });
stopTV.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

pauseRecording();} });
playTV.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

playAudio();
} });

stopplayTV.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


pausePlaying(); } }); }

private void startRecording() {


if (CheckPermissions()) {

stopTV.setBackgroundColor(getResources().getColor(R.color.purple_200));
startTV.setBackgroundColor(getResources().getColor(R.color.black));

playTV.setBackgroundColor(getResources().getColor(R.color.gray));
stopplayTV.setBackgroundColor(getResources().getColor(R.color.gray));

mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/AudioRecording.3gp";

170 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

mRecorder = new MediaRecorder();


mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(mFileName);

try {
mRecorder.prepare(); }

catch (IOException e) {
Log.e("TAG", "prepare() failed"); }

mRecorder.start();
statusTV.setText("Recording Started");

} else {
RequestPermissions(); } }

public void playAudio() {


stopTV.setBackgroundColor(getResources().getColor(R.color.black));

startTV.setBackgroundColor(getResources().getColor(R.color.purple_200));
playTV.setBackgroundColor(getResources().getColor(R.color.black));

stopplayTV.setBackgroundColor(getResources().getColor(R.color.purple_200));
mPlayer = new MediaPlayer();

try {
mPlayer.setDataSource(mFileName);

mPlayer.prepare();
mPlayer.start();

statusTV.setText("Recording Started Playing");


} catch (IOException e) {

Log.e("TAG", "prepare() failed");


} }

public void pauseRecording() {

171 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

stopTV.setBackgroundColor(getResources().getColor(R.color.black));
startTV.setBackgroundColor(getResources().getColor(R.color.purple_200));

playTV.setBackgroundColor(getResources().getColor(R.color.purple_200));

stopplayTV.setBackgroundColor(getResources().getColor(R.color.purple_200));
mRecorder.stop();

mRecorder.release();
mRecorder = null;

statusTV.setText("Recording Stopped"); }
public void pausePlaying() {

mPlayer.release();
mPlayer = null;

stopTV.setBackgroundColor(getResources().getColor(R.color.gray));
startTV.setBackgroundColor(getResources().getColor(R.color.purple_200));

playTV.setBackgroundColor(getResources().getColor(R.color.purple_200));
stopplayTV.setBackgroundColor(getResources().getColor(R.color.gray));

statusTV.setText("Recording Play Stopped"); }}

५.६.२ क camera

.
. :

क टट(Camera Intent)
.

MediaStore.ACTION_IMAGE_CAPTURE ACTION_VIDEO_CAPTURE
. MediaStore

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

172 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क API (Camera API)


.

. API :

1.CameraManager:

.
2.CameraDevice: .

3.CaptureRequest: .
4.CameraCaptureSession: CameraCaptureSession

.
5.CameraCaptureSession.CaptureCallback: .

क टक

क (Camera Permission) -
.

<uses-permission android:name="android.permission.CAMERA"/>
क (Camera Features) -

, :
<uses-feature android:name="android.hardware.camera" />

Storage Permission ) - Android 10 (API 29)


(SD )

.
<uses- “>

क (Audio Recording Permission) - ,


.

<uses-permission android:name="android.permission.RECORD_AUDIO" />

173 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Activity_main.xml

<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:gravity="center"
tools:context=".MainActivity">

<Button
android:id="@+id/button"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:textStyle="bold"
android:textSize="24sp"

android:text="Click here to take picture"


android:layout_centerHorizontal="true"

android:layout_marginTop="25sp"/>
<ImageView

android:id="@+id/imageView"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:scaleType="centerCrop"

android:layout_below="@id/button" />
</RelativeLayout>

MainActivity.java

package com.example.image_capture;

import android.content.Intent;
174 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.graphics.Bitmap;
import android.os.Bundle;

import android.view.View;

import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {

Button btnTakePhoto;
ImageView imageView;

public static final int RequestPermissionCode = 1;


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
btnTakePhoto = findViewById(R.id.button);

imageView = findViewById(R.id.imageView);
btnTakePhoto.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);


startActivityForResult(intent, 9);

} }); }
@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {


super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 9 && resultCode == RESULT_OK) {


Bitmap bitmap = (Bitmap) data.getExtras().get("data");

imageView.setImageBitmap(bitmap); } }}

175 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=http://schemas.android.com/apk/res/android

package="com.example.image_capture">
<uses-permission android:name="android.permission.CAMERA"></uses-permission>

<application
android:allowBackup="true"

android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"

android:theme="@style/Theme.Image_Capture">
<activity

android:name=".MainActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>

</activity>
</application>

</manifest>

५.७

५.७.१ ट Bluetooth

. API .

176 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

BluetoothAdapter . getDefaultAdapter()
. .

private BluetoothAdapter BA;


BA = BluetoothAdapter.getDefaultAdapter();

, ACTION_REQUEST_ENABLE
.

.
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(turnOn, 0);

API :
ACTION_REQUEST_DISCOVERABLE

ACTION_STATE_CHANGED

ACTION_FOUND

, getBondedDevices()
. . .

private Set<BluetoothDevice>pairedDevices;
pairedDevices = BA.getBondedDevices();

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

177 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools=http://schemas.android.com/tools

android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".MainActivity"

android:layout_margin="14dp"
android:orientation="vertical">

<TextView
android:id="@+id/textView"

android:layout_width="match_parent"
android:layout_height="wrap_content"

android:text="Bluetooth"
android:textSize="20dp"

android:textStyle="bold"/>
<Button

android:id="@+id/on"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Turn On" />

<Button
android:id="@+id/getvisible"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Get Visible" />


<Button

android:id="@+id/listdevice"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="List Devices" />

178 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<Button
android:id="@+id/off"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Turn OFF" />

<ListView
android:id="@+id/lv"

android:layout_width="279dp"
android:layout_height="284dp"/>

</LinearLayout>
MainActivity.java

package com.example.bluetoothpr24;
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE;

import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;

import java.util.Set;
public class MainActivity extends AppCompatActivity {

Button on,off,getvisible,listdevice;
final BluetoothAdapter bAdapter = BluetoothAdapter.getDefaultAdapter();

private Set<BluetoothDevice> pairedDevices;


ListView lv;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

on = (Button) findViewById(R.id.on);
off = (Button) findViewById(R.id.off);

getvisible = (Button) findViewById(R.id.getvisible);


listdevice = (Button) findViewById(R.id.listdevice);

179 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

lv = (ListView) findViewById(R.id.lv);
on.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {


bAdapter.enable(); } });

off.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


bAdapter.disable();

}});
getvisible.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

Intent getVisible = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);


startActivityForResult(getVisible, 0); } });

listdevice.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


pairedDevices = bAdapter.getBondedDevices();

ArrayList list = new ArrayList();


for(BluetoothDevice bt : pairedDevices) list.add(bt.getName());

Toast.makeText(getApplicationContext(), "Showing Paired Devices", Toast.LENGTH_SHORT).show();


ArrayAdapter adapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1, list);

lv.setAdapter(adapter); }
}); }}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="com.example.bluetoothpr24">

180 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />


<application

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"
android:theme="@style/Theme.BluetoothPr24">

<activity
android:name=".MainActivity"

android:exported="true">
<intent-filter>

<action android:name="android.intent.action.MAIN" />


<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
</activity>

</application>
</manifest>

181 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ५.१०

५.७.२ Animation

. .
.

(View Animation):
.

. . , ,
, , ,

, ,
. , ,

.
ट (Property Animation):

Android 3.0 (API 11) .


. , , ,

.
(Drawable Animation):

182 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

, Animation .
, AnimationUtils loadAnimation

.

Animation animation =AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);


animation.xml . res (res->anim->myanimation.xml)

Activity_main.xml
<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:paddingLeft="12dp"
android:paddingRight="12dp"

android:paddingTop="12dp"
android:paddingBottom="12dp" tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Alert Dialog"

android:id="@+id/textView"
android:textSize="35dp"

android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

183 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<TextView
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Amrutvahini"
android:id="@+id/textView2"

android:textColor="#ff3eff0f"
android:textSize="35dp"

android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />

<ImageView
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:id="@+id/imageView"

android:src="@drawable/download"
android:layout_below="@+id/textView2"

android:layout_alignRight="@+id/textView2"
android:layout_alignEnd="@+id/textView2"

android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"/>

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="zoom"

android:id="@+id/button"
android:layout_below="@+id/imageView"

android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"

android:layout_marginTop="40dp"
android:onClick="clockwise"/>

184 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="clockwise"
android:id="@+id/button2"

android:layout_alignTop="@+id/button"
android:layout_centerHorizontal="true"

android:onClick="zoom"/>
<Button

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="fade"
android:id="@+id/button3"

android:layout_alignTop="@+id/button2"
android:layout_alignParentRight="true"

android:layout_alignParentEnd="true"
android:onClick="fade"/>

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="blink"

android:onClick="blink"
android:id="@+id/button4"

android:layout_below="@+id/button"
android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />
<Button

android:layout_width="wrap_content"
android:layout_height="wrap_content"

185 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:text="move"
android:onClick="move"

android:id="@+id/button5"

android:layout_below="@+id/button2"
android:layout_alignRight="@+id/button2"

android:layout_alignEnd="@+id/button2"
android:layout_alignLeft="@+id/button2"

android:layout_alignStart="@+id/button2" />
<Button

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="slide"
android:onClick="slide"

android:id="@+id/button6"
android:layout_below="@+id/button3"

android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView" />

</RelativeLayout>

MainActivity.java
package com.example.animation;

import android.app.Activity;
import android.os.Bundle;

import android.view.View;
import android.view.animation.Animation;

import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import android.widget.Toast;
public class MainActivity extends Activity {

186 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

ImageView image;
@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

image= (ImageView)findViewById(R.id.imageView);
}

public void clockwise(View view){


Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),

R.anim.myanimation);
image.startAnimation(animation);

}
public void zoom(View view){

Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(),


R.anim.clockwise);

image.startAnimation(animation1);
}

public void fade(View view){


Animation animation1 =AnimationUtils.loadAnimation(getApplicationContext(),

R.anim.fade_animation);
image.startAnimation(animation1);

}
public void blink(View view){

Animation animation1 =AnimationUtils.loadAnimation(getApplicationContext(),


R.anim.blink_animation);

image.startAnimation(animation1);
}

public void move(View view){


Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);

187 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

image.startAnimation(animation1);
}

public void slide(View view){

Animation animation1 =AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);


image.startAnimation(animation1);

}}
blink_animation.xml

<?xml version="1.0" encoding="utf-8"?>


<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"

android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"

android:repeatMode="reverse"
android:repeatCount="infinite"/>

</set>
Clockwise.xml

<?xml version="1.0" encoding="utf-8"?>


<set xmlns:android="http://schemas.android.com/apk/res/android">

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"

android:toDegrees="360"
android:pivotX="50%"

android:pivotY="50%"
android:duration="5000" >

</rotate>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"

android:startOffset="5000"
android:fromDegrees="360"

188 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:toDegrees="0"
android:pivotX="50%"

android:pivotY="50%"

android:duration="5000" >
</rotate>

</set>
Fade_animation.xml

<?xml version="1.0" encoding="utf-8"?>


<set xmlns:android="http://schemas.android.com/apk/res/android"

android:interpolator="@android:anim/accelerate_interpolator">
<!-- duration is the time for which animation will work-->

<alpha
android:duration="1000"

android:fromAlpha="0"
android:toAlpha="1" />

<alpha
android:duration="1000"

android:fromAlpha="1"
android:startOffset="2000"

android:toAlpha="0" />
</set>

Move.xml
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"

android:fillAfter="true">
<translate

android:fromXDelta="0%p"
android:toXDelta="75%p"

189 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:duration="700" />
</set>

Myanimation.xml

<?xml version="1.0" encoding="utf-8"?>


<set xmlns:android="http://schemas.android.com/apk/res/android">

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.5"

android:toXScale="3.0"
android:fromYScale="0.5"

android:toYScale="3.0"
android:duration="5000"

android:pivotX="50%"
android:pivotY="50%" >

</scale>
<scale xmlns:android="http://schemas.android.com/apk/res/android"

android:startOffset="5000"
android:fromXScale="3.0"

android:toXScale="0.5"
android:fromYScale="3.0"

android:toYScale="0.5"
android:duration="5000"

android:pivotX="50%"
android:pivotY="50%" >

</scale>
</set>

Slide.xml
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >


<scale

190 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:duration="500"
android:fromXScale="1.0"

android:fromYScale="1.0"

android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"

android:toYScale="0.0" />
</set>

Zoom.xml
<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android=http://schemas.android.com/apk/res/android android:fillAfter="true" >


<scale

android:duration="500"
android:fromXScale="1.0"

android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"

android:toXScale="1.0"
android:toYScale="0.0" />

</set>
५.८

५.८.१ SQLite ट SQLite Database

SQLite SQL .
SQLite .

५.८.२ SQLite क Necessity of SQLite

SQLite . , JDBC, ODBC .

.
, .

191 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५.८.३ ट क Creation and connection of the database


SQLiteOpenHelper SQLite

.android.database.sqlite.SQLiteOpenHelper

. , SQLiteOpenHelper onCreate()
onUpgrade() .

SQLiteOpenHelper क
SQLiteOpenHelper .

SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)

, .

SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version,


DatabaseErrorHandler errorHandler)

, . .

SQLiteOpenHelper
public ab t act void onC eate SQLiteDataba e db

public ab t act void onUpg ade SQLiteDataba e db, int oldVe ion, int newVe ion

public ynch onized void clo e

SQLiteDatabase class

, , , .

SQLiteDatabase
void execSQL(String sql)

sql .
int update(String table, ContentValues values, String whereClause, String[] whereArgs)

192 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

.
long insert(String table, String nullColumnHack, ContentValues values)

. table ,nullColumnHack

. , , .
.

Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String
groupBy, String having, String orderBy)

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools=http://schemas.android.com/tools

android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainActivity">
<EditText

android:id="@+id/editText2"
android:layout_width="match_parent"

android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent" />
<Button

android:id="@+id/button1"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="submit"

193 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

app:layout_constraintBottom_toTopOf="@+id/button3"
app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText2" />
<Button

android:id="@+id/button3"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="show"

app:layout_constraintBottom_toTopOf="@+id/textView1"
app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText2"
app:layout_constraintVertical_bias="0.778" />

<TextView
android:id="@+id/textView1"

android:layout_width="259dp"
android:layout_height="212dp"

android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintHorizontal_bias="0.585"
app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.911" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

194 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

package com.example.sqlite_insert;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;
import android.content.Context;

import android.database.Cursor;
import android.os.Bundle;

import android.app.Activity;
import android.content.Intent;

import android.database.sqlite.SQLiteDatabase;
import android.text.Editable;

import android.view.Menu;
import android.view.View;

import android.view.View.OnClickListener;
import android.widget.Button;

import android.widget.EditText;
import android.widget.TextView;

import android.widget.Toast;
public class MainActivity extends Activity {

SQLiteDatabase Student_database;
@Override

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
final EditText eroll = (EditText)findViewById(R.id.editText2);

Button bsubmit = (Button)findViewById(R.id.button1);


Button bshow_details = (Button)findViewById(R.id.button3);

final TextView tvstuddetails = (TextView)findViewById(R.id.textView1);


String s;

195 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

bsubmit.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {

Student_database = openOrCreateDatabase("student", Context.MODE_PRIVATE,null);

//openOrCreateDatabase("student",null);
Student_database.execSQL("CREATE TABLE IF NOT EXISTS stud(name VARCHAR(20));");

String s, s1;
s1 = eroll.getText().toString();

Student_database.execSQL("INSERT INTO stud VALUES('" + s1 + "');");


Toast.makeText(getApplicationContext()," Record successfully

stored",Toast.LENGTH_LONG).show();
Student_database.close();

}
});

bshow_details.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {

Student_database = openOrCreateDatabase("student", Context.MODE_PRIVATE,null);


String s6;

int total = 0, n;
Cursor C3=Student_database.rawQuery("select * from stud;",null);

C3.moveToFirst();
if(!C3.isAfterLast())

{
do{

s6 = C3.getString(0);
tvstuddetails.append("\n" + s6);

}while(C3.moveToNext());
}

Student_database.close();
}

196 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

});
}}

Example 2
package com.example.sq;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.os.Bundle;
import android.view.View;

import android.widget.Button;
import android.widget.EditText;

import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {

Button b1,b2,b3;
TextView t;

SQLiteDatabase db;
String d1,d2,d3,d4,d5;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1=findViewById(R.id.b1);
b2=findViewById(R.id.b2);

b3=findViewById(R.id.b3);
t=findViewById(R.id.t);

197 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

db=openOrCreateDatabase("student", Context.MODE_PRIVATE, null);


db.execSQL("CREATE TABLE IF NOT EXISTS stud1(name VARCHAR(20),rollno NUMBER,marks

NUMBER,branch VARCHAR(20),per NUMBER);");

}
public void insert(View v){

db.execSQL("INSERT INTO stud1 VALUES('ajinkya',10,890,'CM',90);");


db.execSQL("INSERT INTO stud1 VALUES('abc',11,800,'CM',91);");

db.execSQL("INSERT INTO stud1 VALUES('pqr',10,870,'CM',78);");


db.execSQL("INSERT INTO stud1 VALUES('ijk',10,890,'CM',80);");

db.execSQL("INSERT INTO stud1 VALUES('lmn',10,690,'CM',67);");


Toast.makeText(this,"record inserted", Toast.LENGTH_LONG).show();

}
public void view(View v){

String s6;
int total = 0, n;

Cursor C3=db.rawQuery("select * from stud1;",null);


C3.moveToFirst();

if(!C3.isAfterLast())
{

do{
s6 = C3.getString(0)+C3.getInt(1)+C3.getInt(2)+C3.getString(3)+C3.getInt(4);

t.append("\n" + s6);
}while(C3.moveToNext());

} }
public void delete(View v){

db.execSQL("DELETE FROM stud1 where name="+"'ajinkya';");


Toast.makeText(this,"record deleted", Toast.LENGTH_LONG).show();

}}

198 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools=http://schemas.android.com/tools
android:layout_width="match_parent"

android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"

android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="insert"

android:onClick="insert"
android:id="@+id/b1"/>

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="view"

android:onClick="view"
android:id="@+id/b2"/>

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="delete"

199 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:onClick="delete"
android:id="@+id/b3"/>

<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/t"/>
</LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>

५.८.४ क क Extracting value from cursor

. .

1. abstract void close()


, .

2. abstract int getColumnCount()

3. abstract int getColumnIndex(String columnName)

- , -1.

4. abstract String getColumnName(int columnIndex)

- .

5. abstract String[] getColumnNames()

6. abstract int getCount()

7. abstract double getDouble(int columnIndex)

200 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

8. abstract float getFloat(int columnIndex)

9. abstract int getInt(int columnIndex)

int .

10. abstract long getLong(int columnIndex)

11. abstract short getShort(int columnIndex)

12. abstract String getString(int columnIndex)

13. abstract boolean moveToPrevious()

14. abstract boolean isAfterLast()

15. abstract boolean isBeforeFirst()

16. abstract boolean isClosed()

17. abstract boolean isFirst()

18. abstract boolean isLast()

201 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

19. abstract boolean isNull(int columnIndex)

20. abstract boolean move(int offset)

, .

21. abstract boolean moveToFirst()

22. abstract boolean moveToLast()

23. abstract boolean moveToNext()

.
24. abstract boolean moveToPosition(int position)

५.८.५ ट Transactions

void beginTransaction():transaction
void setTransactionSuccessful():the transaction .

void endTransaction(): setTransactionSuccessful() transaction


.

SQLiteDatabase.beginTransaction() . ,

(insert(), update(), delete()) .


, SQLiteDatabase.endTransaction() .

202 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

, , SQLiteDatabase.endTransaction()
SQLiteDatabase.setTransactionSuccessful() . endTransaction()

setTransactionSuccessful() , ,

. setTransactionSuccessful() endTransaction()
, setTransactionSuccessful() endTransaction() -

. ,
setTransactionSuccessful() endTransaction()

(Bibliography)

https://www.geeksforgeeks.org/multimedia-framework-in-android/

https://developer.android.com/media/platform/mediaplayer

https://www.javatpoint.com/playing-audio-in-android-example

https://www.javatpoint.com/android-sqlite-tutorial

https://www.geeksforgeeks.org/how-to-create-and-add-data-to-sqlite-database-in-android/

https://www.tutlane.com/tutorial/android/android-texttospeech-with-examples

203 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

घटक –६ (Unit –VI)


सुरक्ष आवण अनुप्रयोग उपयोजन (SECURITY AND APPLICATION DEPLOYMENT)

(Marks : 20) :२०

विषय वनष्पत्ती (Course Outcome):


 एिएमएि टे सलफोनी, स्थान आधाररत िेवा िदसशित करा आसण अँडरॉइड अॅप्लिकेशन िकासशत करा

घटक वनष्पत्ती (Unit Outcome):


 सदलेल्या स्थानावर आधाररत िेवा स्पष्ट करा

 वापरकत्याा िाठी सदलेल्या परवानग्या िानुकूसलत करण्यािाठी पायऱ्या सलहा.


 सदलेल्या िेवेची वैसशष्ट्ये स्पष्ट करा.

 सदलेला अनुियोग िकासशत करण्यािाठी पायऱ्या सलहा.

६.१ एां डरॉइडमध्ये SMS टे लीफोनी


, SMS SmsManager API SMS .

, .एं डरॉइड अॅप्लिकेशनच्या


सवकािात SMS टे लीफोनी वापरायची आवड अिते. SMS टे लीफोनीिाठी एं डरॉइडवर टे लीफोनी िेवा वापरून आसण

एिएमएि िोटोकॉल वापरून SMS पाठवणे आसण िाप्त करणे िंबंसधत आहे .
एक एं डरॉइड अॅप्लिकेशनमध्ये SMS टे लीफोनी वापरण्यािाठी, तुम्हाला टे लीफोनी िेवेची अनुमती समोवणे आवडे ल.

SEND_SMS अनुमतीची आवड आहे ज्यामुोे तुम्ही एिएमएि पाठवू शकता.


एक एं डरॉइड अॅप्लिकेशनमध्ये SMS पाठवताना, तुम्हाला एक SmsManager वापरायचा अिेल. त्यािाठी तुम्हाला खालील

कोड वापरायचा अिेल:


// एिएमएि पाठवताना

String phoneNumber = "िंदेशाचे िाप्तकताि हृमां क";


String message = "तुमचा िंदेश";

SmsManager smsManager =
SmsManager.getDefault();smsManager.sendTextMessage(phoneNumber, null, message, null, null);

यामुोे तुम्ही एक िामान्य एिएमएि पाठवू शकता.

SmsManager API
SmsManager smsManager = SmsManager.getDefault();

204 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);


Built-in SMS application

Intent sendIntent = new Intent(Intent.ACTION_VIEW);

sendIntent.putExtra("sms_body", "default content");


sendIntent.setType("vnd.android-dir/mms-sms");

startActivity(sendIntent);
Of course, both need SEND_SMS permission.

<uses-permission android:name="android.permission.SEND_SMS" />


Apart from the above method, there are few other important functions available in SmsManager

class.

Sr.No. Method & Description


१.ArrayList<String> divideMessage(String text)

ही पद्धत िंदेशाच्या मजकुराचे अनेक तुकड्यां मध्ये सवभाजन करते , कमाल SMS िंदेश आकारापेक्षा मोठा नाही.
२.static SmsManager getDefault()

ही पद्धत SmsManager चे डीफॉल्ट उदाहरण समोसवण्यािाठी वापरली जाते


३.void sendDataMessage(String destinationAddress, String scAddress, short destinationPort, byte[]

data, PendingIntent sentIntent, PendingIntent deliveryIntent)


ही पद्धत सवसशष्ट ऍप्लिकेशन पोटि वर डे टा आधाररत एिएमएि पाठवण्यािाठी वापरली जाते.

४.void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String>


parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)

मल्टी-पाटि टे क्स्ट आधाररत एिएमएि पाठवा.


५.void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent

sentIntent, PendingIntent deliveryIntent)


मजकूर आधाररत एिएमएि पाठवा.एं डरॉइडवर SMS िाप्त करण्यािाठी, तुम्ही SmsReceiver अिेही वापरू शकता. हे

एक बॅकग्रौंड िप्लव्हिि अिते ज्याने नवीन एिएमएि िाप्त केल्यावर तुमच्या अनुियोगाला िूचना दे ते.
उद हरण-

// Import necessary packages


import android.os.Build;

205 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.os.Bundle;
import android.telephony.TelephonyManager;

import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class PhoneInfoActivity extends AppCompatActivity {


@Override

protected void onCreate(@Nullable Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_phone_info);
// Get references to TextViews in the layout

TextView modelTextView = findViewById(R.id.modelTextView);


TextView manufacturerTextView = findViewById(R.id.manufacturerTextView);

TextView versionTextView = findViewById(R.id.versionTextView);


TextView imeiTextView = findViewById(R.id.imeiTextView);

// Get device information


String model = Build.MODEL;

String manufacturer = Build.MANUFACTURER;


String version = Build.VERSION.RELEASE;

// Display device information


modelTextView.setText("Model: " + model);

manufacturerTextView.setText("Manufacturer: " + manufacturer);


versionTextView.setText("Android Version: " + version);

// Get IMEI number


TelephonyManager telephonyManager = (TelephonyManager)

getSystemService(TELEPHONY_SERVICE);
if (telephonyManager != null) {

String imei = telephonyManager.getDeviceId();


imeiTextView.setText("IMEI: " + imei);

206 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

} else {
imeiTextView.setText("IMEI: Not available");

}
}

SmsManager

.
१. Android Studio IDE .

२. src/MainActivity.java
.

३. XML res/layout/activity_main.xml GUI .


GUI SMS SMS

.
४. res/values/strings.xml .

.
५. AndroidManifest.xml

६.
.

package com.example.;
import android.Manifest;

import android.content.pm.PackageManager;
import android.os.Bundle;

import android.app.Activity;
import android.support.v4.app.ActivityCompat;

import android.support.v4.content.ContextCompat;
import android.telephony.SmsManager;

import android.util.Log;
import android.view.Menu;

207 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import android.view.View;
import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;
public class MainActivity extends Activity {

private static final int MY_PERMISSIONS_REQUEST_SEND_SMS =0 ;


Button sendBtn;

EditText txtphoneNo;
EditText txtMessage;

String phoneNo;
String message;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sendBtn = (Button) findViewById(R.id.btnSendSMS);


txtphoneNo = (EditText) findViewById(R.id.editText);

txtMessage = (EditText) findViewById(R.id.editText2);


sendBtn.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {


sendSMSMessage();

}
});

}
protected void sendSMSMessage() {

phoneNo = txtphoneNo.getText().toString();
message = txtMessage.getText().toString();

if (ContextCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS)!=
PackageManager.PERMISSION_GRANTED) {

208 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {

} else {

ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},

MY_PERMISSIONS_REQUEST_SEND_SMS);
}

}
}

@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {

switch (requestCode) {
case MY_PERMISSIONS_REQUEST_SEND_SMS: {

if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

SmsManager smsManager = SmsManager.getDefault();


smsManager.sendTextMessage(phoneNo, null, message, null, null);

Toast.makeText(getApplicationContext(), "SMS sent.",


Toast.LENGTH_LONG).show();

} else {
Toast.makeText(getApplicationContext(),

"SMS faild, please try again.", Toast.LENGTH_LONG).show();


return;

} }
}

}
}

Following will be the content of res/layout/activity_main.xml file –


<?xml version="1.0" encoding="utf-8"?>

209 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

<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="MainActivity">

<TextView
android:id="@+id/textView1"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Sending SMS Example"


android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"
android:textSize="30dp" />

<TextView
android:id="@+id/textView2"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="Tutorials point "


android:textColor="#ff87ff09"

android:textSize="30dp"
android:layout_below="@+id/textView1"

android:layout_alignRight="@+id/imageButton"
android:layout_alignEnd="@+id/imageButton" />

<ImageButton
android:layout_width="wrap_content"

210 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_height="wrap_content"
android:id="@+id/imageButton"

android:src="@drawable/abc"

android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true" />

<EditText
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:id="@+id/editText"

android:hint="Enter Phone Number"


android:phoneNumber="true"

android:textColorHint="@color/abc_primary_text_material_dark"
android:layout_below="@+id/imageButton"

android:layout_centerHorizontal="true" />
<EditText

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:id="@+id/editText2"
android:layout_below="@+id/editText"

android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"

android:textColorHint="@color/abc_primary_text_material_dark"
android:layout_alignRight="@+id/imageButton"

android:layout_alignEnd="@+id/imageButton"
android:hint="Enter SMS" />

<Button
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Send Sms"

211 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:id="@+id/btnSendSMS"
android:layout_below="@+id/editText2"

android:layout_centerHorizontal="true"

android:layout_marginTop="48dp" />
</RelativeLayout>

Following will be the content of e /value / t ing .xml to define two new con tant −
<?xml version="1.0" encoding="utf-8"?>

<resources>
<string name="app_name">tutorialspoint</string>

</resources>
Following i the default content of And oidManife t.xml −

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.tutorialspoint" >
<uses-permission android:name="android.permission.SEND_SMS" />

<application
android:allowBackup="true"

android:icon="@drawable/ic_launcher"
android:label="@string/app_name"

android:theme="@style/AppTheme" >
<activity

android:name="com.example.tutorialspoint.MainActivity"
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>

212 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

</manifest>
Output:

क ६ .१

६.२ (Location based services in android)


,

. ,
API .

?
, , , .

क API क (Key)

Google Maps API Google Cloud Platform .

, Google Maps API


.

१.Google Cloud Platform क :


 Google Cloud Console Google .

213 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

२. क :
 , "Select a Project" "New Project"

३. API क :
 , "APIs & Services" > "Dashboard" .

 "Enable APIs and Services" "Maps SDK for Android" .


४.API Key क :

 "Credentials" > "Create Credentials" .


 "API key" API key "Android apps" "Android

package name" "SHA-1 certificate fingerprint" .


 "Restrict usage to your Android apps" "Create" .

५.API Key :
 , google_maps_api.xml .

 API key :
<resources>

<string name="google_maps_key" templateMergeStrategy="preserve"


translatable="false">YOUR_API_KEY_HERE</string>

</resources>
YOUR_API_KEY_HERE API XML .

Google Maps . API key


.

६.३ Google क

. Google ,
, . Google .

१.Google क क

Google , .
. .

214 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

: ,

: .
.

: , .
: . ,

.
क : .

Syntax of different types of map

googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);

Methods of Google map

Google नकाशा API अनेक पद्धती िदान करते ज्या Google नकाशा िानुकूसलत करण्यात मदत करतात. या पद्धती
खालीलिमाणे आहे त.

1.getMapAsync() मेथड:

 त्या कोड रृंगार करण्यािाठी वापरला जातो ज्यानुिार गुगल मॅपमध्ये ऑब्जेक्ट तयार करतो आसण त्याचं वापर
करतो. त्याचं एक िमुख उदाहरण खालीलिमाणे सदलं जातं.

mapView.getMapAsync(new OnMapReadyCallback() {

@Override

public void onMapReady(GoogleMap googleMap) {

// येथे तुमचं कोड सलहा

});

215 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

2. मैपिर स्थ न सेट करणे:

Google Map वर स्थान िे ट करण्यािाठी moveCamera() सकंवा animateCamera() मेथड वापरा.

LatLng location = new LatLng(मानचं अक्षां श, मानचं दे शां तर);

googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));

3. म कशर जोडणे:

स्थानां िह माकिर जोडण्यािाठी addMarker() मेथड वापरा.

googleMap.addMarker(new MarkerOptions()

.position(new LatLng(मानचं अक्षां श, मानचं दे शां तर))

.title("माकिरचं शीषिक")

.snippet("माकिरिोबत िंबंसधत िुचना"));

4. म नचां स्थ न आवण स्थ न अपडे ट करणे:

मानचं स्थान समोवण्यािाठी getMyLocation() मेथड वापरा. स्थान अपडे ट करण्यािाठी setMyLocationEnabled()
मेथड वापरा.

5. मैपिर Zoom करणे:

मैपवर Zoom करण्यािाठी moveCamera() सकंवा animateCamera() मेथडि वापरा.

6. म गश दशशविणे:

मागि दशिसवण्यािाठी Intent वापरा सकंवा Google Maps API वापरता तर त्यािाठी Direction API वापरा.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" +


destinationLat + "," + destinationLng));

startActivity(intent);

Example of Google Map


Google Maps , Google Maps API

. Google Maps :
१. Google Cloud Platform क :

 Google Cloud Console .


 Google .
२. क :

 "Select a project" - .
216 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

 "New Project" .
 "Create" .

३. Google Maps Platform क :

 .
 "Enable APIs and Services" .

 "Google Maps JavaScript API" "Google Maps Android API" .


४. API क क :

 "Credentials" .
 "Create Credentials" "API Key" .

 API .
५. Android Studio क क :

 Android Studio "Start a new Android Studio project" .


 .

 "Add an activity to Mobile" "Maps Activity" .


६. ट API क :

 "google_maps_api.xml" API .
 google_maps_api.xml <string name="google_maps_key"

templateMergeStrategy="preserve" translatable="false">YOUR_API_KEY</string>
YOUR_API_KEY API .

७. ट :
 "MapsActivity.java" .

import androidx.fragment.app.FragmentActivity;

import android.os.Bundle;
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;

217 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()


.findFragmentById(R.id.map);

mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {

mMap = googleMap;
// Add a marker in a location of your choice

LatLng sydney = new LatLng(-34, 151);


mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));

mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}}

८. ट :
 "res/layout/activity_maps.xml" XML .

<?xml version="1.0" encoding="utf-8"?>


<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=".MapsActivity">

<fragment

android:id="@+id/map"
218 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:name="com.google.android.gms.maps.SupportMapFragment"

android:layout_width="match_parent"

android:layout_height="match_parent" />

</RelativeLayout>

९. अॅप्लिकेशन रन कर :

• आपले अॅप्लिकेशन तयार केलं जाईल आसण आपले सडव्हाइि सकंवा एम्युलेटरवर रन करा.

क ६ .२

६.४ कट

,
. ( )

. API 29 .

क ६ .३

219 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

मध्ये Zoom Control अांमलबज िणीस ठी तुमचां ऍप Google Map ि परत असल्य स, ख लील मेथड् स
तुम्ह ल तुमच्य ऍपमध्ये Zoom Control जोडण्य त मदत करू शकत त:

1.CameraUpdateFactory.zoomIn() आवण CameraUpdateFactory.zoomOut() मेथड् स:


जे तुम्ही तुमच्या Zoom Control बटणां िह जोडलेलं अितं , त्यािाठी CameraUpdateFactory.zoomIn() आसण

CameraUpdateFactory.zoomOut() मेथड् ि वापरा. इ.ि. तुम्ही सजथे सतथे तुम्ही तुमचं मैप Zoom In आसण Zoom
Out करू शकता.

2. CameraUpdateFactory.newLatLngZoom(LatLng, float) मेथड:

या मेथडिाठी एक LatLng आसण एक float (Zoom Level) अिायचं. त्यानुिार, तुम्ही वापरकत्याि चं स्थान आसण त्यां चं
Zoom Level सदलेलं मैपवर Zoom करू शकता.

3. setOnCameraIdleListener() मेथड:

तुम्ही setOnCameraIdleListener() मेथड वापरून मैपवर Camera बदलतानाचं इवेंट िुसनसित करू शकता. तेव्हा
तुम्ही जेव्हा तु म्हाला मानचं आहे की Zoom नीटाचं बदललंय, तेव्हा तुम्ही कोड सलहू शकता.

4. setOnCameraMoveStartedListener() आवण setOnCameraMoveListener() मेथडस:

तुम्हाला जेव्हा तुम्हाला Zoom Control बटणंिह मैपवर Zoom करायचं तेव्हा तु म्ही
setOnCameraMoveStartedListener() आसण setOnCameraMoveListener() मेथडि वापरून कोड सलहू

शकता.reason मध्ये REASON_GESTURE, REASON_API_ANIMATION, आसण


REASON_DEVELOPER_ANIMATION यां ची मासहती सदली जाते.

या मेथड् िचं वापर करून तुम्ही तुमच्या ऍपमध्ये Zoom Control अंमलबजावणी करू शकता.

Example कट

ऍपमध्ये Zoom Control अांमलबज िणीस ठी ख लील पदक्रम ांवकांचे सुचन आहे:
1.Zoom Control जोड :

तुमच्या ऍपमध्ये Zoom Control जोडण्यािाठी, XML लेआउट फाइलमध्ये ZoomControls वापरा.
<ZoomControls

220 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:id="@+id/zoomControls"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="bottom|center" />
2. Zoom Control इवनवशयल ईज कर :

तुमच्या Java अॅप्लक्टसवटी/फ्रॅग्मेंटमध्ये , ZoomControls इसनसशयलाईज करा.


ZoomControls zoomControls = findViewById(R.id.zoomControls);

3. Google Map तय र कर (जर तुम्ही Google Maps ि परत तर):

तुम्ही Google Maps वापरता आहात तर, तुम्हाला Google Map तयार करावंता हवंचं आहे .
GoogleMap googleMap = ... // GoogleMap तयार करा

4. Zoom Control अांमलबज िणीसोबत सांप दन कर :

ZoomControls िोबत setOnZoomInClickListener आसण setOnZoomOutClickListener मेथड् ि वापरून जुनी


आसण नवीन प्लस्थतीवर Zoom करण्याचं िंपादन करा.

zoomControls.setOnZoomInClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

// Zoom In करण्यािाठी कोड


googleMap.animateCamera(CameraUpdateFactory.zoomIn());

}
});

zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


// Zoom Out करण्यािाठी कोड

googleMap.animateCamera(CameraUpdateFactory.zoomOut());
}

221 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

});
त्यािाठी तुम्ही CameraUpdateFactory.zoomIn() आसण CameraUpdateFactory.zoomOut() मेथड् िचं वापरून

Google Map अपडे ट करू शकता.

5. Optional: आपल्य ऍपमध्ये Zoom Level सोड :


जेव्हा तुम्ही Zoom Control वापरून Google Map अपडे ट करता तेव्हा तु म्ही Zoom Level वाचू शकता.

float zoomLevel = googleMap.getCameraPosition().zoom;


// आता zoomLevel वापरून तुम्ही काही करू शकता

जेव्हा तुम्ही तुमचं ऍप चालवलंय, तेव्हा तुम्ही Zoom Control वापरून स्थानां तर अथवा कोणत्याही इतर
उपयोगां िाठी स्थान िंपासदत करू शकता.

XML Code:
<?xml version="1.0" encoding="utf-8"?>

<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=".MainActivity">

<!--Adding the image view-->

<ImageView
android:id="@+id/image_View"

android:layout_width="match_parent"
android:layout_height="match_parent"

android:scaleType="fitXY"
android:src="@drawable/indiamap" />

<!--Adding the Zoom Controls


within the relative layout-->

<ZoomControls
android:id="@+id/zoom_controls"

222 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"
android:layout_margin="10dp" />

</RelativeLayout>

Java Code:
// Java code to implement the zoom controls

import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;

import android.os.Bundle;
import android.view.MotionEvent;

import android.view.View;
import android.widget.ImageView;

import android.widget.ZoomControls;
public class MainActivity extends AppCompatActivity {

ImageView imageView;
ZoomControls zoomControls;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageView=findViewById(R.id.image_View);

zoomControls=findViewById(R.id.zoom_controls);
zoomControls.setBackgroundColor(Color.BLACK);

zoomControls.show();
// onTouch listener function when the image is clicked

223 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

imageView.setOnTouchListener(
new View.OnTouchListener() {

@Override

public boolean onTouch(View view, MotionEvent motionEvent) {


zoomControls.show();

return false;
}

}
);

// This function will be automatically called out,when


// zoom in button is being pressed

zoomControls.setOnZoomInClickListener(
new View.OnClickListener() {

@Override
public void onClick(View view) {

float x=imageView.getScaleX();
float y=imageView.getScaleY();

// setting the new scale

imageView.setScaleX((float)(x+0.5f));
imageView.setScaleY((float)(y+0.5f));

zoomControls.hide();
}

}
);

// This function will be called when


// zoom out button is pressed

zoomControls.setOnZoomOutClickListener(
new View.OnClickListener() {

224 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
public void onClick(View view) {

float x=imageView.getScaleX();

float y=imageView.getScaleY();
if(x==1 && y==1)

{
// the scale will remain same,since

// it is maximum possible zoom out


imageView.setScaleX((float)(x));

imageView.setScaleY((float)(y));
zoomControls.hide();

}
else

{
// setting the new scale

imageView.setScaleX((float)(x-0.5f));
imageView.setScaleY((float)(y-0.5f));

// hiding the zoom controls


zoomControls.hide();

}
}

}
);

}
}

Output:

225 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

क ६.४

६.५ मध्ये Google नकाशे वर एकासधक माकिर किे जोडायचे ?


Google नकाशे बहुते क अॅ प्समध्ये वापरले जाते जे Google नकाशे वर अनेक स्थाने आसण माकिर दशिवण्यािाठी वापरले

जातात. (Markers) . Google


Maps .

import androidx.fragment.app.FragmentActivity;

import android.os.Bundle;
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;

226 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment)

getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

}
@Override

public void onMapReady(GoogleMap googleMap) {


mMap = googleMap;

// Add a marker at a location


LatLng markerLocation = new LatLng(-34, 151);

Marker marker = mMap.addMarker(new MarkerOptions().position(markerLocation).title("Marker


Title"));

// Move camera to the marker


mMap.moveCamera(CameraUpdateFactory.newLatLng(markerLocation));

// Set a listener for marker click events


mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker marker) {

// Handle marker click event


return false;

}
});

227 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

}}

1. LatLng markerLocation = new LatLng(-34, 151); -


.

2. Marker marker = mMap.addMarker(new


MarkerOptions().position(markerLocation).title("Marker Title")); -

.
3. mMap.moveCamera(CameraUpdateFactory.newLatLng(markerLocation)); -

.
4. mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {...}); -

.
Google Map वर Marker जोडण्याची िसहृया ऍपमध्ये िवाा िाठी एक अत्यंत महत्त्वाची सहृया आहे . खालील

िदसशित उदाहरणात, तुम्ही एक Google Map वर Marker जोडून त्यां चं स्थान दशिवू सशकून जुनी Marker िोडू आसण
नवीन Marker जोडूची िसहृया िां सगतली आहे :

1.Google Maps API Key प्र प्त कर :


Google Maps API सकंवा Google Places API वापरण्यािाठी तुम्हाला API की िाप्त करावी लागेल. त्यािाठी Google

Cloud Console वर जाऊन एक नवीन API की बनवा आसण त्याची कीवडि समोवा.
2.Google Maps Dependency जोड :

तुमच्या build.gradle फाइलमध्ये Google Maps dependency जोडून तुम्हाला तुमच्या ऍपमध्ये Google Maps वापरू
शकेल.

implementation 'com.google.android.gms:play-services-maps:17.0.1'
3.XML लेआउटमध्ये MapView जोड :

तुमच्या XML लेआउटमध्ये MapView जोडून तुम्ही Google Map दशिवू शकता.
<com.google.android.gms.maps.MapView

android:id="@+id/mapView"
android:layout_width="match_parent"

228 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:layout_height="match_parent"
android:apiKey="तुमचं API कीवडि "

map:cameraTargetLat="तुमचं स्थान अक्षां श"

map:cameraTargetLng="तुमचं स्थान दे शां तर" />


4.Map इवनवशयल ईज कर :

तुमच्या Java फाइलमध्ये , MapView इसनसशयलाईज करा आसण आपले Google Map वकि करून तयार करा.
MapView mapView = findViewById(R.id.mapView);

mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {

@Override
public void onMapReady(GoogleMap googleMap) {

// GoogleMap तयार झाल्यानं तर, तुम्हाला कोड सलहायचं आहे


}

});
5. मैपिर Marker जोड आवण क ही सुचन दशशि :

तुम्ही तुमच्या कोडमध्ये आपलं Marker जोडू शकता आसण कोणत्याही इतर िुचना दशिवू शकता.
. googleMap.addMarker(new MarkerOptions()

.position(new LatLng(तुमचं स्थान अक्षां श, तुमचं स्थान दे शां तर))


.title("तुमचं स्थान")

.snippet("तुमचं िुंदर स्थान"));

तुम्ही position, title, आसण snippet अशी मासहती जोडली आहे . position मध्ये स्थानाची अक्षां श आसण दे शां तर सदले
आहे , title मध्ये माकिरचं शीषिक, आसण snippet मध्ये माकिरिोबत िं बंसधत िुचना सदली आहे .

आता, तुमचं ऍप मैपवर Marker जोडून िुधाररत केलं आहे . तुम्ही अनेक Marker जोडून त्यां चं स्थान दशिवू

शकता आसण त्यां च्या िाथी इतर इन्टरे प्लक्टसवटीिह िंवाद िाधू शकता.

६.६ Geocoding and Reverse Geocoding

229 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

(Geocoding) .

(Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain

View, CA") into geographic coordinates (like latitude 37.423021 and longitude -122.083739), while
reverse geocoding is the process of converting geographic coordinates

Geocoding (Address to Coordinates):

1. Enable Geocoding API:

 Go to the Google Cloud Console.

 Enable the "Geocoding API" for your project.

2. Add Permissions: Open your AndroidManifest.xml and add the necessary permissions:

<uses-permission android:name="android.permission.INTERNET" />

क क क :
Implement Geocoding: Create a method to perform geocoding in your MapsActivity:

// MapsActivity.java
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;

import android.util.Log;
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;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {


private GoogleMap mMap;

230 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment)

getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

// Perform geocoding
geocodeAddress(" , , ");}

@Override
public void onMapReady(GoogleMap googleMap) {

mMap = googleMap;
}

private void geocodeAddress(String address) {


// Use Geocoding API to convert address to coordinates

Geocoder geocoder = new Geocoder(this);


try {

List<Address> addresses = geocoder.getFromLocationName(address, 1);


if (!addresses.isEmpty()) {

Address location = addresses.get(0);


LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15));
} else {

Log.e("Geocoding", "No results found");


}

} catch (IOException e) {
e.printStackTrace();

} }}

231 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Reverse Geocoding (Coordinates to Address):


(Reverse Geocoding) .

( . ) ,
.

1. Implement Reverse Geocoding: Create a method to perform reverse geocoding:

// MapsActivity.java
import android.location.Address;

import android.location.Geocoder;
import android.os.Bundle;

import androidx.fragment.app.FragmentActivity;
import android.util.Log;

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 java.io.IOException;

import java.util.List;
import java.util.Locale;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {


private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

232 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

SupportMapFragment mapFragment = (SupportMapFragment)


getSupportFragmentManager().findFragmentById(R.id.map);

mapFragment.getMapAsync(this);

// Perform reverse geocoding


reverseGeocodeLocation(18.5204, 73.8567);

}
@Override

public void onMapReady(GoogleMap googleMap) {


mMap = googleMap;

}
private void reverseGeocodeLocation(double latitude, double longitude) {

// Use Geocoding API to convert coordinates to address


Geocoder geocoder = new Geocoder(this, Locale.getDefault());

try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

if (!addresses.isEmpty()) {
Address address = addresses.get(0);

String addressString = address.getAddressLine(0);


Log.d("Reverse Geocoding", "Address: " + addressString);

} else {
Log.e("Reverse Geocoding", "No results found");

}
} catch (IOException e) {

e.printStackTrace();
}

}
}

िेिहोडर "YOUR_API_KEY_HERE" ला google_maps_api.xml फाईलमधील तुमच्या वास्तसवक Google Maps


API कीिह बदलण्याची खारी करा. तिेच, API की िुरसक्षतपणे हाताोा.

233 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Geocoder एक मधील वापरकत्याा ना स्थानाची मासहती िदान करण्यािाठी अिलेली क्लाि आहे . ती सकंवा
सतच्या getFromLocation() आसण getFromLocationName() मेथड् ििह तुम्ही एक स्थानाची मासहती िाप्त करू

शकता.

खालीलिमाणे उपयोग करा:


1.getFromLocation() मेथड:

या मेथडने एक सदलेल्या अक्षां श आसण दे शां तरािाठी स्थानाची मासहती िाप्त करते.
2.getFromLocationName() मेथड:

या मेथडने एक सदलेल्या स्थानाचं नां व वापरून स्थानाची मासहती िाप्त करते.


इथे, "स्थानाचं नां व" तुमचं शोधणारं स्थान आहे . आसण समोवण्यािाठी_मानचं_सकंवा_वाचक वापरल्याि तुम्ही त्यां ना समोवू

शकता सकंवा त्यां चं वाचू शकता.


या मेथड् िमध्ये , Address ऑब्जेक्टचं वापर करून तु म्ही स्थानाचं नां व, अक्षां श, दे श, राज्य, आसण इतर मासहती समोवू

शकता.

Here's an example of using the Geocoder class in an Android activity:


import android.content.Context;

import android.location.Address;
import android.location.Geocoder;

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;

import java.util.List;
import java.util.Locale;

public class GeocoderExampleActivity extends AppCompatActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
// Example of using Geocoder for reverse geocoding

234 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Geocoder geocoder = new Geocoder(this, Locale.getDefault());


double latitude = 37.7749;

double longitude = -122.4194;

try {
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

if (!addresses.isEmpty()) {
Address address = addresses.get(0);

Log.d("Geocoder", "Address: " + address.getAddressLine(0));


} else {

Log.e("Geocoder", "No results found");


}

} catch (IOException e) {
e.printStackTrace();

}
}

अँडरॉइड वजओकोडर िगश ररव्हसश वजओकोवडां गस ठी पद्धती प्रद न करतो,(methods for reverse geocoding)

Android मध्ये Reverse Geocoding सकंवा स्थानाच्या अक्षां श आसण दे शां तरानुिार स्थानाची मासहती िाप्त करण्यािाठी
Geocoder क्लािचं getFromLocation() मेथड वापरलं जातं. Reverse Geocoding मेथडि चुसकचं अक्षां श आसण

दे शां तर समोवणे आवडतं आहे आसण ते किं काम करतं याचं िराव िदान करतं.
खालीलिमाणे Reverse Geocoding किं काम करतं याचं दाखवतो:

येथे, latitude आसण longitude अिेही तुम्हाला समोसवतलं स्थानाचं अक्षां श आसण दे शां तर. getFromLocation()
मेथडचं सतिचं वापर करून तुम्ही एक List<Address> समोवु शकता. आपल्याला इथे वापरलेलं 1 हे सकती लोकेशंिेि

तुम्हाला समोसवतलंय याचं एक नमुनं आहे .


तुम्ही Address ऑब्जेक्ट मध्ये स्थानाचं नां व, अक्षां श, दे श, सपनकोड, राज्य, आसण इतर मासहती समोवू शकता. आपल्याला

त्यां ची सवसशष्टता सनसदि ष्ट करण्यािाठी तुम्ही यारेतली getMaxAddressLineIndex() मेथड वापरू शकता. उदाहरणाथि ,
address.getMaxAddressLineIndex() हे त्यां चं पूणि पत्तंग सकतीला लां बंवाचं आहे याचं माप दे ईल.

235 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Example:

import android.content.Context;

import android.location.Address;
import android.location.Geocoder;

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;

import java.util.List;
import java.util.Locale;

public class ReverseGeocoderExampleActivity extends AppCompatActivity {


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
// Example of using Geocoder for reverse geocoding

Geocoder geocoder = new Geocoder(this, Locale.getDefault());


double latitude = 37.7749;

double longitude = -122.4194;


try {

List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1); if


(!addresses.isEmpty()) {

Address address = addresses.get(0);


Log.d("Geocoder", "Address: " + address.getAddressLine(0));

} else {
Log.e("Geocoder", "No results found");

}
} catch (IOException e) {

236 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

e.printStackTrace();
}

हे उदाहरण ररव्हिि सजओकोसडं गिाठी सजओकोडर क्लािचा वापर दाखवते , सनदे शां कां ना मानवी वाचनीय पत्त्यामध्ये
रूपां तररत करते. या उदाहरणात getFromLocation पद्धत वापरली आहे .

६.७Android – Location स्थान आधाररत िेवा


(Location) ,

API . API
, , .

API .
.

सनसमितीिाठी ऍपमध्ये स्थान िोडवण्याचे कायि करण्यािाठी खालील पदहृमां सकंचे िुचना आहे :

1.स्थान िुचवा:
स्थान वापरण्यािाठी तु मच्या ऍपमध्ये एक MapView वापरा. त्यािाठी, तुम्ही build.gradle फाइलमध्ये Google

Maps dependency जोडू शकता.


implementation 'com.google.android.gms:play-services-maps:17.0.1'

2. API की सवनंती:
Google Maps API की सवनंतीिाठी Google Cloud Platform (GCP) वर एक पयाि यी खाते तयार करा. API कीवडि

घेऊन तुम्ही आपल्या ऍपमध्ये स्थान िुचवू इप्लिता अिलेल्या API कीवड्ि ि काढू शकता.
3. Google Maps API कीवड्ि ि जोडा:

तुमच्या AndroidManifest.xml फाइलमध्ये Google Maps API कीवड्ि ि जोडून स्थान िुचवण्यािाठी API कीवडि
नोंदवा.

<application>
<!-- आपली API कीवडि जोडा -->

<meta-data
android:name="com.google.android.geo.API_KEY"

237 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

android:value=" API_kayword " />


</application>

4. मैप वापरणे:

तुमच्या ऍपमध्ये एक MapView ठे वा सजतके तु म्हाला स्थान िुचवायचं आहे .


<com.google.android.gms.maps.MapView

android:id="@+id/mapView"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:apiKey=" API_kayword "

map:cameraTargetLat="तुमचं _स्थान_अक्षां श"


map:cameraTargetLng="तुमचं _स्थान_दे शां तर" />

तुमचं स्थान अक्षां श आसण दे शां तर लाभल्याि, तुम्ही तुमच्या ऍपमध्ये वापरकत्याा िाठी िुरसक्षत वापरण्यािाठी त्याचं
उपयुक्त िेसटं ग करू शकता.

5.मैपवर स्थान ठे वणे आसण अपडे ट करणे:

तुमच्या ऍपमध्ये MapView तयार झाल्यानंतर, तुम्हाला तु मच्या कोडमध्ये तुमचे स्थान ठे वण्यािाठी आसण स्थान अपडे ट
करण्यािाठी त्याचं वापर करण्याचं आवश्यक आहे .

// तुमचं MapView आसण GoogleMap ऑब्जेक्ट तयार करा


MapView mapView = findViewById(R.id.mapView);

mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {

@Override
public void onMapReady(GoogleMap googleMap) {

// GoogleMap तयार झाल्यानंतर, तुमच्या कोडमध्ये स्थान ठे वा आसण अपडे ट करा


LatLng location = new LatLng(तुमचं _स्थान_अक्षांश, तुमचं _स्थान_दे शां तर);

googleMap.addMarker(new MarkerOptions().position(location).title("तुमचं स्थान"));


googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));

}});

238 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

त्यािाठी तुमचं स्थान अक्षां श आसण दे शां तर वापरा आसण तुमचं ऍपमध्ये स्थानाचं मैप दशिवा.आपलं ऍप यारां त
स्थान िोडवण्याची क्षमता अिणे तुमचं ऍप वापरकत्याा ि आपलं ऍप आसण सवसशष्ट क्षेरातील स्थान दशिवण्याि िुधाररत

करू शकेल.

:
1. , Manifest.permission.ACCESS_FINE_LOCATION

Manifest.permission.ACCESS_COARSE_LOCATION .
2. FusedLocationProviderClient .

3. requestLocationUpdates .
4. , .

६.८ The Location Object स्थान ऑब्जेक्ट

स्थान ऑब्जेक्ट भौगोसलक स्थानाचे िसतसनसधत्व करते ज्यामध्ये अक्षां श , रे खां श, टाइम स्टॅ म्प आसण इतर मासहती जिे की
बेअररं ग, उं ची आसण वेग यां चा िमावेश अिू शकतो. खालील महत्त्वाच्या पद्धती आहे त ज्या तु म्ही स्थान सवसशष्ट मासहती

समोसवण्यािाठी स्थान ऑब्जेक्टिह वापरू शकता.


स्थ न ऑब्जेि पद्धती:

मध्ये Location ऑब्जेक्ट हे स्थानाच्या मासहतीिाठी वापरलेलं आहे . जेव्हा तुम्हाला आपल्या ऍपमध्ये
स्थानाचं टर ॅ सकंग करण्याची आवड अिते , तेव्हा तुम्ही Location ऑब्जेक्ट वापरू शकता. खालीलिमाणे , तुम्हाला आपल्या

Location ऑब्जेक्टमध्ये िं ग्रसहत केलेली मासहती काही महत्त्वाची आहे :


1. Latitude आवण Longitude वमळि :

getLatitude() आसण getLongitude() मेथडिाठी वापर करा.


2. Altitude वमळि (जर उपलब्ध आहे):

hasAltitude() आसण getAltitude() मेथडिाठी वापर करा.


3. Speed (गवत) वमळि (जर उपलब्ध आहे):

hasSpeed() आसण getSpeed() मेथडिाठी वापर करा.


4. Accuracy वमळि :

getAccuracy() मेथडिाठी वापर करा.


5. Time (समय) वमळि :

getTime() मेथडिाठी वापर करा.


6. Provider वमळि :

239 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

getProvider() मेथडिाठी वापर करा.


7. समय नुस र Location अपडे ट केलेलां आहे की न ही ते तप स :

isFromMockProvider() मेथडिाठी वापर करा.

६.९ Get the Current Location


(Current Location)

API .
Google Map .

, LocationClient , ()

getLastLocation() .

. , −
• GooglePlayServicesClient.ConnectionCallbacks
• GooglePlayServicesClient.OnConnectionFailedListener

क ( क क ) abstract void onConnected(Bundle connectionHint)


.

connect() .
() () onDisconnected()

- .

( )

, , LocationListener

. ,

( )

LocationClient .

240 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

Example:
import android.Manifest;

import android.content.pm.PackageManager;

import android.location.Location;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;

import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.location.FusedLocationProviderClient;

import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationResult;

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;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;


private FusedLocationProviderClient fusedLocationClient;

private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;


@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_maps);
fusedLocationClient = new FusedLocationProviderClient(this);

SupportMapFragment mapFragment = (SupportMapFragment)


getSupportFragmentManager().findFragmentById(R.id.map);

mapFragment.getMapAsync(this);
// Check and request location permission

241 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,

Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},


LOCATION_PERMISSION_REQUEST_CODE);

}
else {

// Permission already granted, start location updates


startLocationUpdates();

}
}

@Override
public void onMapReady(GoogleMap googleMap) {

mMap = googleMap;
// Map initialization code...

// Request location updates when the map is ready


startLocationUpdates();

}
private void startLocationUpdates() {

fusedLocationClient.requestLocationUpdates(createLocationRequest(), new LocationCallback() {


@Override

public void onLocationResult(LocationResult locationResult) {


if (locationResult != null) {

Location location = locationResult.getLastLocation();


LatLng currentLatLng = new LatLng(location.getLatitude(), location.getLongitude());

mMap.moveCamera(CameraUpdateFactory.newLatLng(currentLatLng));
// You can use the current location as needed in your app

}
}

242 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

}, null);
}

private void stopLocationUpdates() {

fusedLocationClient.removeLocationUpdates(new LocationCallback());
}

@Override
protected void onDestroy() {

super.onDestroy();
stopLocationUpdates();

}
private static int UPDATE_INTERVAL = 5000; // 5 seconds

private static int FASTEST_INTERVAL = 3000; // 3 seconds


private LocationRequest createLocationRequest() {

LocationRequest locationRequest = LocationRequest.create();


locationRequest.setInterval(UPDATE_INTERVAL);

locationRequest.setFastestInterval(FASTEST_INTERVAL);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

return locationRequest;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull

int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// Permission granted, start location updates


startLocationUpdates();

} else {
// Permission denied, handle accordingly

243 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

} } }}
.

ACCESS_FINE_LOCATION ACCESS_COARSE_LOCATION

६.१० क क ट क Monitoring location in android


.

, :
1.स्थान िेवा स्वीकृती:

तुमच्या अॅपला स्थान िेवा स्वीकृती दे णे आवडे ल. त्यािाठी AndroidManifest.xml फाइलमध्ये खालील इम्पोटि
जोडा:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


आपल्या ऍपला वापरकत्याा कडून स्थान िेवा स्वीकृती समोवण्यािाठी तुमचं ऍपलं सवनामूल्य िेवा िदान करू शकता.

2. LocationManager वापरणे:
तुमच्या एप्लिकेशनमध्ये LocationManager चा वापर करून स्थान तपािण्याि िुरुवात करा

LocationManager locationManager = (LocationManager)


getSystemService(Context.LOCATION_SERVICE);

3.LocationListener स्थासपत करा:

एक LocationListener इं स्टॅन्स तयार करून स्थानाची बदलाची िुचना समोवा.

LocationListener locationListener = new LocationListener() {


public void onLocationChanged(Location location) {
// स्थान बदलल्यानंतर केल्या जातात
double latitude = location.getLatitude();
double longitude = location.getLongitude();
// तुमच्या कोडमध्ये तुमचे काम करा
}

public void onStatusChanged(String provider, int status, Bundle extras) {}

public void onProviderEnabled(String provider) {}

public void onProviderDisabled(String provider) {}


};
244 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

4. स्थान िुरसक्षत करा:


तुमच्या एप्लिकेशनला स्थान िुरसक्षत करण्यािाठी तु म्ही वापरकत्याा कडून स्थान िेवा िक्षम/अक्षम करू शकता.

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) ==

PackageManager.PERMISSION_GRANTED) {
// स्थान िेवा िक्षम आहे

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
} else {

// स्थान िेवा िक्षम निल्याि स्थान िेवा स्वीकृती मागवा


ActivityCompat.requestPermissions(this, new

String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}

5.स्थान िुरसक्षत करणे आसण अद्यसतत करणे:


तुमच्या एप्लिकेशनमध्ये तु म्हाला स्थान िुरसक्षत करण्यािाठी आसण स्थान अपडे ट करण्यािाठी आपल्या कोडमध्ये

आवश्यक बदल करा.


या कोडमुोे, तुमचं ऍप वापरकत्याा ि स्थानाची सनगरानी करू शकेल.

६.११ द्वारे िदान केलेली िुरक्षा वैसशष्ट्ये

.
1. :

 , .
.

2. :

.
, .

3. :
 . ,

,
.

245 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

4. - :
 - ,

.
5. Google Play Protect:

 Google Play Protect -


Google Play .

.
6. ट:

 ,
. , ,

.
7. (HSM):

६.१२
,

. :
1. :

2. :
 .

.
3. ट :

 .
4. - (Secure Elements):

 (SIM, ) - .
.

246 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

5. (KeyStore):
 , KeyStore .

6. टक टक :

 ,
.

7. ट ट :
 ,

.
8. ट:

9. Android Enterprise:
 Android Enterprise

६.१३

,
(permissions) . .

permissions :
Permissions:

1. INTERNET:
 : .

 : , - .
2. ACCESS_NETWORK_STATE:

 : .
 : , .

3. READ_EXTERNAL_STORAGE:
 : .

 : SD , .
4. WRITE_EXTERNAL_STORAGE:

247 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

 : .
 : SD , .

5. CAMERA:

 : .
 : , .

6. READ_CONTACTS:
 : .

 : , .
7. WRITE_CONTACTS:

 : .
 : , .

8. ACCESS_FINE_LOCATION:
 : .

 : GPS , .
9. ACCESS_COARSE_LOCATION:

 : .
 : , .

10. CALL_PHONE:
 : .

 : .
11. SEND_SMS:

 : SMS .
 : .

12. RECEIVE_SMS:
 : SMS .

 : .

248 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

६.१४ घ क
permissions .

AndroidManifest.xml . ,

.
AndroidManifest.xml :

1. ट ट :
<uses-permission android:name="android.permission.INTERNET" />

1. क :
<uses-permission android:name="android.permission.READ_CONTACTS" />

2. क :
<uses-permission android:name="android.permission.CAMERA" />

3. :
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

4. SMS :
<uses-permission android:name="android.permission.SEND_SMS" />

5. permissions :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />


permissions , AndroidManifest.xml

.
:

import android.Manifest;
import android.content.pm.PackageManager;

import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity;

public class YourActivity extends AppCompatActivity {


// ,

private static final int CONTACTS_PERMISSION_CODE = 100;


@Override

249 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//
requestContactsPermission();

}
private void requestContactsPermission() {

//
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) !=

PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS},


CONTACTS_PERMISSION_CODE);

} else {
// , ( )

}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull

int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == CONTACTS_PERMISSION_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// ,
// ( )

} else {
// , , ( . )

} } }}

250 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

permissions
.

६.१५ ट (Permissions group in android)

, permissions permissions
. permissions permissions ,

permissions permissions .
, , CALL_PHONE ,

permission group , . READ_PHONE_STATE. permission


group .

permissions :

import android.Manifest;
import android.content.Context;

import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;

public class PermissionUtil {


private static final String[] PHONE_PERMISSIONS = {

Manifest.permission.CALL_PHONE,
Manifest.permission.READ_PHONE_STATE

};
public static boolean requestPhonePermissions(Context context)

{
for (String permission : PHONE_PERMISSIONS) {

if (ActivityCompat.checkSelfPermission(context, permission) !=
PackageManager.PERMISSION_GRANTED)

{
ActivityCompat.requestPermissions((YourActivity) context, PHONE_PERMISSIONS,

PHONE_PERMISSIONS_REQUEST_CODE);
return false;

251 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

}
}

return true;

}
}

PermissionUtil , permissions
permissions .

६.१६ क (Signing android application steps)

.
, APK KeyStore .

KeyStore .
, Android Studio .

Android Studio .

१. KeyStore क :
Android Studio .

"File" > "New" > "KeyStore" .


KeyStore , , , .

KeyStore KeyStore .
२. KeyStore क Android Studio :

Android Studio .
"File" > "Project Structure" > "Signing" .

"Config signing for the first time" .


KeyStore "OK" .

३. क क :
Android Studio .

"Build" > "Build Bundles(s) / APK(s)" > "Build APK(s)" .


APK , "Build" .

252 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

!
KeyStore .

६.१७ क (Steps to deploy android application)

.
, .

1. क :
 Google Play Console .

2. क :
 .

 Google Play .
3. क,क क :

 .
4. क :

 .
5. क क :

 .
 "Create Application" .

 .
6. क :

 , , .
 .

 .
7. APK क :

 Play "Release" .
 "Create Release" .

 APK .
8. टक :

 , , , .
 , .

253 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

६.१८ क (Developer Console)

Google Play Store .


, , , .

,
. Google

.
, , Google Play

. , ,
.

६.१९ क
Google Play Store

. :
१. क :

 क क : Google Play Store


.

 क टक :
.

२. क ट:
 क ट: , , .

 क : , .
३. :

 :
.

 : .
४. :

254 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

 क :
.

 : .

५. :
 क : , .

 क ट : .
६. :

 :
.

६.२० क क (Becoming a Publisher in android)

Google Play Store


" " (Publisher) . Google Play Console

. .
Google Play Store :

१. Google Play Console क :


 Google Play Console .

 Google Google .
२. क क :

 Android Studio IDE .


 Google

Play Console .
३. Google Play Console क :

 Google Play Console Google Play Console .


४. क क :

 Google Play Console "Create Application"


.

255 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI
Mobile Application Development (22617) (२२६१७)

५. क ट क :
 , , .

६. क :

 .
७. क क क :

 , "Submit for Review"


.

, Google Play Store


, .

सांदभशसूची(Bibliography)

१ https://www.geeksforgeeks.org/google-maps-in-android/
२ https://developer.android.com/studio/publish

३ https://developer.android.com/distribute/console
४ https://www.tutorialspoint.com/android/android_sending_sms.htm

५ https://developer.android.com/reference/android/widget/ZoomControls
६ https://www.tutorialspoint.com/android/android_location_based_services.htm

256 | Page
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ,MUMBAI

You might also like