0% found this document useful (0 votes)
17 views34 pages

Mad ct2

The document outlines key concepts in Android development, including geocoding, intents, the Android security model, and permissions. It provides code examples for sending SMS, capturing images, and explains the activity and service lifecycle. Additionally, it details the steps required to upload an application to the Google Play Store.

Uploaded by

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

Mad ct2

The document outlines key concepts in Android development, including geocoding, intents, the Android security model, and permissions. It provides code examples for sending SMS, capturing images, and explains the activity and service lifecycle. Additionally, it details the steps required to upload an application to the Google Play Store.

Uploaded by

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

1) Define geocoding and reverse geocoding

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:

2) What is Intent? Give the types of Intent


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

<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;

public class MainActivity extends AppCompatActivity {


Button btnDial, btnGoogle;

@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);
}
});
}
}

3) Define Android Security Model


Android is a multi-process system, in which each application (and parts of the system) runs in its
own process.
• Most security between applications and the system is enforced at the process level through
standard Linux facilities, such as user and group IDs that are assigned to applications.
• Additional finer-grained security features are provided through a “permission” mechanism that
enforces restrictions on the specific operations that a particular process can perform, and per-
URI permissions for granting ad-hoc access to specific pieces of data.
• The Android security model is primarily based on a sandbox and permission mechanism. Each
application is running in a specific Dalvik virtual machine with a unique user ID assigned to it,
which means the application code runs in isolation from the code of all others applications. As a
consequence, one application has not granted access to other applications’ files.

4) Which permission are required for:


● SMS

For Sending SMS

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

● Bluetooth
<uses-permission android:name="android.permission.BLUETOOTH" />
● Wifi

● Internet/Data

Internet Permission

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

5) Write the code to send SMS

AndroidManifest.xml

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


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"

android:hint="Enter Phone Number" />

<EditText

android:id="@+id/etMessage"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Message" />

<Button

android:id="@+id/btnSend"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Send SMS" />

</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;

public class MainActivity extends AppCompatActivity {

EditText etNumber, etMessage;

Button btnSend;
@Override

protected void onCreate(Bundle savedInstanceState) {

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

public void onClick(View v) {

String number = etNumber.getText().toString();

String message = etMessage.getText().toString();

try {

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(number, null, message, null, null);

Toast.makeText(MainActivity.this, "SMS Sent", Toast.LENGTH_SHORT).show();

} catch (Exception e) {

Toast.makeText(MainActivity.this, "Failed to send SMS",


Toast.LENGTH_SHORT).show();

}
});

6) Write a program to capture image & display it in Image View


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="40dp"
android:orientation="horizontal"
tools:context=".MainActivity">

<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;

public class MainActivity extends AppCompatActivity {


Button b1;
ImageView imageView;
int CAMERA_REQUEST=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1=findViewById(R.id.photo);
imageView=findViewById(R.id.image);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);


startActivityForResult(i,CAMERA_REQUEST);
}
});

}
@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);
}
}
}

7) Explain Activity life cycle with diagram


onCreate()
This is the first callback and called when the activity is first created.
onStart()
This callback is called when the activity becomes visible to the user.
onResume()
This is called when the user starts interacting with the application.
onPause()
The paused activity does not receive user input and cannot execute any code and called when the
current activity is being paused and the previous activity is being resumed.
onStop()
This callback is called when the activity is no longer visible.
onDestroy()
This callback is called before the activity is destroyed by the system.
onRestart()
This callback is called when the activity restarts after stopping it.

8) Explain Service life cycle with diagram


1. onStartCommand()

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.

9) What is the need of permissions? Explain different types of permissions


• The purpose of a permission is to protect the privacy of an Android user. Android apps must
request permission to access sensitive user data (such as contacts and SMS), as well as
certain system features (such as camera and internet). Depending on the feature, the system
might grant the permission automatically or might prompt the user to approve the request.
• A central design point of the Android security architecture is that no app, by default, has
permission to perform any operations that would adversely impact other apps, the operating
system, or the user. This includes reading or writing the user's private data (such as contacts or
emails), reading or writing another app's files, performing network access, keeping the device
awake, and so on.

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.

Android includes several sub-types of install-time permissions,

Normal permissions and Signature permissions.

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

· Runtime permissions, also known as dangerous permissions, give your app


additional access to restricted data, and they allow your app to perform restricted
actions that more substantially affect the system and other apps.

· 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.

· The system assigns the "dangerous" protection level to runtime permissions.

3. Special permissions

