Recieving text messages within my app - android

The aim of my app is to grab in a text message and then display it on screen within a dialog box. It should also make it so that the message does not appear in the phones inbox. Currently i've coded what i think should work but when i send texts to the phone, they just appear in the inbox with no response from the app at all.
code below:
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
Intent act = new Intent(context, MainActivity.class);
act.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
act.putExtra("message",str);
context.startActivity(act);
//abortBroadcast();
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cam.sms"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECIEVE_SMS"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.cam.sms.MainActivity"
android:label="#string/app_name"
android:alwaysRetainTaskState="True"
android:launchMode="singleInstance">"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SettingsScreen"
android:alwaysRetainTaskState="True"
android:launchMode="singleInstance">
</activity>
<receiver android:name=".SMSReceiver" android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>

add
<intent-filter android:priority="100">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
to your manifest

In Manifest add one row inside of Intent filter of your app:
<intent-filter android:priority="100">
It means that your app will first decide what to do with your message.
Also, add in your code
this.abortBroadcast();
to stop further forwarding.
EDIT: Try also adding
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
Log.d("SMSReceiver",str);

BroadcastReceiver is a service. which means that it always look for the service and it is independent to the app activity.
so it won't show the application dependent Toast in service but you can call Activity using this service.
and for to receive first into your application give priority level 100 in your manifest file.
use
abortBroadcast();
method in your code

Related

Displaying SMS message once received in Android

I am trying to write a simple android program that listens to SMS messages, and once a message is received, it displays it in a toast.
Below is my Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zaidalmahmoud.expenseless">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Below is my SMS Listener:
public class SmsListener extends BroadcastReceiver {
private String msgBody;
private SharedPreferences preferences;
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Toast.makeText(context,"message received:",Toast.LENGTH_SHORT).show();
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msgs[i].getOriginatingAddress();
msgBody = msgs[i].getMessageBody();
}
Toast.makeText(context,"message is:"+msgBody,Toast.LENGTH_SHORT).show();
}catch(Exception e){
Log.d("Exception caught",e.getMessage());
}
}
}
}
}
and below is my activity:
public class MainActivity extends AppCompatActivity{
SmsListener smsListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
smsListener= new SmsListener();
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(smsListener, intentFilter);
}
#Override
public void onDestroy()
{
super.onDestroy();
// Unregister the SMS receiver
unregisterReceiver(smsListener);
}
}
Surprisingly, I am getting no output at all (no Toast message) once the SMS is received. Can someone help? Thank you.
You are not declaring your receiver in Manifest file, because of it will not listen anything.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zaidalmahmoud.expenseless">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SmsListener"/>
</application>

BroadcastReceiver listen to SMS not working

Hello I have implemented BroadcastReceiver exactly like in this post
Android – Listen For Incoming SMS Messages
but for some reason, when I try send message from one AVD to second AVD with app runing, it doesnt even print the "Message received" text to log.
Manifest:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<application>
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SmsListener">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
BroadcastReceiver
public class SmsListener extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("SmsListener", "Message received");
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Log.d("SmsListener", "Message received");
Bundle bundle = intent.getExtras(); //---get the SMS message passed in---
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
//---retrieve the SMS message received---
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for(int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msgs[i].getOriginatingAddress();
String msgBody = msgs[i].getMessageBody();
Log.d("SmsListener", "Message: "+msgBody);
}
} catch(Exception e) {
Log.d("Exception caught", e.getMessage());
}
}
}
}
}
can anyone explain where is the problem?
Starting from KitKat incoming SMS broadcast interception a bit changed. Look into this manifest, which covers both pre Kitkat and Kitkat versions:
<!-- SMS receiver -->
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BROADCAST_SMS" >
<intent-filter android:priority="2147483647" > <!-- 999 is highest system priority, so it's hack 2147483647 -->
<action android:name="android.provider.Telephony.SMS_RECEIVED" /> <!-- pre kitkat action -->
<action android:name="android.provider.Telephony.SMS_DELIVER" /> <!-- kitkat action -->
</intent-filter>
</receiver>
So depending on Android version you have to intercept in different way:
#Override
public void onReceive(Context context, Intent intent) {
//<action android:name="android.provider.Telephony.SMS_RECEIVED" /> <!-- pre kitkat action -->
//<action android:name="android.provider.Telephony.SMS_DELIVER" /> <!-- kitkat action -->
//if it is kitkat - ignore pre kitkat action
if(intent.getAction().equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED") && android.os.Build.VERSION.SDK_INT >= 19)
return;
//if it is not kitkat - ignore kitkat action
if(intent.getAction().equalsIgnoreCase("android.provider.Telephony.SMS_DELIVER") && android.os.Build.VERSION.SDK_INT < 19)
return;
//blah-blah
}

Android SMS dynamic Broadcast

I have a Program that is sending a SMS to a device witch answers with an SMS.
I want to receive the SMS in an give the message back to my program.
Cause I will only wait for a certain time I need a dynamic registration
Here my Code for the Breadcast Receiver
public class SMSReceiver extends BroadcastReceiver {
private MainActivity father = null;
private String call_number = null;
public void setFather (MainActivity father) {
this.father = father;
call_number = father.getCallNumber().trim();
while (call_number.startsWith("0")) {
call_number = call_number.substring(1);
}
}
public void onReceive(Context cxt, Intent intent)
{
//if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
{
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++)
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
String sender = smsMessage[0].getDisplayOriginatingAddress();
String mess = smsMessage[0].getDisplayMessageBody();
String toast = "Received SMS from: " + sender + "\nMessage: " + mess;
//if ((sender != null) && (sender.endsWith(call_number))) {
father.setSMSMessage((mess ==null ? "": mess)+ "\n from "+sender);
//}
Toast.makeText(cxt, toast, Toast.LENGTH_LONG).show();
}
}
}
Here my Code for the Registration
myreceiver=new SMSReceiver();
myreceiver.setFather(this);
IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(myreceiver, filter);
Here my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.standheizung"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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=".SMSChecker">
<intent-filter>
<action android:name="SMS_SENT" />
<action android:name="SMS_DELIVERED" />
</intent-filter>
</receiver>
</application>
</manifest>
My problem is that I get a SMS from the Device but my receiver does nothing.
Comment the Receiver for Sending the SMS works without any Problem
Has anybody an idea whats the problem ???

