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:
and this is my Manifest
However, the application never touches that class, Am I missing something on it?
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();
}
}
}
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>