This is my first effort in making an Android app. It is a simple SMS listener that then displays SMS as a Toast.
public class SmsReciever extends BroadcastReceiver {
String msgBody = null;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals("android.provider.Telephony.SMS_RECIEVED")){
Bundle bundle = intent.getExtras();
SmsMessage[] msg = null;
String msg_from;
if(bundle != null)
{
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msg = new SmsMessage[pdus.length];
for(int i=0;i<msg.length;i++)
{
msg[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
msg_from = msg[i].getOriginatingAddress();
msgBody += msg[i].getMessageBody();
}
}catch(Exception e)
{
Log.d("Exception caught",e.getMessage());
}
Toast.makeText(context, msgBody, Toast.LENGTH_SHORT).show();
}
}
}}
I am getting the following error:
java.lang.RuntimeException: Unable to instantiate receiver com.example.droid.SmsReceiver: java.lang.ClassNotFoundException: com.example.droid.SmsReceiver
I assure you the SmsReciever.java is in droid/src. I have spent whole night researching on this problem. Please help.
EDIT: This is the manifest xml file that u asked for.
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" android:permission="android.permission.RECEIVE_SMS">
<activity
android:name=".JarvisActivity"
android:label="@string/title_activity_jarvis" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecureMessagesActivity" 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" android:exported="false" >
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
EDIT: I did a bit of a research and found out that in my manifest file i have an activity tag which points to SecureMessagesActivity. But in my whole project i don't have an activity by that name. So is this the problem?
EDIT: Okay, So i deleted the SecureMessageActivity part from my manifest file and i guess it removed the error. Now i'm getting this Permisssion denial message:
Permission Denial: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED flg=0x10 (has extras) } to net.learn2develop.SMSMessaging requires android.permission.RECEIVE_SMS due to sender com.android.phone (uid 1001)
Also net.learn2develop.SMSMessaging activity was used by me in an attempt to copy another code for the same purpose but now i have deleted the whole project and cleaned my own project many times. Still this activity keeps coming again and again. edit Chuck it i'll be starting all over again soon... Thanks for all the input.