SMS READER IN ANDROID:
Now a days many application providing functionality for SMS. In android programming we can implement this functionality with the below permission permissions
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
Below example code can be copied from here in desired application and It can read all inbox as well as it updates SMS when new SMS comes on user device.
We can develop whole messaging apps if we want make that functionality to part of our application like few apps providing that functionality to make their apps as a default messenger app.
Here is SMS reader example
Android manifest permission:
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<activity
android:name=".SmsActivity"
android:label="@string/app_name" >
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
android:name=".SmsActivity"
android:label="@string/app_name" >
<!-- <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>-->
</activity>
<receiver android:name=".SmsBroadcastReceiver" android:exported="true" >
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
XML implementation (activity_sms.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/MainLayout"
android:weightSum="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="SMS Inbox"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".15">
<ListView android:id="@+id/SMSList"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".85"
android:gravity="center_horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Report"
android:textColor="@color/white"
android:background="@color/darkVoilet"
android:id="@+id/btn_report"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/MainLayout"
android:weightSum="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="SMS Inbox"
android:id="@+id/textView"
android:layout_gravity="center_horizontal"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".15">
<ListView android:id="@+id/SMSList"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".85"
android:gravity="center_horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Report"
android:textColor="@color/white"
android:background="@color/darkVoilet"
android:id="@+id/btn_report"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
values / Colors.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="lightVoilet">#ccccff</color>
<color name="darkVoilet">#944dff</color>
<color name="white">#ffffff</color>
</resources>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="lightVoilet">#ccccff</color>
<color name="darkVoilet">#944dff</color>
<color name="white">#ffffff</color>
</resources>
Activity Class - SmsActivity.java :
package com.example.com.testapp;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class SmsActivity extends AppCompatActivity implements OnItemClickListener,View.OnClickListener {
private static SmsActivity inst;
ArrayList<String> smsMessagesList = new ArrayList<String>();
ListView smsListView;
ArrayAdapter arrayAdapter;
Button btn_report;
public static SmsActivity instance() {
return inst;
}
@Override
public void onStart() {
super.onStart();
inst = this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
btn_report=(Button)findViewById(R.id.btn_report);
btn_report.setOnClickListener(this);
smsListView = (ListView) findViewById(R.id.SMSList);
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, smsMessagesList);
smsListView.setAdapter(arrayAdapter);
smsListView.setOnItemClickListener(this);
refreshSmsInbox();
}
/*
Coloum details for SMS reader
olumn ID – Column Name
0 : _id
1 : thread_id
2 : address
3 : person
4 : date
5 : protocol
6 : read
7 : status
8 : type
9 : reply_path_present
10 : subject
11 : body
12 : service_center
13 : locked*/
public void refreshSmsInbox() {
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"), null, null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayAdapter.clear();
do {
String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
"\n" + smsInboxCursor.getString(indexBody) + "\n";
arrayAdapter.add(str);
} while (smsInboxCursor.moveToNext());
}
public void updateList(final String smsMessage) {
arrayAdapter.insert(smsMessage, 0);
arrayAdapter.notifyDataSetChanged();
}
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
try {
String[] smsMessages = smsMessagesList.get(pos).split("\n");
String address = smsMessages[0];
String smsMessage = "";
for (int i = 1; i < smsMessages.length; ++i) {
smsMessage += smsMessages[i];
}
String smsMessageStr = address + "\n";
smsMessageStr += smsMessage;
Toast.makeText(this, smsMessageStr, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.btn_report:
}
}
}
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class SmsActivity extends AppCompatActivity implements OnItemClickListener,View.OnClickListener {
private static SmsActivity inst;
ArrayList<String> smsMessagesList = new ArrayList<String>();
ListView smsListView;
ArrayAdapter arrayAdapter;
Button btn_report;
public static SmsActivity instance() {
return inst;
}
@Override
public void onStart() {
super.onStart();
inst = this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
btn_report=(Button)findViewById(R.id.btn_report);
btn_report.setOnClickListener(this);
smsListView = (ListView) findViewById(R.id.SMSList);
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, smsMessagesList);
smsListView.setAdapter(arrayAdapter);
smsListView.setOnItemClickListener(this);
refreshSmsInbox();
}
/*
Coloum details for SMS reader
olumn ID – Column Name
0 : _id
1 : thread_id
2 : address
3 : person
4 : date
5 : protocol
6 : read
7 : status
8 : type
9 : reply_path_present
10 : subject
11 : body
12 : service_center
13 : locked*/
public void refreshSmsInbox() {
ContentResolver contentResolver = getContentResolver();
Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"), null, null, null, null);
int indexBody = smsInboxCursor.getColumnIndex("body");
int indexAddress = smsInboxCursor.getColumnIndex("address");
if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
arrayAdapter.clear();
do {
String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
"\n" + smsInboxCursor.getString(indexBody) + "\n";
arrayAdapter.add(str);
} while (smsInboxCursor.moveToNext());
}
public void updateList(final String smsMessage) {
arrayAdapter.insert(smsMessage, 0);
arrayAdapter.notifyDataSetChanged();
}
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
try {
String[] smsMessages = smsMessagesList.get(pos).split("\n");
String address = smsMessages[0];
String smsMessage = "";
for (int i = 1; i < smsMessages.length; ++i) {
smsMessage += smsMessages[i];
}
String smsMessageStr = address + "\n";
smsMessageStr += smsMessage;
Toast.makeText(this, smsMessageStr, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.btn_report:
}
}
}
Broadcast receiver – SmsBroadcastReceiver :
package com.example.com.testapp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsBroadcastReceiver extends BroadcastReceiver {
public static final String SMS_BUNDLE = "pdus";
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String smsBody = smsMessage.getMessageBody().toString();
String address = smsMessage.getOriginatingAddress();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
}
Toast.makeText(context, smsMessageStr, Toast.LENGTH_SHORT).show();
//this will update the UI with message
SmsActivity inst = SmsActivity.instance();
inst.updateList(smsMessageStr);
}
}
}
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsBroadcastReceiver extends BroadcastReceiver {
public static final String SMS_BUNDLE = "pdus";
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String smsBody = smsMessage.getMessageBody().toString();
String address = smsMessage.getOriginatingAddress();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
}
Toast.makeText(context, smsMessageStr, Toast.LENGTH_SHORT).show();
//this will update the UI with message
SmsActivity inst = SmsActivity.instance();
inst.updateList(smsMessageStr);
}
}
}
I have write here only for reader code making few changes sms writing functionality can be implemented.
Antalya
ReplyDeleteKonya
Adana
Ankara
Van
SW6İ
6C136
ReplyDeleteŞırnak Parça Eşya Taşıma
Çanakkale Parça Eşya Taşıma
Bingöl Evden Eve Nakliyat
Denizli Evden Eve Nakliyat
Malatya Lojistik
FAB6C
ReplyDeleteBursa Şehirler Arası Nakliyat
Batıkent Boya Ustası
Gümüşhane Evden Eve Nakliyat
Altındağ Fayans Ustası
Niğde Lojistik
Düzce Evden Eve Nakliyat
Referans Kimliği Nedir
Çerkezköy Halı Yıkama
Ankara Şehir İçi Nakliyat
84D74
ReplyDeleteBalıkesir Şehir İçi Nakliyat
Balıkesir Şehirler Arası Nakliyat
Bitmex Güvenilir mi
Malatya Evden Eve Nakliyat
Mersin Lojistik
Van Parça Eşya Taşıma
Çerkezköy Boya Ustası
Nevşehir Parça Eşya Taşıma
Hakkari Şehir İçi Nakliyat
7AE2B
ReplyDeleteKırıkkale Şehirler Arası Nakliyat
Çanakkale Şehirler Arası Nakliyat
Erzincan Parça Eşya Taşıma
Muğla Şehirler Arası Nakliyat
Denizli Şehir İçi Nakliyat
Zonguldak Evden Eve Nakliyat
Çerkezköy Çekici
Adana Şehir İçi Nakliyat
Burdur Şehir İçi Nakliyat
94383
ReplyDeletepharmacy steroids for sale
steroid cycles
primobolan
parabolan
buy masteron
order testosterone propionat
buy trenbolone enanthate
buy sarms
steroid cycles for sale
CBD70
ReplyDeleteuşak rastgele görüntülü sohbet ücretsiz
adıyaman canlı sohbet ücretsiz
canli sohbet
karabük yabancı görüntülü sohbet siteleri
kütahya bedava görüntülü sohbet sitesi
görüntülü sohbet sitesi
manisa bedava sohbet siteleri
çorum bedava sohbet uygulamaları
mobil sohbet chat
9A1B0
ReplyDeletecanli sohbet chat
yalova sohbet
en iyi ücretsiz sohbet siteleri
kütahya en iyi ücretsiz görüntülü sohbet siteleri
bilecik telefonda canlı sohbet
Diyarbakır Bedava Sohbet
Antalya En İyi Ücretsiz Sohbet Uygulamaları
ankara rastgele sohbet siteleri
canlı sohbet siteleri ücretsiz
AFC7F
ReplyDeleteTumblr Takipçi Hilesi
Nexa Coin Hangi Borsada
Tiktok İzlenme Satın Al
Binance Borsası Güvenilir mi
Binance Kimin
Soundcloud Beğeni Satın Al
Coin Nasıl Kazılır
Parasız Görüntülü Sohbet
Paribu Borsası Güvenilir mi
CD65E
ReplyDeleteBitcoin Nasıl Kazanılır
Gate io Borsası Güvenilir mi
Threads İzlenme Hilesi
Binance Hesap Açma
Shinja Coin Hangi Borsada
Binance Referans Kodu
Parasız Görüntülü Sohbet
Youtube Abone Hilesi
Bitcoin Nasıl Üretilir
51732
ReplyDeleteAdalar
Erbaa
Söke
Gülşehir
Odunpazarı
Altındağ
Gaziantep
İvrindi
Hınıs
D5B319C201
ReplyDeletetiktok en ucuz takipçi