Mad ct2
Mad ct2
Geocoding:
If we know the latitude and longitude of a location, we can find out its address using a process
known as Geocoding. Google Maps in Android supports this via the Geocoder class.
we can find out the address of a location we have just touched using
the getFromLocation() method:
Reverse Geocoding:
If we know the address of a location but want to know its latitude and longitude, we can do so
via reverse-Geocoding. Again, we can use the Geocoder class for this purpose.
we can find the exact location of the Empire State Building by using
the getFromLocationName() method:
<Button
android:id="@+id/btnDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Dialer" />
<Button
android:id="@+id/btnGoogle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open Google" />
</LinearLayout>
package com.example.jod;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnDial = findViewById(R.id.btnDial);
btnGoogle = findViewById(R.id.btnGoogle);
btnDial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
}
});
btnGoogle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.com"));
startActivity(intent);
}
});
}
}
<uses-permission android:name="android.permission.SEND_SMS"/>
● Bluetooth
<uses-permission android:name="android.permission.BLUETOOTH" />
● Wifi
● Internet/Data
Internet Permission
AndroidManifest.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">
<EditText
android:id="@+id/etNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</LinearLayout>
Java
package com.example.jod;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
Button btnSend;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNumber = findViewById(R.id.etNumber);
etMessage = findViewById(R.id.etMessage);
btnSend = findViewById(R.id.btnSend);
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
try {
} catch (Exception e) {
}
});
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:id="@+id/text"
android:textSize="20dp"
android:gravity="center"/>
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="81dp"
android:src="@drawable/rose"/>
<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="TAKE PHOTO" />
</RelativeLayout>
Java File
package com.example.ifcdiv;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
b1=findViewById(R.id.photo);
imageView=findViewById(R.id.image);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_REQUEST)
{
Bitmap image= (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}
The system calls this method whenever a component, say an activity requests ‘start’ to a service, using
startService().
Once we use this method it’s our duty to stop the service using stopService() or stopSelf().
2. onBind()
This is invoked when a component wants to bind with the service by alling bindService(). In this, we must
provide an interface for clients to communicate with the service. For interprocess communication, we use
the IBinder object.
It is a must to implement this method. If in case binding is not required, we should return null as
implementation is mandatory.
3. onUnbind()
The system invokes this when all the clients disconnect from the interface published by the service.
4. onRebind()
The system calls this method when new clients connect to the service. The system calls it after the
onBind() method.
5. onCreate()
This is the first callback method that the system calls when a new component starts the service. We need
this method for a one-time set-up.
6. onDestroy()
This method is the final clean up call for the system. The system invokes it just before the service
destroys. It cleans up resources like threads, receivers, registered listeners, etc.
1. Install-time permissions
· Install-time permissions give your app limited access to restricted data, and they
allow your app to perform restricted actions that minimally affect the system or other
apps.
· When you declare install-time permissions in your app, the system automatically
grants your app the permissions when the user installs your app.
a) Normal permissions
· These permissions allow access to data and actions that extend beyond your app's
sandbox.
· However, the data and actions present very little risk to the user's privacy, and the
operation of other apps.
b) Signature permissions
· If the app declares a signature permission that another app has defined, and if the
two apps are signed by the same certificate, then the system grants the permission
to the first app at install time. Otherwise, that first app cannot be granted the
permission.
2. Runtime permissions
· Many runtime permissions access private user data, a special type of restricted data
that includes potentially sensitive information. Examples of private user data include
location and contact information.
3. Special permissions
· Additionally, the platform and OEMs usually define special permissions when they
want to protect access to particularly powerful actions, such as drawing over other
apps.
· Before you can publish any app on Google Play, you need to create a Developer Account. You
can easily sign up for one using your existing Google Account.
· You’ll need to pay a one-time registration fee of $25 using your international credit or debit card.
It can take up to 48 hours for your registration to be fully processed.
· If you want to publish a paid app or plan to sell in-app purchases, you need to create a payments
center profile, i.e. a merchant account.
· A merchant account will let you manage your app sales and monthly payouts, as well as analyze
your sales reports right in your Play Console.
Step 3: Create an App
· Now you have create an application by clicking on 'Create Application'. Here you have to select
your app’s default language from the drop-down menu and then type in a title for your app. The title
of your app will show on Google Play after you’ve published.
· Before you can publish your app, you need to prepare its store listing. These are all the details
that will show up to customers on your app’s listing on Google Play. You not necessarily complete it
at once , you can always save a draft and revisit it later when you’re ready to publish.
· The information required for your store listing is divided into several categories such as Product
Details containing title, short and full description of the app, Your app’s title and description should
be written with a great user experience in mind. Use the right keywords, but don’t overdo it. Make
sure your app doesn’t come across as spam-y or promotional, or it will risk getting suspended on the
Play Store.
· Graphic Assets where you can add screenshots, images, videos, promotional graphics, and icons
that showcase your app’s features and functionality.
· Languages & Translations, Categorization where in category can be selected to which your app
belong to. Contact Details , Privacy Policy for apps that request access to sensitive user data or
permissions, you need to enter a comprehensive privacy policy that effectively discloses how your
app collects, uses, and shares that data.
· Finally upload your app, by uploading APK file. Before you upload APK, you need to create an
app release. You need to select the type of release you want to upload your first app version to.
· You can choose between an internal test, a closed test, an open test, and a production release. The
first three releases allow you to test out your app among a select group of users before you make it go
live for everyone to access.
· This is a safer option because you can analyze the test results and optimize or fix your app
accordingly if you need to before rolling it out to all users.
· Once you create a production release, your uploaded app version will become accessible to
everyone in the countries you choose to distribute it in and click on ‘Create release.’
· If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps that are ‘Unrated’ may
get removed from Google Play.
· To rate your app, you need to fill out a content rating questionnaire An appropriate content rating
will also help you get to the right audience, which will eventually improve your engagement rates.
· You can always change your app from paid to free later, but you cannot change a free app to paid.
For that, you’ll need to create a new app and set its price.
· The final step involves reviewing and rolling out your release after making sure you’ve taken care
of everything else.
· Before you review and rollout your release, make sure the store listing, content rating, and pricing
and distribution sections of your app each have a green check mark next to them.
· Once you’re sure about the correctness of the details, select your app and navigate to ‘Release
management’ – ‘App releases.’
· You can always opt for reviews by clicking on ‘Review’ to be taken to the ‘Review and rollout
release’ screen. Here, you can see if there are any issues or warnings you might have missed out on.
Finally, select ‘Confirm rollout.’ This will also publish your app to all users in your target countries
on Google Play.
11) Give the steps to generate API key for Google Maps Activity
The API key is a unique identifier that authenticates requests associated with your project for usage and
billing purposes. You must have at least one API key associated with your project.
4. Add your project name and organization name in the fields present on the screen.
8. To create an API key for Maps click on Create credentials option and then select the
API key option
9. Click on the API key option to generate your API key. After clicking on this option
your API key will be generated
3. Now open the google_maps_api_xml file and copy the api key
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text"
android:hint="enter text"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="speak"/>
</LinearLayout>
package com.example.exp12;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import java.util.Locale;
setContentView(R.layout.activity_main);
btn=findViewById(R.id.btn);
ed=findViewById(R.id.text);
ts= new TextToSpeech(this, new
TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
ts.setLanguage(Locale.UK);
}
});
btn.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
String s=ed.getText().toString();
ts.speak(s,TextToSpeech.QUEUE_FLUSH,null);
}
});
}
}
<Button
android:id="@+id/btnEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Email" />
</LinearLayout>
Java
package com.example.jod;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
Button btnEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnEmail = findViewById(R.id.btnEmail);
btnEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]
{"[email protected]"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Test Subject");
intent.putExtra(Intent.EXTRA_TEXT, "This is the email body.");
startActivity(Intent.createChooser(intent, "Choose Email App"));
}
});
}
}
</LinearLayout>
⮚ Java code:-
package com.example.myapplication;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; // AndroidX import
import android.util.Log;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("lifecycle", "onCreate invoked");
}
@Override
protected void onStart() {
super.onStart();
Log.d("lifecycle", "onStart invoked");
}
@Override
protected void onResume() {
super.onResume();
Log.d("lifecycle", "onResume invoked");
}
@Override
protected void onPause() {
super.onPause();
Log.d("lifecycle", "onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
Log.d("lifecycle", "onStop invoked");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("lifecycle", "onRestart invoked");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("lifecycle", "onDestroy invoked");
}
}
<scale
android:fromXScale="0.5"
android:toXScale="1.0"
android:fromYScale="0.5"
android:toYScale="1.0"
android:duration="300" />
<scale
android:fromXScale="1.0"
android:toXScale="0.5"
android:fromYScale="1.0"
android:toYScale="0.5"
android:duration="300" />
</set>
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="300" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="300"
android:duration="300" />
</set>
Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@mipmap/ic_launcher" />
<Button
android:id="@+id/btnZoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom In/Out" />
<Button
android:id="@+id/btnFade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fade In/Out" />
</LinearLayout>
Java
package com.example.jod;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
ImageView imageView;
Button btnZoom, btnFade;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
btnZoom = findViewById(R.id.btnZoom);
btnFade = findViewById(R.id.btnFade);
btnZoom.setOnClickListener(v ->
imageView.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.zoom_in_out)));
btnFade.setOnClickListener(v ->
imageView.startAnimation(AnimationUtils.loadAnimation(this,
R.anim.fade_in_out)));
}
}
20) explain android security model and explain various types of permission (repeated)
21) write significance of developer console
22) wap to list all types sensors
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="@+id/tvSensors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sensors List:"
android:textSize="18sp" />
</LinearLayout>
Java Code :
package com.example.sensordemo;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
import java.util.List;
TextView tvSensors;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvSensors = findViewById(R.id.tvSensors);
SensorManager sensorManager = (SensorManager)
getSystemService(SENSOR_SERVICE);
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
tvSensors.setText(sensorData.toString());
}
}
Bluetooth :
Manifest :
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnTurnOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn ON Bluetooth"
android:onClick="turnOnBluetooth" />
<Button
android:id="@+id/btnTurnOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn OFF Bluetooth"
android:onClick="turnOffBluetooth" />
<Button
android:id="@+id/btnShowDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Paired Devices"
android:onClick="showPairedDevices" />
<ListView
android:id="@+id/listViewDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Java
package com.example.bluetoothapp;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import java.util.ArrayList;
import java.util.Set;
BluetoothAdapter bluetoothAdapter;
ListView listViewDevices;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listViewDevices = findViewById(R.id.listViewDevices);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
if (deviceList.isEmpty()) {
Toast.makeText(this, "No Paired Devices Found", Toast.LENGTH_SHORT).show();
} else {
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, deviceList);
listViewDevices.setAdapter(adapter);
}
}
}
Wifi :
Manifest :
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnWifiOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn ON WiFi"
android:onClick="turnOnWifi" />
<Button
android:id="@+id/btnWifiOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn OFF WiFi"
android:onClick="turnOffWifi" />
</LinearLayout>
Java:
package com.example.wifitest;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
WifiManager wifiManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wifiManager = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
}