Professional Documents
Culture Documents
Untitled Document
Untitled Document
LAB REPORT NO #5
Course Title: Mobile Application Development
Course Code: CSE 436 Section: 211D3
Student Details
Name ID
Md Sharafat Kabir 193902017
Lab Date :
Submission Date :
Course Teacher’s Name : Sudip Chandra Ghosal
[For Teachers use only: Don’t Write Anything inside this box]
1. Introduction
2. Objective
3. Procedure
1. Open `AndroidManifest.xml`.
4. Design
5. Implementation
The implementation details are divided into XML and Java code.
BatteryBroadcastReceiver.java
package com.example.batteryexample;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.widget.TextView;
@Override
MainActivity.java (Optional)
package com.example.batteryexample;
import androidx.appcompat.app.AppCompatActivity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
batteryLevelTextView = findViewById(R.id.batteryLevelTextView);
batteryLevelReceiver = new
BatteryLevelReceiver(batteryLevelTextView);
@Override
super.onStart();
registerReceiver(batteryLevelReceiver,
BatteryLevelReceiver.getBatteryLevelIntentFilter());
}
@Override
super.onStop();
unregisterReceiver(batteryLevelReceiver);
activity_main.xml (Optional)
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="@+id/batteryLevelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Battery Level: "
android:textSize="24sp"
android:layout_centerInParent="true" />
</RelativeLayout>
6. Output
When the application is run, and the battery percentage changes, the
`BatteryBroadcastReceiver` will be triggered. A Toast message will appear on
the screen displaying the updated battery percentage.
7. Conclusion