0% found this document useful (0 votes)
15 views135 pages

CHP 6 Mad

The document discusses making phone calls and sending SMS and emails from an Android application. It describes using intents and permissions to make phone calls, and using SMSManager API or intents to send SMS. Code samples are provided for making phone calls and sending SMS.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views135 pages

CHP 6 Mad

The document discusses making phone calls and sending SMS and emails from an Android application. It describes using intents and permissions to make phone calls, and using SMSManager API or intents to send SMS. Code samples are provided for making phone calls and sending SMS.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 135

Chapter 6

Security andApplication Deployment


SMS Telephony-Phone Call
Android provides Built-in applications for phone calls, in some
occasions we may need to make a phone call through our application.
This could easily be done by using implicit Intent with appropriate
actions. Also, we can use PhoneStateListener and TelephonyManager
classes, in order to monitor the changes in some telephony states on
the device.
Intent Object - Action to make Phone Call
You will use ACTION_CALL action to trigger built-in phone call
functionality available in Android device. Following is simple syntax to
create an intent with ACTION_CALL action
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
You can use ACTION_DIAL action instead of ACTION_CALL, in that case
you will have option to modify hardcoded phone number before making
a call instead of making a direct call.
Intent Object - Data/Type to make Phone Call
To make a phone call at a given number 91-000-000-0000, you need to
specify tel: as URI using setData() method as follows −
phoneIntent.setData(Uri.parse("tel:91-000-000-0000"));
Add Permission to AndroidManifest.xml File
You need to take permission from the user for a phone call and for that
CALL_PHONE permission is added to the manifest file. Here is the code
of the manifest file:
<!-- Permission for phone call -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<?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 phone number -->
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" />
<!-- Button to make call -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="115dp"
android:padding="5dp"
android:text="Make Call!!" />
</RelativeLayout>
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// define objects for edit text and button
EditText edittext;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
edittext = findViewById(R.id.editText);
button.setOnClickListener(arg -> {
// getting phone number from edit text and changing it to String
String phone_number = edittext.getText().toString();
// Getting instance of Intent with action as ACTION_CALL
Intent phone_intent = new Intent(Intent.ACTION_CALL);
// Set data of Intent through Uri by parsing phone number
phone_intent.setData(Uri.parse("tel:" + phone_number));
// start Intent
startActivity(phone_intent);
});
}
}
Android Send SMS with
Examples
In android, we can send SMS from our android application in two ways
either by using SMSManager API or Intents based on our requirements.
If we use SMSManager API, it will directly send SMS from our
application.
In case if we use Intent with proper action (ACTION_VIEW), it will
invoke a built-in SMS app to send SMS from our application.
1. Android Send SMS using SMSManager API
In android, to send SMS using SMSManager API we need to write the
code like as shown below.
SmsManager smgr = SmsManager.getDefault();
smgr.sendTextMessage(MobileNumber,null,Message,null,null);
SMSManager API required SEND_SMS permission in our android
manifest to send SMS. Following is the code snippet to set SEND_SMS
permissions in manifest file.
<uses-permission android:name="android.permission.SEND_SMS"/>
2. Android Send SMS using Intent
In android, Intent is a messaging object which is used to request an
action from another app component such as activities, services,
broadcast receivers, and content providers.
To send SMS using the Intent object, we need to write the code like as
shown below.
Intent sInt = new Intent(Intent.ACTION_VIEW);
sInt.putExtra("address", new String[]{txtMobile.getText().toString()});
sInt.putExtra("sms_body",txtMessage.getText().toString());
sInt.setType("vnd.android-dir/mms-sms");
Even for Intent, it required a SEND_SMS permission in our android
manifest to send SMS. Following is the code snippet to set SEND_SMS
permissions in manifest file.
<uses-permission android:name="android.permission.SEND_SMS"/>
Android Send SMS Example

Now we will see how to send SMS in android application using


