0% found this document useful (0 votes)
31 views13 pages

Unit-6 Security and Application Deployment

This document outlines the key aspects of mobile application development focusing on security and application deployment, specifically for Android apps. It covers topics such as SMS telephony, location-based services, the Android security model, and the steps required to publish an app on the Google Play Store. The content includes practical examples and code snippets for implementing features like SMS sending, map integration, and permission management.

Uploaded by

samarthkul407
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views13 pages

Unit-6 Security and Application Deployment

This document outlines the key aspects of mobile application development focusing on security and application deployment, specifically for Android apps. It covers topics such as SMS telephony, location-based services, the Android security model, and the steps required to publish an app on the Google Play Store. The content includes practical examples and code snippets for implementing features like SMS sending, map integration, and permission management.

Uploaded by

samarthkul407
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Mobile Application Development Unit-VI Security and Application Deployment

Unit-VI Security and Application Deployment

Course Outcome:

Publish Android applications.

Unit Outcomes:

6a. Explain the given location based service.


6b. Write the steps to customize the given permissions for users.
6c. Explain features of the given android security service.
6d. Write the steps to publish the given android App.
------------------------------------------------------------------------------------------------------------

Contents:

6.1 SMS Telephony


6.2 Location Based Services: Creating the project, Getting the maps API key, Displaying the map,
Displaying the zoom control, Navigating to a specific location, Adding markers, Getting location,
Geocoding and reverse Geocoding, Getting Location data, Monitoring Location.
6.3 Android Security Model, Declaring and Using Permissions, Using Custom Permission.
6.4 Application Deployment: Creating Small Application, Signing of application, Deploying app
on Google Play Store, Become a Publisher, Developer Console

6.1 SMS Telephony:

● Provides functionality to send and receive SMS (Short Message Service) messages.
● Allows applications to interact with the device's SMS capabilities.

Basic Requirements:

● SmsManager:
○ Handles sending SMS messages.
○ Provides methods like sendTextMessage() to send SMS.
● BroadcastReceiver:
○ Used to receive incoming SMS messages.
○ Listens for the android.provider.Telephony.SMS_RECEIVED broadcast.
● SmsMessage:
○ Represents an SMS message.
○ Provides methods to extract the sender's phone number, message body, etc.

Permissions:

● <uses-permission android:name="android.permission.SEND_SMS" />


● <uses-permission android:name="android.permission.RECEIVE_SMS" />
● <uses-permission android:name="android.permission.READ_SMS" />

Department of Computer Engineering 1 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

● Program in android to send & receive sms.


● activity_smsdemo.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SMSDemo">

<EditText
android:id="@+id/PhoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="phone number"/>

<EditText
android:id="@+id/Message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="message"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SendSMS”
android:onClick="sendSMS"/>
</LinearLayout>

SMSDemo.java
public class SMSDemo extends AppCompatActivity
{
EditText ph,msg;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_smsdemo);
ph=findViewById(R.id.PhoneNumber);
msg=findViewById(R.id.Message);
}
public void sendSMS(View view)
{
String phone=ph.getText().toString();
String text=msg.getText().toString();
SmsManager mgr=SmsManager.getDefault();
mgr.sendTextMessage(phone,null,text,null,null);
Toast.makeText(this,"sms sent!!",Toast.LENGTH_LONG).show();
}

}
Department of Computer Engineering 2 Mrs. Kulkarni D.P.
Mobile Application Development Unit-VI Security and Application Deployment

SMSReceiver.java(BroadcastReceiver)
public class SMSReceiver extends BroadcastReceiver
{

public void onReceive(Context context, Intent intent)


{
if (Objects.equals(intent.getAction(), "android.provider.Telephony.SMS_RECEIVED"))
{

Object[] pdus = (Object[]) intent.getExtras().get("pdus");


StringBuilder message = new StringBuilder();
for (Object pdu : pdus) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdu);
message.append(smsMessage.getMessageBody());
}

// Display the received message


Toast.makeText(context, "Received SMS: " + message.toString(), Toast.LENGTH_LONG).show();
}
throw new UnsupportedOperationException("Not yet implemented");
}
}
AndroidMenifest.xml(Register Receiver & permission)
<manifest….>

<uses-permission android:name="android.permission.SEND_SMS" />


<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application….>
<receiver
android:name=".SMSReceiver"
android:enabled="true"
android:exported="true”>
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application….>
</manifest….>

Department of Computer Engineering 3 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

6.2 Location Based Service :


 Location-based services (LBS) are applications or services that use geographical location data
(like GPS or network-based location) to provide relevant information or perform actions based
on where the user is located.