my sms receiver can't accept new sms

i want to receive sms on my application, but when i try to get new sms my application didn't get the new sms. I cannot find where I am doing wrong. I'm not sure if there's something wrong with the code, or debugging.
I'm trying to be notified if a new SMS arrives and save the sms on my database.
this is my receiver.
public void onReceive( Context c, Intent i) {
Bundle b = i.getExtras();
SmsMessage[] m = null;
String s = "";
TelephonyManager teleponyManager = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
int x;
if (b != null) { //IF valid SMS
Object[] p = (Object[]) b.get("p");
m = new SmsMessage[p.length];
for (x = 0; x < m.length; x++) { //FOR ambil konten SMS
m[x] = SmsMessage.createFromPdu((byte[])p[x]);
s += "SMS dari " +m[x].getOriginatingAddress().toString().trim();
s += " :";
s += m[x].getMessageBody().toString();
s += "\n";
}
Toast.makeText(c, s, Toast.LENGTH_LONG).show();
nomor = m[x].getOriginatingAddress().toString().trim();
pesan = m[x].getMessageBody().toString();
Cursor cursorKontak = data.pilihKontak(nomor);
if(cursorKontak.moveToFirst()) {
idkontak = cursorKontak.getString(cursorKontak.getColumnIndex("idkontak"));
}
if(idkontak == null) {
nama = nomor;
data.inputKontak(nama, nomor);
Cursor cursorKontak2 = data.pilihKontak(nomor);
if(cursorKontak2.moveToFirst()) {
idkontak = cursorKontak2.getString(cursorKontak2.getColumnIndex("idkontak"));
}
data.inputPesanMasuk(idkontak, pesan);
}else {
data.inputPesanMasuk(idkontak, pesan);
}
Intent broadcastIntent = new Intent();
broadcastIntent.setAction("SMS_RECEIVED_ACTION");
broadcastIntent.putExtra("sms", s);
c.sendBroadcast(broadcastIntent);
my android manifest
Update
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="1" android:versionName="1.0"
package="com.sms" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:label="#string/app_name"
android:name="EnkripsiSMS" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name=".SMSReceiver" >
<intent-filter >
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
<activity android:name=".KotakMasuk"/>
<activity android:name=".TulisPesan"/>
<activity android:name=".KotakKeluar"/>
<activity android:name=".HasilEnkripsi"/>
<activity android:name=".KirimPesan"/>
<activity android:name=".IsiPesanKeluar"/>
<activity android:name=".DekripsiPesanKeluar"/>
<activity android:name=".HasilDekripsiPesanKeluar"/>
<activity android:name=".TeruskanPesanKeluar"/>
<activity android:name=".KirimPesanKeluar"/>
<activity android:name=".IsiPesanMasuk"/>
<activity android:name=".DekripsiPesanMasuk"/>
<activity android:name=".TeruskanPesanMasuk"/>
<activity android:name=".HasilDekripsiPesanMasuk"/>
<activity android:name=".Balas"/>
<activity android:name=".HasilBalas"/>
<activity android:name=".KirimPesanMasuk"/>
</application>
</manifest>
can somebody help me?
i really need the solution.
thanks..
Instead of p use pdus
Object[] p = (Object[]) b.get("pdus");

How to block an incoming message in android?

I am trying to develop an app in android which blocks an incoming sms. I have set the priority but its not blocking the incoming sms. I have used this.abortBroadcast() also but no result.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;
#SuppressWarnings("deprecation")
public class SmsReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
this.abortBroadcast();
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
}
}
}
and the manifest file is like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="BVB.EDU"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SMS"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<receiver android:name=".SMSReceiver">
<intent-filter android:priority="99999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
</manifest>
Here's what I use for blocking incoming texts.
SmsReceiver.java
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 BroadCastReceiver extends BroadcastReceiver
{
/** Called when the activity is first created. */
private static final String ACTION = "android.provider.Telephony.SEND_SMS";
public static int MSG_TPE=0;
public void onReceive(Context context, Intent intent)
{
String MSG_TYPE=intent.getAction();
if(MSG_TYPE.equals("android.provider.Telephony.SMS_RECEIVED"))
{
// Toast toast = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);
// toast.show();
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++)
{
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
// show first message
Toast toast = Toast.makeText(context,"BLOCKED Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
abortBroadcast();
for(int i=0;i<8;i++)
{
System.out.println("Blocking SMS **********************");
}
}
else if(MSG_TYPE.equals("android.provider.Telephony.SEND_SMS"))
{
Toast toast = Toast.makeText(context,"SMS SENT: "+MSG_TYPE , Toast.LENGTH_LONG);
toast.show();
abortBroadcast();
for(int i=0;i<8;i++)
{
System.out.println("Blocking SMS **********************");
}
}
else
{
Toast toast = Toast.makeText(context,"SIN ELSE: "+MSG_TYPE , Toast.LENGTH_LONG);
toast.show();
abortBroadcast();
for(int i=0;i<8;i++)
{
System.out.println("Blocking SMS **********************");
}
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="APP.PACKAGE.NAMEHERE"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:resizeable="true"
android:anyDensity="true" />
<uses-feature android:name="android.hardware.telephony" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".APPACTIVITYHERE"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden" >
<service android:name=".MyService" android:enabled="true"/>
<receiver android:name="SmsReceiver">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_SENT"/>
</intent-filter>
</receiver>
<service android:name=".MyServiceSentReceived" android:enabled="true"/>
<receiver android:name="SmsReceiver">
<intent-filter android:priority="2147483645">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
The main thing to take away from the manifest is the service block, receiver block, and the permissions.
Add abortBroadcast(); in the if(bundle!=null){} block. that should stop it going to other apps. And I noticed that your Broadcast Receiver's name is SmsReceiver, but in Manifest, you gave it ".SMSReceiver" (case sensitive).
Problem is there in your manifest, you're closing <application> tag before the receiver tag and it's wrong. All components should be inside an application tag.
Your class name is SmsReceiver, and in manifest you declared as SMSReceiver,
so you won't get the broadcast at all for your receiver.
Use have to change your class name in manifest like below
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="99999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
And in your receiver, it's better to check the intent object for whether you got the message or not and then you can abort it.
But be careful it will abort all messages. If you want abort messages depending on some particular string you can do some manipulation on message what you got and then you can abort it.
If you want to abort all messages you can directly call abortBroadcast() before doing any manipulation on that message.
Bundle extras = intent.getExtras();
if ( extras != null )
{
// do you manipulation on String then if you can abort.
if(somecondition){
abortBroadcast();
}
}
Here is my manifest which working fine, once compare with your code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<application android:icon="#drawable/icon" android:enabled="true" android:label="#string/app_name">
<service android:name="com.mypackage.service.MyService" android:exported="true">
</service>
<receiver android:name="com.mypackage.receiver.MyReceiver">
<intent-filter android:priority="100"><action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter>
</receiver>
</application>
</manifest>
and the java code
public void onReceive( Context context, Intent intent )
{
if(intent != null){
String action = intent.getAction();
if(action.equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle extras = intent.getExtras();
if ( extras != null ){
//read sms
}
}
}
}
#sankar
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="BVB.EDU"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SMS"
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=".SmsReceiver">
<intent-filter android:priority="99999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
</manifest>
Because of the security policy in Android 4.4 and up
to block the incoming SMS-messages it is required to give to the
application the permissions of "Default SMS-application"

Categories

Resources