Practical:13: 2ceit509 Mobile Application Development
Practical:13: 2ceit509 Mobile Application Development
Practical:13: 2ceit509 Mobile Application Development
Practical:13
Department of Computer
Engineering/Information Technology
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="4dp"
tools:context=".ui.MainActivity">
<EditText
android:id="@+id/editTextNum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter mobile number"
android:textColor="@color/black"
tools:ignore="TouchTargetSizeCheck" />
<EditText
android:id="@+id/editTextMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your message"
android:textColor="@color/black"
tools:ignore="TouchTargetSizeCheck" />
<Button
android:id="@+id/btnSendMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android: > android:text="Send Message" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation1"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="470dp"
android:background="@color/cardview_light_background"
app:menu="@menu/bottom_nav_menu" />
</LinearLayout>
package com.example.practical_13_19012021017.ui
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.telephony.SmsManager
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.example.practical_13_19012021017.R
import com.google.android.material.bottomnavigation.BottomNavigationView
bottomnav.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.list1 -> {
Intent(this, SMS_list::class.java).also {
startActivity(it)
}
return@setOnNavigationItemSelectedListener true
}
else -> return@setOnNavigationItemSelectedListener false
}
}
editTextNumber = findViewById(R.id.editTextNum)
editTextMessage = findViewById(R.id.editTextMsg)
button = findViewById(R.id.btnSendMsg)
}
fun sendMessage(view: View) {
val permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
myMessage()
Activity_sms_list.xml
<ListView
android:id="@+id/all_sms_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/cardview_light_background"
app:menu="@menu/bottom_nav_menu" />
</RelativeLayout>
SMS_list.kt
package com.example.practical_13_19012021017.ui
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.database.Cursor
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.example.practical_13_19012021017.R
import com.google.android.material.bottomnavigation.BottomNavigationView
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sms_list)
var msgData = ""
bottomnav.setOnNavigationItemSelectedListener {
when (it.itemId) {
R.id.sms1 -> {
Intent(this, MainActivity::class.java).also {
startActivity(it)
}
return@setOnNavigationItemSelectedListener true
}
else -> return@setOnNavigationItemSelectedListener false
}
}
val sms = ArrayList<Any>()
if(cursor != null) {
cursor.moveToFirst()
}
if (cursor != null) {
while (cursor.moveToNext()) {
val address: String = cursor.getString(1)
val body: String = cursor.getString(3)
sms.add("Address = " + address + "\nSMS = " + body+"\n")
}
}
Simple_list_item_1.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
Androidmanifest.xml
<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/Theme.practical_13_19012021017">
<activity
android:name=".ui.SMS_list"
android:exported="true" />
<activity
android:name=".ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
<item
android:id="@+id/sms1"
android:icon="@drawable/ic_baseline_message_24"
android:title="New" />
<item
android:id="@+id/list1"
android:icon="@drawable/ic_baseline_list_24"
android:title ="All" />
</menu>
String.xml
<resources>
<string name="app_name">practical_13_19012021017</string>
<string
name="title_activity_bottom_navigation_menu">Bottom_Navigation_Menu</string
>
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</string>
<string name="title_notifications">Notifications</string>
<string
name="title_activity_simple_list_item1">simple_list_item_1</string>
<!-- Strings used for fragments for navigation -->
<string name="first_fragment_label">First Fragment</string>
<string name="second_fragment_label">Second Fragment</string>
<string name="next">Next</string>
<string name="previous">Previous</string>