1. Creating the Project

 To use Google Maps in your application, you first need to create a new project in Google
Cloud Console.

 Go to the Google Cloud Console, create a new project, and enable the Google Maps SDK for
Android.

 Once enabled, you can generate an API key that will allow your app to access Google Maps
services.

2. Getting the Maps API Key

 Go to Google Cloud Console → APIs & Services → Credentials.

 Create new credentials for your app by selecting Create Credentials → API Key.

 Restrict the API Key to your app’s package name to prevent unauthorized access.

 Copy this key and use it in your app to authenticate your API requests.

3. Displaying the Map

 In your Android app, add a MapFragment or SupportMapFragment to your layout XML.

 In your activity, obtain a GoogleMap object using getMapAsync().

 Program to display a simple map:

public class CurrentLocation extends AppCompatActivity implements OnMapReadyCallback


{
private GoogleMap mMap;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_current_location);
SupportMapFragment smp=(SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
smp.getMapAsync(this);
}

Department of Computer Engineering 4 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

public void onMapReady(GoogleMap gmap)


{
mMap=gmap;

LatLng sydney=new LatLng(-34,151);


mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

}
}
Output :

4. Displaying the Zoom Control

● By default, zoom controls are enabled in Google Maps. If you want to enable them explicitly,
as
mMap.getUiSettings().setZoomControlsEnabled(true);

This will allow the user to zoom in and out of the map using on-screen buttons.

Department of Computer Engineering 5 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

5. Navigating to a Specific Location

● You can navigate to a specific location on the map by using CameraUpdateFactory to move
the camera to the desired coordinates:

LatLng location = new LatLng(40.7128, -74.0060); // New York City


mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 15));

This will move the camera to New York City with a zoom level of 15.

6. Adding Markers

● To add a marker on the map, use the addMarker() method:

LatLng location = new LatLng(40.7128, -74.0060); // New York City

mMap.addMarker(new MarkerOptions().position(location).title("Marker in NYC"));

This will place a marker at the specified latitude and longitude with a title.

7. Getting Location

Program to find Current location of user.


 You can use FusedLocationProviderClient to get the user’s current location (latitude and
longitude):

 Permissions to set in AndroidMenifest.xml

o <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
o <uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>

 activity_current_location.xml
<?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:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CurrentLocation">

Department of Computer Engineering 6 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

</LinearLayout>
 CurrentLocation.java
public class CurrentLocation extends AppCompatActivity implements OnMapReadyCallback
{
private GoogleMap mMap;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_current_location);
SupportMapFragment smp = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
smp.getMapAsync(this);
}

public void onMapReady(GoogleMap gmap)


{
mMap = gmap;
FusedLocationProviderClient objt =
LocationServices.getFusedLocationProviderClient(this);
obj.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>()
{
@Override
public void onSuccess(Location location)
{
if (location != null)
{
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng currentLocation = new LatLng(latitude, longitude);
mMap.addMarker(new MarkerOptions().position(currentLocation).title("You are here"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(currentLocation));
}
}
});
}
}

Department of Computer Engineering 7 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

 Output :

8. Geocoding and Reverse Geocoding

 Geocoding: Convert an address into geographic coordinates (latitude and longitude).

 Reverse Geocoding: Convert geographic coordinates back into a human-readable address.

 Example of Geocoding:

Geocoder geocoder = new Geocoder(this, Locale.getDefault());


