开发者

Android BroadcastReceiver works on MOTODEV Emulator but not on Actual Motorola i1 device

开发者 https://www.devze.com 2023-02-08 10:24 出处:网络
I have a simple android app (API 1.5) devel开发者_开发问答oped for Motorola i1 from Nextel. It creates a simple SMS listener via BroadcastReveiver and it works when I test it

I have a simple android app (API 1.5) devel开发者_开发问答oped for Motorola i1 from Nextel. It creates a simple SMS listener via BroadcastReveiver and it works when I test it on the i1 emulator that came with MOTODEV android studio.

When I install it on the actual device nothing... onReceive never gets called. I can see this via debug trace...

I tried some other receivers i.e Intent.ACTION_AIRPLANE_MODE_CHANGED to see if this is a SMS specific issue but same thing...works on emulator not on device. What am I missing here? Any ideas?

Here is the code:

package com.smsmanager;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        registerReceiver(br, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
    }

    private BroadcastReceiver br = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Hello SMS", Toast.LENGTH_LONG).show();

        }
    };

}

AND here is the manifest:

<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="1" android:versionName="1.0"
    package="com.smsmanager" mlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <uses-sdk android:minSdkVersion="3" />
</manifest>

I am starting to think that this may be due to changes made by Motorola!?


I got this resolved with the help of Pragnesh Goyani...

Motorola i1 unit from Nextel supports MMS as a transport even for Text messages. Thus, an incoming text message won't invoke SMS Broadcast intent. You may want to use "android.provider.Telephony.WAP_PUSH_RECEIVED" intent instead.

here is the solution:

to put following code in your AndroidManifest.xml.

<receiver android:name=".SmsReceiver">
              <intent-filter>
                   <action android:name="android.provider.Telephony.SMS_RECEIVED" />

              </intent-filter>
              <intent-filter>
                    <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
                    <data android:mimeType="application/vnd.wap.mms-message" />
              </intent-filter>
</receiver>
0

精彩评论

暂无评论...
验证码 换一张
取 消