SMSManager API with examples.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
android:text="Mobile No" />
<EditText
android:id="@+id/mblTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10"/>
<TextView
android:id="@+id/secTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:layout_marginLeft="100dp" />
<EditText
android:id="@+id/msgTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Send SMS" />
</LinearLayout>
MainActivity.java
package com.tutlane.sendsmsexample;
import android.content.Intent;
import android.net.Uri;
import android.provider.Telephony;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText txtMobile;
private EditText txtMessage;
private Button btnSms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main)
txtMobile = (EditText)findViewById(R.id.mblTxt);
txtMessage = (EditText)findViewById(R.id.msgTxt);
btnSms = (Button)findViewById(R.id.btnSend);
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
SmsManager smgr = SmsManager.getDefault();

smgr.sendTextMessage(txtMobile.getText().toString(),null,txtMessage.getText().toString(
),null,null);
Toast.makeText(MainActivity.this, "SMS Sent Successfully",
Toast.LENGTH_SHORT).show();
}
catch (Exception e){
Toast.makeText(MainActivity.this, "SMS Failed to Send,
Please try again", Toast.LENGTH_SHORT).show();
}
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutlane.sendsmsexample">
<uses-permission android:name="android.permission.SEND_SMS"/>
<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/AppTheme">
<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>
In case if we want to use Intents to send SMS to replace button click
code like as shown below.
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("smsto:"));
i.setType("vnd.android-dir/mms-sms");
i.putExtra("address", new String(txtMobile.getText().toString()));
i.putExtra("sms_body",txtMessage.getText().toString());
startActivity(Intent.createChooser(i, "Send sms via:"));
}
catch(Exception e){
Toast.makeText(MainActivity.this, "SMS Failed to Send, Please try
again", Toast.LENGTH_SHORT).show();
}
}
});
Android Send Email with
Examples
In android, we can easily send an email from our android application
using existing email clients such as GMAIL, Outlook, etc. instead of
building an email client from scratch.
Generally, the Intent object in android with proper action
(ACTION_SEND) and data will help us to launch the available email
clients to send an email in our application.
In android, Intent is a messaging object which is used to request an
action from another app component such as activities, services,
broadcast receivers, and content providers.
To know more about an Intent object in android check this Android
Intents with Examples.
To send an email using the Intent object in android application, we
need to write the code as shown below.
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
it.putExtra(Intent.EXTRA_SUBJECT, "Welcome to Tutlane");
it.putExtra(Intent.EXTRA_TEXT, "Hi Guest, Welcome to Tutlane Tutorial Site");
it.setType("message/rfc822");
If you observe above code we used multiple components to send email, those
are
it - Our local implicit intent
ACTION_SEND - It’s an activity action that specifies that we are sending some
data.
putExtra - we use this putExtra() method to add extra information to our Intent.
Here we can add the following things.
EXTRA_EMAIL - It’s an array of email addresses
EXTRA_SUBJECT - The subject of the email that we want to send
EXTRA_TEXT - The body of the email
The android Intent object is having different options such as EXTRA_CC,
EXTRA_BCC, EXTRA_HTML_TEXT, EXTRA_STREAM, etc. to add different options
for an email client.
setType - We use this property to set the MIME type of data that we want to
send. Here we used “message/rfc822” and other MIME types are “text/plain”
and “image/jpg”.
Now we will see how to send an email in android application using an Intent
object with examples.
activity_main.xml
Following is the example of sending an email with existing email clients
using Intent in the android application.
<?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:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="vertical" >
<EditText
android:id="@+id/txtTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To"/>
<EditText
android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"/>
<EditText
android:id="@+id/txtMsg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Message"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>
MainActivity.java
package com.tutlane.sendmailexample;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText eTo;
private EditText eSubject;
private EditText eMsg;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = (EditText)findViewById(R.id.txtTo);
eSubject = (EditText)findViewById(R.id.txtSub);
eMsg = (EditText)findViewById(R.id.txtMsg);
btn = (Button)findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{eTo.getText().toString()});