List<Address> addresses = geocoder.getFromLocationName("New York", 1);
if (addresses != null && !addresses.isEmpty())
{
Address address = addresses.get(0);
LatLng newYork = new LatLng(address.getLatitude(), address.getLongitude());
mMap.addMarker(new MarkerOptions().position(newYork).title("New York"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(newYork, 10));
}

Department of Computer Engineering 8 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

 Example of Reverse Geocoding (getting address from latitude and longitude):

Geocoder geocoder = new Geocoder(this, Locale.getDefault());


List<Address> addresses = geocoder.getFromLocation(40.7128, -74.0060, 1);
if (addresses != null && !addresses.isEmpty())
{
Address address = addresses.get(0);
String addressText = address.getAddressLine(0); // Get the full address
Log.d("Geocoding", "Address: " + addressText);
}

9. Getting Location Data

 You can get details like the user’s location, speed, altitude, etc., from the Location object
provided by the FusedLocationProviderClient:

Location location = fusedLocationClient.getLastLocation();

if (location != null) {

double latitude = location.getLatitude();

double longitude = location.getLongitude();

float speed = location.getSpeed(); // Speed in meters/second

float altitude = location.getAltitude(); // Altitude in meters

10. Monitoring Location

● You can set up location updates to monitor the user’s movement in real-time using
FusedLocationProviderClient. This is useful for navigation apps or when you need to track
the user’s location continuously.

LocationRequest locationRequest = LocationRequest.create();


locationRequest.setInterval(10000); // 10 seconds
locationRequest.setFastestInterval(5000); // 5 seconds
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback,
Looper.getMainLooper());

Department of Computer Engineering 9 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

6.3. Android Security Model:


⎯ App Isolation (Sandbox):
o Each app runs in its own isolated space, like a separate room.
o This prevents apps from interfering with each other's data.

⎯ Unique User IDs:

o Every app gets a unique ID when installed.


o This reinforces the isolation, making it hard for bad apps to access good app's stuff.

⎯ App Signing:

o Apps are "signed" with a digital certificate, like a seal.

o This confirms who created the app and helps verify it's not tampered with.

⎯ Permissions at Installation:

o Apps must tell you what resources they need (like internet access) when you install
them.
o This is to ensure that you are aware of what an application is accessing.
⎯ Purpose of Permissions:
o Protects user privacy and system security.
o Apps must request permission for sensitive data & system features.
o Some permissions require user approval, while others are auto-granted.

⎯ Types of Permissions
1. Normal Permissions (Low-risk)
o Allow access to resources outside the app sandbox.
o Normal permissions allow an app to access non-sensitive system features that do not
affect user privacy or the functionality of other apps.
o Automatically granted at install time (No user approval needed).
o Example: Setting the time zone,Vibrate,Internet,Access Network state.
2. Signature Permissions (Restricted to Same Developer)
o Only granted when both apps are signed by the same developer certificate.
o Used mainly for internal communication between apps developed by the same
company or developer..
o Granted at install time without user interaction.
o Example : Read logs, Install Shortcuts etc.

Department of Computer Engineering 10 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

3. Dangerous Permission (High-risk)


o Allow access to sensitive user data (e.g., contacts, SMS, location).
o User must manually approve the request at runtime.
o Without approval, the app cannot access the data.
o Users can revoke these permissions anytime from device settings.
o Example: Reading contacts,Messages,Location etc

6.4. Publish your Android app on the Google Play Store:


Step 1: Create a Developer Account
 Sign up on Google Play Console and pay a one-time $25 fee.
 Fill in your details and wait for approval (can take up to 48 hours).
Step 2: Set Up a Merchant Account (If selling)
 If you want to sell apps or in-app purchases, create a Google Merchant Account to receive
payments.
Step 3: Create Your App
 In Google Play Console, click "Create App".
 Enter basic details like app name, category, and pricing (free or paid).
Step 4: Add Store Details
 Fill in app description, screenshots, app icon, and contact details.
 Add a privacy policy URL if your app collects user data.
Step 5: Upload Your App File (APK/AAB)
 Go to "Production Release" and upload your signed APK/AAB file.
 Add release notes (explain what’s new in this version).
Step 6: Set Content Rating
 Answer some questions about your app’s content (violence, age rating, etc.).
 Get an official Google Play content rating.
Step 7: Choose Pricing & Availability
 Decide if your app is free or paid (you can’t change free to paid later).
 Select the countries where your app should be available.
Step 8: Publish Your App
 Review everything and click "Start Rollout to Production".
 Google will review your app (can take a few hours to days).
 Once approved, your app will be live on the Play Store!

Department of Computer Engineering 11 Mrs. Kulkarni D.P.


Mobile Application Development Unit-VI Security and Application Deployment

Program to draw route between two locations.

activity_current_location.xml
<?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"
android:id="@+id/main"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CurrentLocation">

<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

</LinearLayout>

CurrentLocation.java
public class CurrentLocation extends AppCompatActivity implements OnMapReadyCallback
{
private GoogleMap mMap;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_current_location);

SupportMapFragment smp = (SupportMapFragment)

getSupportFragmentManager().findFragmentById(R.id.map);
smp.getMapAsync(this);
}

public void onMapReady(GoogleMap gmap)


{
mMap = gmap;
try
{
Uri uri = Uri.parse("https://www.google.co.in/mpas/dir/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.google.android.apps.maps");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
Department of Computer Engineering 12 Mrs. Kulkarni D.P.
Mobile Application Development Unit-VI Security and Application Deployment

Intent intent = new Intent(Intent.ACTION_VIEW, uri);


intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
AndroidMenifest.xml(Register Receiver & permission)
<manifest….>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application….>
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyAcZXRLRz73BY1SqJjrAsgYvNjZznhy4kE"/>
<activity
android:name=".CurrentLocation"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application….>
</manifest….>
Output :

Department of Computer Engineering 13 Mrs. Kulkarni D.P.

You might also like