0% found this document useful (0 votes)
3 views

Unit 4

This document provides an overview of JSON (JavaScript Object Notation), its features, and comparisons with XML, including data types and structures like objects and arrays. It also discusses the use of intents in Android development, detailing explicit and implicit intents for activity management and data exchange. Additionally, it includes code examples for creating and handling intents in an Android application.

Uploaded by

ridham26kamani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 4

This document provides an overview of JSON (JavaScript Object Notation), its features, and comparisons with XML, including data types and structures like objects and arrays. It also discusses the use of intents in Android development, detailing explicit and implicit intents for activity management and data exchange. Additionally, it includes code examples for creating and handling intents in an Android application.

Uploaded by

ridham26kamani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

UNIT- 4 JSON CONCEPT

… 04.1 Concept and Features of JSON, Similarities and difference among JSON and
XML
4.2 JSON objects (with string and Numbers))
4.3 JSON Arrays and their examples:
4.3.1 Array of string, Array of Numbers, Array of Booleans, Array of objects, Multi-
Dimensional Arrays
4.3.2 JSON comments
4.4 Building multi-screen apps:
4.4.1 Intents and their applications, types of intents,
4.4.2 Data exchange from one activity to another using intent
4.5 Working with implicit intents:
4.5.1 Opening web URLs through app
4.5.2 Sharing media from our app to other apps

What is json?
● JSON stands for JavaScript object notation. JSON has been derived from
javascript, where javascript is a programming language. It was originally created
to hold the structured data that could be used in javascript. JSON became so
popular that it is used for data for all kinds of applications. It is the most popular
way of sending the data for Web APIs.
● The JSON format was originally specified by Douglas Crockford, and is
described in RFC 4627(The application/json Media Type for JavaScript
Object Notation (JSON)).
● It use within various programming languages such as PHP, PERL, Python, Ruby,
Java, etc.
● It is commonly use for Api and Configuration.

Basic data types supported by json are:

○ Strings: Characters that are enclosed in single or double quotation marks.

○ Number: A number could be integer or decimal, positive or negative.

○ Booleans: The Boolean value could be either true or false without any quotation
marks.

○ Null: Here, null means nothing without any quotation marks.


UNIT- 4 JSON CONCEPT

JSON Example
{"employees":[

{ "firstName":"John", "lastName":"Doe" },

{ "firstName":"Anna", "lastName":"Smith" },

{ "firstName":"Peter", "lastName":"Jones" }

]}

JSON XML

JSON stands for javascript object XML stands for an extensible markup
notation. language.

The extension of the json file is .json. The extension of the xml file is .xml.

The internet media type is The internet media type is application/xml or


application/json. text/xml.

JSON is a lightweight, text-based, The type of format in XML is a markup


language-independent data interchange
language.
format
UNIT- 4 JSON CONCEPT

It is extended from javascript. It is extended from SGML.

It is open source and means that we It is also open source.


do not have to pay anything to use
JSON.

The data types supported by JSON XML data is in a string format.


are strings, numbers, Booleans, null,
array.

It does not have any capacity to XML is a markup language, so it has the
display the data. capacity to display the content.

JSON has no tags. XML data is represented in tags, i.e., start


tag and end tag.

JSON is quicker to read and write. XML file takes time to read and write
because the learning curve is higher.

JSON can use arrays to represent the XML does not contain the concept of arrays.
data.

It can be parsed by a standard XML data which is used to interchange the


javascript function. It has to be parsed data, must be parsed with respective to their
before use. programming language to use that.

File size is smaller as compared to File size is larger.


XML.

JSON is data-oriented. XML is document-oriented.


UNIT- 4 JSON CONCEPT

It is less secure than XML. It is more secure than JSON.

{"employees":[ <employees>
{ "firstName":"John", "lastName":"Doe" <employee>
}, <firstName>John</firstName>
{ "firstName":"Anna", <lastName>Doe</lastName>
"lastName":"Smith" }, </employee>
{ "firstName":"Peter", <employee>
"lastName":"Jones" } <firstName>Anna</firstName>
]} <lastName>Smith</lastName>
</employee>
<employee>
<firstName>Peter</firstName>
<lastName>Jones</lastName>
</employee></employees>

