views:

58

answers:

1

Hello,

I'm trying to receive SMS using broadcast receiver. MySMSReceiver :

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;

public class MySmsReceiver extends BroadcastReceiver {
    /** Tag string for our debug logs */
    private static final String TAG = "MySmsReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "Recieved a message");
        Bundle extras = intent.getExtras();
        if (extras == null)
            return;

        Object[] pdus = (Object[]) extras.get("pdus");

        for (int i = 0; i < pdus.length; i++) {
            SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
            String fromAddress = message.getOriginatingAddress();
            String fromDisplayName = fromAddress;

            Log.i(TAG, fromAddress);
            Log.i(TAG, fromDisplayName);
            Log.i(TAG, message.getMessageBody().toString());

            break;          
        }
    }
}

and added in Mainfest file

<receiver android:name=".MySmsReceiver" android:enabled="false">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
    <uses-permission android:name="android.permission.RECEIVE_SMS" />

but when I run this app and send a sms using emulator it shows following logs in logcat

10-12 00:14:53.082: VERBOSE/Telephony(1032): getOrCreateThreadId uri: content://mms-sms/threadID?recipient=9898989898
10-12 00:14:53.203: VERBOSE/Telephony(1032): getOrCreateThreadId cursor cnt: 1
10-12 00:14:53.432: DEBUG/Mms:app(1032): getSmsNewMessageNotificationInfo: count=4, first addr=9898989898, thread_id=3
10-12 00:14:53.482: WARN/NotificationService(62): STOP command without a player
10-12 00:14:53.562: DEBUG/MediaPlayer(62): Couldn't open file on client side, trying server side
10-12 00:14:53.582: ERROR/MediaPlayerService(34): Couldn't open fd for content://settings/system/notification_sound
10-12 00:14:53.592: ERROR/MediaPlayer(62): Unable to to create media player
10-12 00:14:53.643: WARN/NotificationService(62): error loading sound for content://settings/system/notification_sound
10-12 00:14:53.643: WARN/NotificationService(62): java.io.IOException: setDataSource failed.: status=0x80000000
10-12 00:14:53.643: WARN/NotificationService(62):     at android.media.MediaPlayer.setDataSource(Native Method)
10-12 00:14:53.643: WARN/NotificationService(62):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:716)
10-12 00:14:53.643: WARN/NotificationService(62):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:671)
10-12 00:14:53.643: WARN/NotificationService(62):     at com.android.server.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:88)

Suggest me what could be the reason.

+1  A: 

I got this problem solved. I was running in an AVD which was created Google API as runtime and may be some of the classes are not available in that API, so on changing AVD runtime to Android 2.2 it works fine.

GG