Step 1
Create broadcast receiver class for receiving sms
package com.javaorigin.android.sample;
import android.content.*;
import android.os.Bundle;
import android.telephony.*;
import android.util.Log;
import android.widget.Toast;
public class SimpleSmsReciever extends BroadcastReceiver {
private static final String TAG = "Message recieved";
@Override
public void onReceive(Context context, Intent intent) {
Bundle pudsBundle = intent.getExtras();
Object[] pdus = (Object[]) pudsBundle.get("pdus");
SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);
Log.i(TAG, messages.getMessageBody());
Toast.makeText(context, "SMS Received : "+messages.getMessageBody(),
Toast.LENGTH_LONG).show();
}
}
Step 2 :
Configure the AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest android="http://schemas.android.com/apk/res/android"
package="com.javaorigin.android.sample" versioncode="1" versionname="1.0">
<application icon="@drawable/icon" label="@string/app_name">
<receiver name=".SimpleSmsReciever">
<intent-filter>
<action name="android.provider.Telephony.SMS_RECEIVED">
</action>
</intent-filter>
</receiver>
</application>
<uses-sdk minsdkversion="6">
<uses-permission name="android.permission.INTERNET">
Hi,
ReplyDeleteQuestion...
Let's say I have an activity wich should draw something depending on the received message....
vDraw is my view to draw in (ViewDraw.java)
SMSDraw is my main activity (SMSDraw.java)
the drawing part is working...
Now how can I get the information from the sms in my SMSdraw ????
wether we have to register the recever ? in above exaample
ReplyDeleteIs it worked on emulator> i m trying on emulator but not not getting toast nor printing log...
ReplyDeleteIt works but y to add internet permission???
ReplyDeleterequire "android.permission.RECEIVE_SMS" Permission in manifest file to work.
ReplyDeletei can't get the code running it always force closes when i run the application.what could be the reason.I've tried getting it to work but still unsuccessful
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteafter receives sms, protect on the native inbox(doesn't go on inbox) Pls help me... pls tell the Code... My project pls
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteif i want to read sent messages by me at that time broadcast receiver doesn't working...
ReplyDeletethanks. it helps a lot. should include
ReplyDeletethanks.
ReplyDeleteits easy and help a lot.
i also refer some tutorial at androprogrammer.com
Wow, you are a life saver man. Thanks for the awesome code :D Valentines Day 2014
ReplyDeleteGreat I have used this code on my Android Google Blog
ReplyDeletewhere is layout.xml file????????
ReplyDeleteWell written and interesting thoughts. Its amazing how sometimes we get inspiration from the most unexpected of quarters !
ReplyDeleteschool app in chennai
Hey, Really amazing..!
ReplyDeleteI've bookmarked your post for reference and will love to follow you.
Please keep it up good work for us.
We provide a solution to use WhatsApp in your business communications and send invoices though tally.
WhatsApp API Integration
WhatsApp API Tally
Tally Invoices to WhatsApp
best induction cooktop. creates unique index on table/view. You cannot create unique index on duplicate columns and
ReplyDeletesad shayari. drag and drop, charts, fading, all
ReplyDeleteThanks for provide great informatic and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you once agian afghani cap , antique gold choker necklace , embroidered crown patches , Afghani Hand Embroidered Shirt
ReplyDeleteThis is so fun! What a great content. Also I love how authentic you seem to be.
ReplyDelete