0

i am designing a app which will deisplay a toast with its content. i am using android studio and virtual device as lolipop api 21. please help.

MANIFEST_file and CODE

My code is :

    package com.example.vaibhav;
  import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
 import android.os.Bundle;
 import android.telephony.SmsMessage;
 import android.util.Log;
 import android.widget.Toast;
public class SMSReceiver extends BroadcastReceiver  {
    SmsManager sms = SmsManager.getDefault();

    public void onReceive(Context context, Intent intent) {

       // Retrieves a map of extended data from the intent.
       final Bundle bundle = intent.getExtras();

       try {

        if (bundle != null) {

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

            for (int i = 0; i < pdusObj.length; i++) {

                SmsMessage currentMessage =                                                                                    
                 SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                String phoneNumber = 
                currentMessage.getDisplayOriginatingAddress();

                String senderNum = phoneNumber;
                String message = currentMessage.getDisplayMessageBody();

                // Show Alert
                int duration = Toast.LENGTH_LONG;
                Toast toast = Toast.makeText(context,
                        "senderNum: " + senderNum + ", message: " + message, 
                  duration);
                toast.show();

            } // end for loop
        } // bundle is null

         } catch (Exception e) {
             Log.e("SmsReceiver", "Exception smsReceiver" + e);
        }


      }
        }

MY Manifest . xml file is:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.vaibhav"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4"
        android:targetSdkVersion="21"
        />
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses- 
      permission>
    <uses-permission android:name="android.permission.read_sms"></uses-
      permission>
    <uses-permission android:name="android.permission.hardware_test"/>
    <application android:allowBackup="true" android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
        <receiver android:name=".SMSReceiver">
            <intent-filter>
                <action 
     android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>
    </application>

    </manifest>

i am getting error on line 10. Error:(10, 5) error: cannot find symbol class SmsManager Error:(10, 22) error: cannot find symbol variable SmsManager

user2002507
  • 7
  • 1
  • 5
  • Welcome to Stack Overflow! External links have a bad habit of breaking. For posterity, please edit your question and put the relevant code inside your question. – Kyle Falconer Apr 12 '15 at 06:54
  • This answer maybe works for you, Check [here](http://stackoverflow.com/questions/29560393/display-android-toast-on-receive-of-sms/29560876?noredirect=1#comment47279628_29560876). – SilentKnight Apr 12 '15 at 07:26
  • he is doing the same thing . as he said hes also getting error. – user2002507 Apr 12 '15 at 07:34

0 Answers0