chapter-6
chapter-6
Package is android.provider.Telephony.Sms
Contains all text-based SMS messages.
Nested Class
Telephony.Sms.Draft
Contains all draft text-based SMS messages in the SMS app.
Telephony.Sms.Inbox
Contains all text-based SMS messages in the SMS app inbox.
Telephony.Sms.Intents
Contains constants for SMS related Intents that are broadcast.
Telephony.Sms.Outbox
Contains all pending outgoing text-based SMS messages.
Telephony.Sms.Sent
Contains all sent text-based SMS messages in the SMS app.
Telephony.Sms.Conversations
Contains a view of SMS conversations (also referred to as threads).
• send SMS from our android application in two
ways either by using SMSManager API or
Intents .
• 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
• <uses-
permission android:name="android.permission.SEND_SMS"/>
activity_main.xml
• <?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"
MainActivity.java
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;
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>
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
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");
• <uses-
permission android:name="android.permission.SEND_SMS"/>
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");
<receiver android:name="com.javarticles.android.SMSReceiver">
<intent-filter>
<action
android:name="android.provider.Telephony.SMS_RECEIVED" /
>
</intent-filter>
</receiver>
Broadcast Receiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.SmsMessage;
@Override
public void onReceive(Context context, Intent intent) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.settings:
startActivity(new Intent(this, SettingsActivity.class));
}
return super.onOptionsItemSelected(item);
}
}
Activity_main.xml
<LinearLayout 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:orientation="vertical"
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="com.javarticles.android.DatePickerExample" >
<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginTop="18dp"
android:text="@string/welcome"
android:textColor="@color/welcome_text_color"
android:textSize="20sp" />
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<?xml version="1.0" encoding="utf-8"?>
package="com.javarticles.android"
android:versionCode="1"
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="1.0" >
<uses-sdk
android:maxSdkVersion="22"
android:minSdkVersion="14"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher_sandbox"
android:label="@string/app_name" >
<activity android:name="com.javarticles.android.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.javarticles.android.SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Email
• To compose an email, use one of the below actions based on whether you'll
include attachments, and include email details such as the recipient and subject
using the extra keys listed below.
• ActionACTION_SENDTO (for no attachment) or
• ACTION_SEND (for one attachment) or
• ACTION_SEND_MULTIPLE (for multiple attachments)
• MIME Type
– "text/plain"“
– */*“
• Extras
– Intent.EXTRA_EMAIL A string array of all "To" recipient email addresses.
– Intent.EXTRA_CC A string array of all "CC" recipient email addresses.
– Intent.EXTRA_BCC A string array of all "BCC" recipient email addresses
– Intent.EXTRA_SUBJECT A string with the email subject.
– Intent.EXTRA_TEXT A string with the body of the email.
– Intent.EXTRA_STREAM A Uri pointing to the attachment. If using the
ACTION_SEND_MULTIPLE action, this should instead be an ArrayList containing
multiple Uri objects.
• public void composeEmail(String[] addresses, String
subject, Uri attachment) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_STREAM, attachment);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
• If you want to ensure that your intent is handled only by an email app
(and not other text messaging or social apps), then use the
ACTION_SENDTO action and include the "mailto:" data scheme.
• For example:
public void composeEmail(String[] addresses, String subject)
{
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle
this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null)
{
startActivity(intent);
}
}
• <activity ...>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<data android:type="*/*" />
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category
android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:androclass="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">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="22dp"
android:layout_marginTop="18dp"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp"
/>
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
<TextView
android:id="@+id/textView1"
android:textColor="#0F9D58"
android:text="Send To:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"/> <TextView
android:id="@+id/textView2"
android:textColor="#0F9D58"
android:text="Email Subject:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"/>
<TextView
android:id="@+id/textView3"
android:textColor="#0F9D58"
android:text="Email Body:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"/>
<Button
android:id="@+id/button"
android:text="Send email!!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.widget.EditText;
import android.view.View;
import android.view.View.OnClickListener;
import android.net.Uri;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onClick(View view)
{
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();
Generally, the Intent object in android with proper action (ACTION_CALL) and data will help
us to launch a built-in phone calls app to make a phone calls 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 make a phone call using Intent object in android application, we need to write the code
like as shown below.
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:androclass="http://schemas.android.com/apk/res/android"
package="com.example.phonecall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
• googleMap.setMapType(GoogleMap.MAP_TY
PE_NORMAL);
• googleMap.setMapType(GoogleMap.MAP_TY
PE_HYBRID);
• googleMap.setMapType(GoogleMap.MAP_TY
PE_SATELLITE);
• googleMap.setMapType(GoogleMap.MAP_TY
PE_TERRAIN);
Methods of Google map
Methods Description
addCircle(CircleOptions options) This method add circle to map.
addPolygon(PolygonOptions options) This method add polygon to map.
addTileOverlay(TileOverlayOptions This method add tile overlay to the map.
options)
animateCamera(CameraUpdate This method moves the map according to the
update) update with an animation.
clear() This method removes everything from the
map.
getMyLocation() This method returns the currently displayed
user location.
moveCamera(CameraUpdate update) This method reposition the camera according
to the instructions defined in the update.
setTrafficEnabled(boolean enabled) This method set the traffic layer on or off.
snapshot(GoogleMap.SnapshotReadyC This method takes a snapshot of the map.
allback callback)
stopAnimation() This method stops the camera animation if
there is any progress.
Example of Google Map
Copy the URL from google_map_api.xml file
to generate Google map key.
Paste the copied URL at the browser. It will
open the following page.
Click on Create API key to generate API key.
After clicking on Create API key, it will generate
our API key displaying the following screen.
Copy this generated API key in
our google_map_api.xml file
activity_maps.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.SupportMap
Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity" />
MapsActivity.java
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;
@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);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.com.mapexample">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
build.gradel
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-
maps:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner
:1.0.1'
androidTestImplementation 'com.android.support.test.espres
so:espresso-core:3.0.1'
}
Android Google Map Displaying Current Location
• Callback methods in Google Map
• OnMapRreadyCallback: This callback interface invokes when it instance
is set on MapFragment object. The onMapReady(GoogleMap) method of
OnMapReadyCallback interface is called when the map is ready to used.
In the onMapReady(GoogleMap) method we can add markers, listeners
and other attributes.
• LocationListener: This interface is used to receive notification when the
device location has changed. The abstract method of LocationListener
onLocationChanged(Location) is called when the location has changed.
• GoogleApiClient.ConnectionCallbacks: This interface provide callbacks
methods onConnected(Bundle) and onConnectionSuspended(int) which
are called when the device is to connected and disconnected.
• GoogleApiClient.OnConnectionFailedListener: This interface provide
callbacks method onConnectionFailed(ConnectionResult) which is called
when there was an error in connecting the device to the service.
• The setMyLocationEnabled() method of GoogleMap is used to enable
activity_maps.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.SupportMap
Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity" />
build.gradel
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.android.gms:play-services-location:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espre
sso-core:3.0.1'
}
MapsActivity.java
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.common.api.GoogleApiClient;
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.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.LocationServices;
import android.location.Location;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallb
ack,
LocationListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
@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) getSupportFrag
mentManager()
.findFragmentById(R.id.map);
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
@Override
public void onConnectionSuspended(int i) {
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
mCurrLocationMarker = mMap.addMarker(markerOptions);
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
<?xml version="1.0" encoding="utf-8"?>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.com.mapexample">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
LocationManager locationManager =
(LocationManager)getSystemService(Context.LOCA
TION_SERVICE);
Step 2
• identify the location provider you would like to use for retrieving location details.
The location providers actually provide the location data in Android. Android exposes
two main location providers:
– A. It is significantly slower than the network provider to get the initial connection setup with
the satellites. This initial connection, also called Time to First Fix (TTFF) can be extremely
slow but once the connection is established, location updates are quite fast
– B. GPS provider also drains out the battery very first. So, it is very important to judiciously
use this provider. Special care should be taken to ensure that this is turned off when you are
not using it.
– C. The third draw back comes from the fact that GPS uses radio signal which is obstructed by
solid objects. So, GPS provider will not work if you are inside a building or in a basement.
2. Network Provider:
This provider uses Wi-Fi hotspots and cell tower to approximate a location. The
provider retrieves an approximate location by querying the Google location server
using the IDs of the Wi-Fi hotspots and cell towers. Location accuracy is between 100
– 1000 m. The location accuracy is directly proportional to the number of Wi-Fi
You can check the availability of the providers
using the below piece of code:
isGpsEnabled = mLocManager.isProviderEnab
led(LocationManager.GPS_PROVIDER);
isNetworkEnabled =
mLocManager.isProviderEnabled(LocationMa
nager.NETWORK_PROVIDER);
Step 3
To register a location listener with the location manager.
The registration can be done by calling the
method requestLocationUpdates((String provider, long minTime, float
minDistance, LocationListener listener).
Following are the parameters passed to this method:
– provider:
the name of the provider with which to register. This can be either GPS or Network
provider.
– minTime:
minimum time interval between location updates, in milliseconds.
– minDistance:
minimum distance between location updates, in meters.
– listener:
a LocationListener whose onLocationChanged(Location) method will be called for each
location update.
• The Location Manager calls the onLocationChanged() of the listener when the
mobile has moved a distance greater than the minDistance or the time since last
location update is more than minTime.
Permissions required for Location Based
Services in Android
• <uses-
permissionandroid:name=”android.permission.ACCESS_COARSE_LOCATI
ON”/>
<uses-
permissionandroid:name=”android.permission.ACCESS_FINE_LOCATION”
/>
<uses-permissionandroid:name=”android.permission.INTERNET”/>
• Public Methods
– public abstract void activate (
LocationSource.OnLocationChangedListener listener)
listener that's called when a new location is available
Throws IllegalStateException,IllegalArgumentException
• public abstract void deactivate ()
– Deactivates this provider. The previously-
registered callback is not notified of any further
updates. Throws IllegalStateException
Android security model
• Normal permissions cover areas where your app needs to access data or
resources outside the app’s sandbox, but where there’s very little risk to
the user’s privacy or the operation of other apps. For example,
permission to set the time zone is a normal permission. If an app declares
in its manifest that it needs a normal permission, the system
automatically grants the app that permission at install time. The system
doesn’t prompt the user to grant normal permissions, and users cannot
revoke these permissions.
• Signature permissions: The system grants
these app permissions at install time, but only
when the app that attempts to use a
permission is signed by the same certificate as
the app that defines the permission.
• Dangerous permissions cover areas where the app wants data
or resources that involve the user’s private information, or
could potentially affect the user’s stored data or the operation
of other apps. For example, the ability to read the user’s
contacts is a dangerous permission. If an app declares that it
needs a dangerous permission, the user has to explicitly grant
the permission to the app. Until the user approves the
permission, your app cannot provide functionality that
depends on that permission. To use a dangerous permission,
your app must prompt the user to grant permission at
runtime. For more details about how the user is prompted,
see Request prompt for dangerous permission.
Android threat
• However, the Android operating system also revealed some of its faults for the user may be
attacked and stolen personal information.
Some security vulnerabilities on Android:
– Leaking Information to Logs: Android provides centralized logging via the Log API, which can
displayed with the “logcat” command. While logcat is a debugging tool, applications with the
READ_LOGS permission can read these log messages. The Android documentation for this
permission indicates that “the logs can contain slightly private information about what is
happening on the device, but should never contain the user’s private information.”
– SDcard Use: Any application that has access to read or write data on the SDcard can read or
write any other application’s data on the SDcard.
– Intent Injection Attacks: Intent messages are also used to start activity and service
components. An intent injection attack occurs if the in-tent address is derived from untrusted
input.
– Wifi Sniffing: This may disrupt the data being transmitted from A device like many web sites
and applications does not have security measures strict security. The application does not
Requesting permissions
Step 15: Now you will see create release now click on it.
• Step 16: After click on create release you will
see browse files click on it and upload your
signed APK.