0% found this document useful (0 votes)
39 views

Mad 22

The document contains details of a student named Ekambe Ganesh Dattatraya including their roll number 53. It describes two practical exercises involving Android activities and layouts. The first practical sets the background color of a constraint layout based on device orientation. The second retrieves a list of all sensors on the device and displays it in a list view.

Uploaded by

Ganesh Ekambe
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)
39 views

Mad 22

The document contains details of a student named Ekambe Ganesh Dattatraya including their roll number 53. It describes two practical exercises involving Android activities and layouts. The first practical sets the background color of a constraint layout based on device orientation. The second retrieves a list of all sensors on the device and displays it in a list view.

Uploaded by

Ganesh Ekambe
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/ 6

Name: Ekambe Ganesh Dattatraya

Roll No. :53

Practical No. : 22

Exercise

Ans 1)

activity_main.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=”http://schemas.android.com/apk/res/andr
oid” 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:id=”@+id/Layout”
tools:context=”.MainActivity”>

MainActivity.java
package com.example.exp22;
import androidx.appcompat.app.AppCompatActivity;
import
androidx.constraintlayout.widget.ConstraintLayout;
import android.content.res.Configuration;
import
android.graphics.Color;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{ConstraintLayout
constraintLayout; @Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
constraintLayout =
findViewById(R.id.Layout);
if(getResources().getConfiguration().orientatio
n ==
Configuration.ORIENTATION_PORTRAIT){
constraintLayout.setBackgroundColor( Color.parseColor(“#2cbdf2”));
}

if(getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE){
constraintLayout.setBackgroundColor(Color.parse Color”#f083f2”));
}}}
Ans 4)
actvity_main.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=”http://schemas.android.com/apk/res/andr
oid” 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”
tools:context=”.MainActivity”>
<ListView
android:id=”@+id/listView1”
android:layout_width=”match_pare
nt”
android:layout_height=”match_parent” />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java

package com.example.exp22_1;
import androidx.annotation.RequiresApi;
import
androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.hardware.Sensor;
import
android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import
android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.List;
public class MainActivity extends AppCompatActivity
{SensorManager
smm; List<Sensor>
sensor; ListView lv;
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
smm = (SensorManager)
getSystemService(Context.SENSOR_SERVICE); lv = (ListView)
findViewById (R.id.listView1);

sensor = smm.getSensorList(Sensor.TYPE_ALL);
lv.setAdapter(new
ArrayAdapter<Sensor>(this,android.R.layout.simple_list_item_1, sensor));
}

Output
Mobile Application Development(22617)

You might also like