it.putExtra(Intent.EXTRA_SUBJECT,eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT,eMsg.getText());
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Mail App"));
}
});
}
}
If you observe above code we used multiple components to send email,
those are
it - Our local implicit intent
ACTION_SEND - It’s an activity action that specifies that we are sending
some data.
putExtra - we use this putExtra() method to add extra information to
our Intent. Here we can add the following things.
EXTRA_EMAIL - It’s an array of email addresses
EXTRA_SUBJECT - The subject of the email that we want to send
EXTRA_TEXT - The body of the email
setType - We use this property to set the MIME type of data that we
want to send. Here we used “message/rfc822” and other MIME types
are “text/plain” and “image/jpg”.
We need to add MIME type in our android manifest file for that open
android manifest file (AndroidManifest.xml) and write the code like as
shown below
Zoom Controls In Android
Studio
In Android, Zoom Controls class
display simple set of controls that
is used for zooming and provides
callback to register for events.
Zoom Controls has two buttons
ZoomIn and ZoomOut which are
used to control the zooming
functionality.
Zoom Controls code in XML:
<ZoomControls
android:id="@+id/simpleZoomControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000"
android:padding="20dp" />
Attributes Of Zoom Controls
in Android:
1. id: This attribute is used to uniquely identify a ZoomControls.
2. background: This attribute is used to set the background of a ZoomControls.
We can set a color or a drawable in the background of a ZoomControls.
3. padding: This attribute is used to set the padding from left, right, top or
bottom side of a ZoomControls .
paddingRight: set the padding from the right side of a ZoomControls.
paddingLeft: set the padding from the left side of a ZoomControls.
paddingTop: set the padding from the top side of a ZoomControls.
paddingBottom: set the padding from the bottom side of a ZoomControls.
Padding: set the padding from the all side’s of a ZoomControls.
Setting background in ZoomControls In Java class:
ZoomControls simpleZoomControls =
(ZoomControls)findViewById(R.id.simpleZoomControl); // initiate a ZoomControls
simpleZoomControls.setBackgroundColor(Color.BLACK); // set black color in the
background of ZoomControls
Important Methods Of Zoom
Controls:
Now let’s discuss some common methods which are used to configure
ZoomControls in our application.
1. hide(): This method is used to hide the ZoomControls from the
screen. In some cases we need to hide the ZoomControls from the
screen so that we use this function.
2. show(): This method is used to show the ZoomControls which we
hide from the screen by using hide method.
Below we show the use of hide and show methods of ZoomControls:
Step 1: In this example first in xml file we display ZoomControls with
two buttons hide and show which are used to hide and show the
ZoomControls.
xml code
<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">
<ZoomControls
android:id="@+id/simpleZoomControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<Button
android:id="@+id/show"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:background="#0f0"
android:text="Show"
android:textColor="#fff" />
<Button
android:id="@+id/hide"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/show"
android:layout_margin="20dp"
android:background="#f00"
android:text="Hide"
android:textColor="#fff" />
</RelativeLayout>
java file
*Add below setContentView() method in Oncreate()*/
final ZoomControls simpleZoomControls = (ZoomControls)
findViewById(R.id.simpleZoomControl); // initiate a ZoomControls
Button show = (Button) findViewById(R.id.show); // initiate show Button
Button hide = (Button) findViewById(R.id.hide); // initiate hide Button
// perform setOnClickListener on show button
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// show a ZoomControls
simpleZoomControls.show(); } });
// perform setOnClickListener on hide button
hide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// hide a ZoomControls
simpleZoomControls.hide();
}
});
3. setOnZoomInClickListener(OnClickListenerlistener):
This is a listener event automatically called when we click on the Zoom In button of ZoomControls. In
this listener we add the code to zoom in image.
Below we show the use of setOnZoomInClickListener in android.
final ZoomControls simpleZoomControls = (ZoomControls) findViewById(R.id.simpleZoomControl); //
initiate a ZoomControls
// perform setOnZoomInClickListener event on ZoomControls
simpleZoomControls.setOnZoomInClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// add zoom in code here
}
});
4. setOnZoomOutClickListener(OnClickListenerlistener):
This is a listener event automatically called when we click on the Zoom Out button
of ZoomControls. In this listener we add the code for zoom out a image.
Below we show the use of setOnZoomOutClickListener in android.
final ZoomControls simpleZoomControls = (ZoomControls) findViewById(R.id.simpleZoomControl
initiate a ZoomControls
// perform setOnZoomOutClickListener event on ZoomControls
simpleZoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// add zoom out code here} });
5. setIsZoomInEnabled(boolean isEnabled): This method is used to enable or
disable the zoom In button of ZoomControls. In this method we set a Boolean value
either true or false. By default it has true value but sometime after a limit of zoom
in we need to disable the zoom in functionality i.e. after that we didn’t need more
zoom in.
Below we set the false value for setIsZoomInEnabled that disable zoom in button of
ZoomControls.
ZoomControls simpleZoomControls = (ZoomControls)
findViewById(R.id.simpleZoomControl); // initiate a ZoomControls
simpleZoomControls.setIsZoomInEnabled(false); // disable zoom in button of
ZoomControls
6. setIsZoomOutEnabled(boolean isEnabled): This method is used to enable or
disable the zoom Out button of ZoomControls. In this method we set a Boolean
value means true or false. By default it has true value but sometime after a limit
of zoom out we need to disable the zoom out functionality means at that time
we didn’t need more zoom out.
Below we set the false value for setIsZoomOutEnabled that disable zoom out
button of ZoomControls.
ZoomControls simpleZoomControls = (ZoomControls)
findViewById(R.id.simpleZoomControl); // initiate a ZoomControls
simpleZoomControls.setIsZoomOutEnabled(false); // disable zoom out button of
ZoomControls
<?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"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp" />
</RelativeLayout>
MainActivity.java
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
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() {
@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();
}
}
}
);
Google Maps Tutorial With
Example In Android Studio
Android allows us to integrate Google Maps in our application. For this
Google provides us a library via Google Play Services for using maps. In
order to use the Google Maps API, you must register your application
on the Google Developer Console and enable the API.
Steps For Getting The Google Maps Api Key:
An API key is needed to access the Google Maps servers. This key is
free and you can use it with any of your applications. If you haven’t
created project, you can follow the below steps to get started:
Step 1: Open Google developer console and signin with your gmail
account: https://console.developers.google.com/project
Step 2: Now create new project. You can create new project by clicking
on the Create Project button and give name to your project.
Step 3: Now click on APIs &
Services and open Dashboard
from it.
Step 4: In this open Enable APIS
AND SERICES.
Step 5: Now open Google Map
Android API.
Step 6: Now enable the Google
Maps Android API.
Step 6: Now go to Credentials
Step 7: Here click on Create
credentials and choose API key
Step 8: Now API your API key will
be generated. Copy it and save it
somewhere as we will need it
when implementing Google Map
in our Android project.
Android - Google Maps
Android allows us to integrate google maps in our application. You can
show any location on the map , or can show different routes on the map
e.t.c. You can also customize the map according to your choices.
Google Map - Layout file
Now you have to add the map fragment into xml layout file. Its syntax
is given below −
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Google Map -
AndroidManifest file
The next thing you need to do is to add some permissions along with the Google Map
API key in the AndroidManifest.XML file. Its syntax is given below −
<!--Permissions-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.
READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--Google MAP API key-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDKymeBXNeiFWY5jRUejv6zItpmr2MVyQ0" />
Customizing Google Map
You can easily customize google map from its default view , and
change it according to your demand.
Adding Marker
You can place a maker with some text over it displaying your location
on the map. It can be done by via addMarker() method. Its syntax is
given below −
final LatLng TutorialsPoint = new LatLng(21 , 57);
Marker TP = googleMap.addMarker(new MarkerOptions()
.position(TutorialsPoint).title("TutorialsPoint"));
Changing Map Type

