-2

I have done everything exactly as tutorial shows but I still get one error...I have created new activity SmsReceiver.java and there is everything OK but in the manifest when I try to add this

<receiver android:name=".SmsReceiver">  // <-- this is problem
        <intent-filter android:priority="1000">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
</receiver>

It doesn't want to accept that class .SmsReceiver....

I have tried everything please help. When i hover mouse over it says " 'class' or 'interface' expected ".

Here is package view and manifest full code

This is SmsReceiver.java code

package com.dreamdev.matko.smsarduino;

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 SmsReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    if (bundle != null) {

        Object[] pdus = (Object[]) bundle.get("pdu");

        for (int i = 0; i < pdus.length; i++) {
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdus[i]);

            String from = sms.getOriginatingAddress();

            String msg = sms.getDisplayMessageBody();

            Toast.makeText(context, "Prišla správa", Toast.LENGTH_LONG).show();
        }

    }

  }

}
Matrox798
  • 1
  • 3

2 Answers2

0

You say:

I have created new activity SmsReceiver.java

If you have created an Activity, then you cannot declare it in the manifest as a BroadcastReceiver. If you want to have a BroadcastReceiver then your class needs to extend BroadcastReceiver and then you add it to the manifest like this:

<receiver android:name=".SmsReceiver">
David Wasser
  • 93,459
  • 16
  • 209
  • 274
0

Please extend the class as a BroadcastReceiver in your .java file. Like below

public class SmsReceiver extends BroadcastReceiver {
    ......
}
Gaurav Sarma
  • 2,248
  • 2
  • 24
  • 45