· Special permissions correspond to particular app operations.

· Only the platform and OEMs can define 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.

10) Give the steps to upload application on Google Play Store

Step 1: Create a Developer Account

· 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.

Step 2: Plan to Sell? Link Your Merchant Account

· 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.

Step 4: Prepare Store Listing

· 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.

Step 5: Upload APK to an App Release

· 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.’

Step 6: Provide an Appropriate Content Rating

· 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.

Step 7: Set Up Pricing & Distribution


· Before you can fill out the details required in this step, you need to determine your app’s
monetization strategy. Once you know how your app is going to make money, you can go ahead and
set up your app as free or paid.

· 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.

Step 8: Rollout Release to Publish Your App

· 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

Getting the Maps API Key

Creating API keys

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.

1. Browse the site on your browser.

https://console. developers. google.com/project

2. Login with your google account.

3. Create a new project by clicking on Create Project option.

4. Add your project name and organization name in the fields present on the screen.

5. Now click on APIs and Services.

6. Enable APIs and services.

7. Select Google maps Android API

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

Displaying the Maps

1. Create new android project.

2. Select Google Maps Activity and then click finish.

3. Now open the google_maps_api_xml file and copy the api key

12) Explain multimedia framework


● The android multimedia system includes multimedia applications, multimedia framework, OpenCore
engine and hardware abstract for audio/video input/output devices.
● The goal of the android multimedia framework is to provide a consistent interface for Java services.
● The multimedia framework consists of several core dynamic libraries such as libmediajni, libmedia,
libmediaplayservice and so on
● Java classes call the Native C library Libmedia through Java JNI (Java Native Interface).
● Libmedia library communicates with Media Server guard process through Android’s Binder IPC (inter
process communication) mechanism.
● Media Server process creates the corresponding multimedia service according to the Java multimedia
applications. The whole communication between Libmedia and Media Server forms a Client/Server model.
● In Media Server guard process, it calls OpenCore multimedia engine to realize the specific multimedia
processing functions. And the OpenCore engine refers to the PVPlayer and PVAuthor.

13) WAP to convert text to speech

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid"
xmlns:app="http://schemas.android.com/apk/res-
auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<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;

public class MainActivity extends AppCompatActivity


{
EditText ed;
Button btn;
TextToSpeech ts;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);

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);
}
});

}
}

14) WAP to send a email


h<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"
android:gravity="center">

<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;

public class MainActivity extends 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"));
}
});
}
}

15) WAP to display activity life cycle methods as a message (repeated)

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="30dp"
android:gravity="center"
android:layout_marginTop="50dp"/>

</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");
}
}

16) write steps to deploy an app in play store (repeated)


17) what is an intent list its types (repeated)
18) wap to send sms and email (repeated)

19) Animation zoom in-out, fade in-out


RES /ANIM folder :

Zoom in/out .xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

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

Fade in/out .xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<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;

public class MainActivity extends 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;

public class MainActivity extends Activity {

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);

StringBuilder sensorData = new StringBuilder();


for (Sensor sensor : sensorList) {
sensorData.append(sensor.getName()).append("\n");
}

tvSensors.setText(sensorData.toString());
}
}

23) wifi bluetooth code

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;

public class MainActivity extends AppCompatActivity {

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();
}

public void turnOnBluetooth(View view) {


if (!bluetoothAdapter.isEnabled()) {
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(intent);
Toast.makeText(this, "Bluetooth Turned ON", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Bluetooth is already ON", Toast.LENGTH_SHORT).show();
}
}

public void turnOffBluetooth(View view) {


if (bluetoothAdapter.isEnabled()) {
bluetoothAdapter.disable();
Toast.makeText(this, "Bluetooth Turned OFF", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Bluetooth is already OFF", Toast.LENGTH_SHORT).show();
}
}

public void showPairedDevices(View view) {


Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
ArrayList<String> deviceList = new ArrayList<>();

for (BluetoothDevice device : pairedDevices) {


deviceList.add(device.getName() + " - " + device.getAddress());
}

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;

public class MainActivity extends AppCompatActivity {

WifiManager wifiManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wifiManager = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
}

public void turnOnWifi(View view) {


if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
Toast.makeText(this, "WiFi Turned ON", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "WiFi is already ON", Toast.LENGTH_SHORT).show();
}
}

public void turnOffWifi(View view) {


if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
Toast.makeText(this, "WiFi Turned OFF", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "WiFi is already OFF", Toast.LENGTH_SHORT).show();
}
}
}

You might also like