❖ JSON objects
JSON object literals are surrounded by curly braces {}.

JSON object literals contains key/value pairs.

Keys and values are separated by a colon.

Keys must be strings, and values must be a valid JSON data type:

● string
● number
● object
● array
● boolean
● null

Each key/value pair is separated by a comma.


UNIT- 4 JSON CONCEPT

JSON objects can be created with JavaScript.


var JSONObj = {};
Example:-
var JSONObj = { "bookname ":"VB BLACK BOOK", "price":500 };

➢Accessing Object Values


You can access object values by using dot (.) notation:

const myJSON = {"name":"John", "age":30, "car":null};


const myObj = JSON.parse(myJSON);
x = myObj.name;

{
JSON Object with Numbers "integer": 34,
SON supports numbers in double
"fraction": .2145,
precision floating-point format. The
number can be digits (0-9), fractions (.33, "exponent": 6.61789e+0 }
.532 etc) and exponents (e, e+, e-,E, E+,
E-).

{
JSON Object with Booleans "first": true,

JSON also supports boolean values true or "second": false


false.
}

employee:{
JSON Nested Object Example
"firstName": "Sonoo",

"lastName": "Jaiswal",

"age": 27,
UNIT- 4 JSON CONCEPT

"address" : {

"streetAddress": "Plot-6, Mohan


Nagar",

"city": "Ghaziabad",

"state": "UP",

"postalCode": 201007

★JSON Array
JSON array represents ordered list of values. JSON array can store multiple
values. It can store string, number, boolean or object in JSON array.

In JSON array, values must be separated by comma.

The [ (square bracket) represents JSON array.

["Sunday", "Monday", "Tuesday",


JSON Array of Strings "Wednesday", "Thursday", "Friday",
"Saturday"]

[12, 34, 56, 43, 95]

JSON Array of Numbers


UNIT- 4 JSON CONCEPT

[true, true, false, false, true]


JSON Array of Booleans

JSON Array of Objects


Let's see a simple JSON array example having 4 objects.

{"employees":[

{"name":"Ram", "email":"[email protected]", "age":23},

{"name":"Shyam", "email":"[email protected]", "age":28},

{"name":"John", "email":"[email protected]", "age":33},

{"name":"Bob", "email":"[email protected]", "age":41} ]}

➢Multidimensional Array
Creating a multi-dimensional array

We can store an array inside another JSON array. It is known as an array


of arrays or a multi-dimensional JSON array.

var siteInfo = {"name" : "blogger",


"users" : [ [ "admins", "1", "2" , "3"],
[ "editors", "4", "5" , "6"],] }
❖ JSON Comments

JSON doesn't support comments. It is not a standard.

Here, "comments" attribute can be treated as comment.

"employee": {

"name": "Bob",
UNIT- 4 JSON CONCEPT

"salary": 56000,

"comments": "He is a nice man"

● Comments in the form //, #, or /* */, which are used in


popular programming languages, are not allowed in JSON.

❖Intents and their applications, types of intents


➢ What is Intent?
Intent is to perform an action. It is mostly used to start activity,
send broadcast receiver, start services and send message
between two activities. There are two intents available in android
as Implicit Intents and Explicit Intents.

Android intents are mainly used to:

○ Start the service

○ Launch an activity

○ Display a web page

○ Display a list of contacts

○ Broadcast a message
UNIT- 4 JSON CONCEPT

○ Dial a phone call etc.

Methods and their Description

Methods Description

This is to launch a new activity or get an existing


Context.startActivity()
activity to be action.

This is to start a new service or deliver


Context.startService()
instructions for an existing service.

This is to deliver the message to broadcast


Context.sendBroadcast()
receivers.

➢ Explicit Intent−
○ It is going to connect the internal world of an application such as start activity or
send data between two activities. To start new activity we have to create Intent
object and pass source activity and destination activity as shown below:
➢Android calling one activity from another activity example
What is the difference between a bundle and an intent?

Bundles are used with intent and values are sent and retrieved in the same fashion, as

it is done in the case of Intent. It depends on the user what type of values the user

wants to pass, but bundles can hold all types of values (int, String, boolean, char) and

pass them to the new activity.

activity_main.xml

Add the following code in the activity_main.xml.


UNIT- 4 JSON CONCEPT

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

android:gravity="center"

android:padding="10dp"

tools:context=".MainActivity">

<EditText

android:id="@+id/nameEt"

android:hint="Enter Name"

android:inputType="text"

android:layout_width="match_parent"

android:layout_height="wrap_content" />
UNIT- 4 JSON CONCEPT

<EditText

android:id="@+id/emailEt"

android:hint="Enter Email"

android:inputType="textEmailAddress"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

<EditText

android:id="@+id/phoneEt"

android:hint="Enter Phone"

android:inputType="phone"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

<Button

android:id="@+id/saveBtn"

android:text="save"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />
UNIT- 4 JSON CONCEPT

</LinearLayout>

MainActivity.kt
Add the following code in the MainActivity.kt class. In this class,
we are creating an instance of Intent class and calling the
component activity class SecondActivity.kt. The putExtra(key,
value) method of Intent class send the data to the
SecondActivity.kt class. The startActivity() method starts the
Intent.

package com.example.explicit_intent

import androidx.appcompat.app.AppCompatActivity

import android.content.Intent

import android.os.Bundle

import android.widget.Button

import android.widget.EditText

class MainActivity : AppCompatActivity() {


UNIT- 4 JSON CONCEPT

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

val nameEt = findViewById<EditText>(R.id.nameEt)

val emailEt = findViewById<EditText>(R.id.emailEt)

val phoneEt = findViewById<EditText>(R.id.phoneEt)

val saveBtn = findViewById<Button>(R.id.saveBtn)

//handle button click

saveBtn.setOnClickListener {

//get text from edittexts

val name = nameEt.text.toString()

val email = emailEt.text.toString()

val phone = phoneEt.text.toString()

//intent to start activity


UNIT- 4 JSON CONCEPT

val intent = Intent(this@MainActivity,


MainActivity2::class.java)

intent.putExtra("Name", name)

intent.putExtra("Email", email)

intent.putExtra("Phone", phone)

startActivity(intent)

*Note - SecondActivity is the JAVA class name where the activity will
now be navigated.

★ What does class Java do in Kotlin?

It is Kotlin Reflection API, that can handle Kotlin features like properties, data
classes, etc. By using ::class. java , you get an instance of Class. It is Java
Reflection API, that interops with any Java reflection code, but can't work with
some Kotlin features.
UNIT- 4 JSON CONCEPT

Create another activity class named as SecondActivity.

second_activity.xml
In the second_activity.xml file add the following code.

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

android:gravity="center"

android:padding="10dp"

tools:context=".MainActivity2">

<TextView

android:id="@+id/resultTv"

android:textSize="30sp"
UNIT- 4 JSON CONCEPT

android:textStyle="bold"

android:textColor="#000"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

</LinearLayout>

SecondActivity.kt
Add the following code in the SecondActivity.kt class. In this
class, we are receiving the intent data using creating the instance
on Bundle class using intent.extras and displaying the data in
toast message. By clicking on the button, we are invoking Intent
to call MainActivity.kt class.

package com.example.explicit_intent

import android.content.Intent

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

import android.widget.Toast
UNIT- 4 JSON CONCEPT

import android.widget.Button

import android.widget.TextView

class MainActivity2 : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main2)

//get data from intent

val intent = intent

val name = intent.getStringExtra("Name")

val email = intent.getStringExtra("Email")

val phone = intent.getStringExtra("Phone")

//textview

val resultTv = findViewById<TextView>(R.id.resultTv)

//setText
UNIT- 4 JSON CONCEPT

resultTv.text = "Name: "+name+"\nEmail: "+email+"\nPhone:


"+phone

❖ Implicit Intents −
It going to connect with out side application such as call, mail, phone,see any
website ..etc. In implicit intent we have to pass an action using setAction() as
shown below example.

❖ Following is the simple code snippet of implicit intent in the android application.

intent = Intent(Intent.ACTION_VIEW)

intent.setData(Uri.parse("https://www.amrolicollege.org/"))

startActivity(intent)
UNIT- 4 JSON CONCEPT

❖ You can also write this code in given below:-

intent= Intent(Intent.ACTION_VIEW, Uri.parse("https://www.amrolicollege.org/"))

startActivity(intent)

★ Intent in android is an abstract public Class . ACTION_VIEW is the action on Intent.

public static final String ACTION_VIEW.

★ To open a URL/website you do the following: String url = "http://www.example.com";

Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)

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

<android.support.constraint.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="example.javatpoint.com.kotlinimplicitintent.MainActivity">

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
UNIT- 4 JSON CONCEPT

android:layout_marginBottom="8dp"

android:layout_marginTop="8dp"

android:text="Your First Activity"

android:textSize="18sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintHorizontal_bias="0.501"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.172" />

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"
UNIT- 4 JSON CONCEPT

android:text="click to invoke intent"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView"

app:layout_constraintVertical_bias="0.77" />

</android.support.constraint.ConstraintLayout>

MainActivity.kt

Add the following code in the MainActivity.kt class. In this class, we are invoking the
URL on clicking the button using Implicit Intent. To invoke this intent, we are passing the
action type and URL. The startActivity() method is used to start the Intent.

package example.javatpoint.com.kotlinimplicitintent

import android.content.Intent

import android.net.Uri

import android.support.v7.app.AppCompatActivity

import android.os.Bundle

import kotlinx.android.synthetic.main.activity_main.*
UNIT- 4 JSON CONCEPT

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

button.setOnClickListener(){

intent = Intent(Intent.ACTION_VIEW)

intent.setData(Uri.parse("https://www.amrolicollege.org/"))

startActivity(intent)

/* intent= Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.amrolicollege.org/"))

startActivity(intent)*/

Output:
UNIT- 4 JSON CONCEPT

★ Uri is the sequence of the characters used to identify resources uniquely over the
internet.
★ What is Setdata?
- setData() method sets the drag operation's drag data to the specified data and
type.

❖Sharing media from our app to other apps


➢Search for restaurants in San Francisco
➢ Intent will request turn-by-turn navigation to Akshardham ,
Gandhinagar
➢ How to Send an Email From an Android Application
UNIT- 4 JSON CONCEPT

Intent requests
In order to launch Google Maps with an intent you must first create an Intent object,
specifying its action, URI and package.

● Action: All Google Maps intents are called as a View action — ACTION_VIEW.
● URI: Google Maps intents use URL encoded that specify a desired action, along
with some data with which to perform the action.
● Package: Calling setPackage("com.google.android.apps.maps") will ensure that
the Google Maps app for Android handles the Intent. If the package isn't set, the
system will determine which apps can handle the Intent. If multiple apps are
available, the user may be asked which app they would like to use.

Example:- Search for restaurants in San Francisco

button.setOnClickListener(View.OnClickListener {

val gmmIntentUri = Uri.parse("geo:37.7749,-122.4194?q=restaurants")//


Create a Uri from an intent string. Use the result to create an Intent.

val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri) // Create an Intent


from gmmIntentUri. Set the action to ACTION_VIEW

mapIntent.setPackage("com.google.android.apps.maps") // Make the Intent


explicit by setting the Google Maps package

startActivity(mapIntent) // Attempt to start an activity that can handle the Intent

})
UNIT- 4 JSON CONCEPT

Examples:2

The below Intent will request turn-by-turn navigation to Akshardham ,


Gandhinagar

button.setOnClickListener(View.OnClickListener {

val gmmIntentUri =

Uri.parse("google.navigation:q=+BAPS+Akshardham+Temple
,+Gandhinagar+India")

val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)

mapIntent.setPackage("com.google.android.apps.maps")

startActivity(mapIntent)

})

Example:3

➢ How to Send an Email From an Android Application

➢ You can do so with the help of Intent with action as


ACTION_SEND with extra fields:
★ email id to which you want to send mail,

★ the subject of the email and

★ body of the email.


UNIT- 4 JSON CONCEPT

ACTIVITY1.XML

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

<!-- Relative Layout -->

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

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<!-- Edit text for email id -->

<EditText

android:id="@+id/editText1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"

android:layout_marginTop="18dp"

android:layout_marginRight="22dp" />

<!-- Edit text for email subject -->

<EditText

android:id="@+id/editText2"
UNIT- 4 JSON CONCEPT

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/editText1"

android:layout_alignLeft="@+id/editText1"

android:layout_marginTop="20dp" />

<!-- Edit text for email body -->

<EditText

android:id="@+id/editText3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/editText2"

android:layout_alignLeft="@+id/editText2"

android:layout_marginTop="30dp" />

<!-- text Views for label -->

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBaseline="@+id/editText1"

android:layout_alignBottom="@+id/editText1"

android:layout_alignParentLeft="true"

android:text="Send To:"

android:textColor="#0F9D58" />
UNIT- 4 JSON CONCEPT

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBaseline="@+id/editText2"

android:layout_alignBottom="@+id/editText2"

android:layout_alignParentLeft="true"

android:text="Email Subject:"

android:textColor="#0F9D58" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBaseline="@+id/editText3"

android:layout_alignBottom="@+id/editText3"

android:text="Email Body:"

android:textColor="#0F9D58" />

<!-- Button to send email -->

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
UNIT- 4 JSON CONCEPT

android:layout_below="@+id/editText3"

android:layout_alignLeft="@+id/editText3"

android:layout_marginLeft="76dp"

android:layout_marginTop="20dp"

android:text="Send email!!" />

</RelativeLayout>

package com.example.send_email

import android.content.Intent

import android.os.Bundle

import android.widget.Button

import android.widget.EditText

import androidx.activity.ComponentActivity

import androidx.activity.compose.setContent

import androidx.compose.foundation.layout.fillMaxSize

import androidx.compose.material3.MaterialTheme

import androidx.compose.material3.Surface

import androidx.compose.material3.Text

import androidx.compose.runtime.Composable

import androidx.compose.ui.Modifier

import androidx.compose.ui.tooling.preview.Preview

import com.example.send_email.ui.theme.Send_emailTheme

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


UNIT- 4 JSON CONCEPT

super.onCreate(savedInstanceState)

setContentView(R.layout.activity1)

// Getting instance of edittext and button

val sendto:EditText = findViewById(R.id.editText1)

val subject:EditText = findViewById(R.id.editText2)

val body:EditText = findViewById(R.id.editText3)

val button:Button = findViewById(R.id.button)

// attach setOnClickListener to button with Intent object define in it

button.setOnClickListener {

val emailsend = sendto.getText().toString()

val emailsubject = subject.getText().toString()

val emailbody = body.getText().toString()

// define Intent object with action attribute as ACTION_SEND

val intent = Intent(Intent.ACTION_SEND)

// add three fields to intent using putExtra function

intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(emailsend))

intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject)

intent.putExtra(Intent.EXTRA_TEXT, emailbody)

// set type of intent


UNIT- 4 JSON CONCEPT

intent.type = "message/rfc822"

// startActivity with intent with chooser as Email client using


createChooser function

startActivity(Intent.createChooser(intent, "Choose an Email client :"))

★WHAT IS RFC822 IN ABOVE:


The Internet RFC 822 specification defines an electronic message
format consisting of header fields and an optional message body. The
header fields contain information about the message, such as the
sender, the recipient, and the subject.

❖ App that open other app - Alarm,Gallary,Camera

MainActivity.kt
package com.example.implicit_intent

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.AlarmClock
import android.provider.MediaStore
import android.view.View
import android.widget.Button
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
UNIT- 4 JSON CONCEPT

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import
com.example.implicit_intent.ui.theme.Implicit_intentTheme

class MainActivity : ComponentActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val button:Button = findViewById(R.id.button)


button.setOnClickListener(){

//camera
val intent =
Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivity(intent)
})

❖ Send to Alarm App


button.setOnClickListener(View.OnClickListener {
//alarm
val intent = Intent(AlarmClock.ACTION_SHOW_ALARMS)
startActivity(intent)
})

❖ Send to Photo Gallary


//gallary
button.setOnClickListener(View.OnClickListener {

val intent = Intent(Intent.ACTION_VIEW)


intent.data =
Uri.parse("content://media/external/images/media/")
startActivity(intent)
UNIT- 4 JSON CONCEPT

})
}

You might also like