You can also change the type of the MAP. There are four different
types of map and each give a different view of the map. These types are
Normal,Hybrid,Satellite and terrain. You can use them as below
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
Enable/Disable zoom

You can also enable or disable the zoom gestures in the map by calling
the setZoomControlsEnabled(boolean) method. Its syntax is given
below −
googleMap.getUiSettings().setZoomGesturesEnabled(true);
activity_main.xml.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tutorialspoint7.myapplication.MapsActivity" />
MapActivity.java.
package com.example.tutorialspoint7.myapplication;
import android.support.v4.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;
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);
// Obtain the SupportMapFragment and get notified when the map is ready to be
used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager() .findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng TutorialsPoint = new LatLng(21, 57);
mMap.addMarker(new
MarkerOptions().position(TutorialsPoint).title("Tutorialspoint.com"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(TutorialsPoint));
}
}
AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint7.myapplication">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyAXhBdyKxUo_cb-
EkSgWJQTdqR0QjLcqes" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
o/p
How to Publish Your Android
App on Google Play Store?
Step 1: Make a Developer Account
A developer account is must be needed to upload an app on the
Google Play Store, and the process is very simple. Just go through
Google Play Store and do as instructed.
The account can be created in four simple steps:
1. Sign-In with Your Google Account
2. Accept Terms
3. Pay Registration Fee of $25.
4. Complete Your Account Details
Step 2:
After you completed step 1 you will be redirected to this page where
you have to click on the CREATE APPLICATION button.
Once you click on it a pop up will be shown like this where you have to
choose your Default language and Title of your app. Then click on the
CREATE button.
Step 3: Store listing
After you completed step 2 you will be redirected to this page where
you have to provide the Short description and Full description of your
App.
Then you scroll down the page and
now you have to add the Hi-res
icon of your app.
Then you have to provide the
Screenshots of your app.
next thing you have to provide is
the Feature Graphic of your app.
Note that this graphic is then used
everywhere your app is featured
on Google Play.
Then come to Categorization part
where you have to provide your
Application type and Category of
your app.
Then come to Contact details part
where you have to provide your
Website(if any), email, and Phone
of yours.
And finally when you click on SAVE
DRAFT button you can see that
Store listing tab is now become
turned to green and you are done
for Store listing.
Step 4: App release
After completing step 3 go to App
releases then scroll down to
Production track and click on
MANAGE button.
After redirecting to the next page
click on the CREATE RELEASE
button.
After that on the next page, you
have to upload your APK file in
Android App Bundles and APKs to
add section.
After that simply click on the SAVE
button.
Step 5: Content rating
Now after completing step 4 go to Content rating and click on
CONTINUE button.
After that fill your email address as
well as confirm the email address.
And then Select your app category.
After selecting your app category
make sure that you read all of
these and answer them correctly.
And after answering them
correctly don’t forget to click on
SAVE QUESTIONNAIRE button.
Once you saved all those things
then click on CALCULATE RATING
button.
When you redirected to another
page scroll down and click on
APPLY RATING button. And you are
done for Content rating section.
Don’t forget to notice that Content
rating section is now become
turned to green.
Step 6: Pricing & distribution
Then go to the Pricing &
distribution section. Then select
the country in which you want to
available your app.
Then go down and down and
check out the Content guidelines
and US export laws section by
marking them tick mark. And click
on the SAVE DRAFT button. Don’t
forget to notice that Pricing &
distribution section is now become
turned to green tick.
Step 7: App content
Then come to the App content
section. And in the Privacy policy
section click on the Start button.
And then provide a valid Privacy
policy URL. Note that google will
check this.
Then go back and continue further
steps by clicking start button in
Ads section
Then select does your app contain
ads or not? And click on SAVE
button.
Then again go back and continue
further steps by clicking start
button in Target audience and
content section.
In the next page select the Target
age group and scroll down and
click on the Next button.
Then check the Appeal to children
section. And click on the Next
button.
On the next page click on the Save
button and you are done for App
content section.
Step 8: App releases
Again go back to the App
releases section. And in the
Production track click on the EDIT
RELEASE button.
Then on the next page go down
and down and click on the REVIEW
button.
And finally, on the next page click
on the START ROLLOUT TO
PRODUCTION button to send your
app to review. And you are finally
done.
After usually 4 to 5 days they will
review your app and let you know
to either approve or reject your
app.

You might also like