• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Read SMS?

Sergioum86

Lurker
Sep 14, 2010
3
0
Hello, I am pretty new to android and I'm trying to create an application that reads the text of an incoming SMS, however, I've tried many methods found on several tutorials and none of those seem to work.

Could anybody help me?

this is what I've tried:

Code:
package com.smsReader;

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 SmsReceptor extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent){
        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+= msgs[i].getMessageBody();
                
            }
             Toast.makeText(context, str, Toast.LENGTH_LONG).show();
        }
            
    }

}
and this is my Manifest

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.smsReader"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MessageReader"
                  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=".SmsReceptor" android:enabled="true">
    <intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
    </intent-filter>
    </receiver>
</application>
    <uses-sdk android:minSdkVersion="7" />

<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
</manifest>
However, the application never touches that class, Am I missing something on it?
 
I have the same issues, and going crazy... I have the correct permission in my manifest, but in the log it reads:

09-20 19:01:50.710: WARN/ActivityManager(51): Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } to xxx.xxx.xxx requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)

Can anyone help?
 
Upvote 0
Finally got it to work, but i had to declare the receiver dynamically in my service. Dont know why is working for you others, I cant get it to work if I declare it in the manifest, perhaps its like the SCREEN_ON intent which also needs to be received dynamically? Will post the manifest file later on when I am back home
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones