在android上监听MMS_RECEIVED,如SMS_RECEIVED

dj.*_*xss 2 wap android telephony mms broadcastreceiver

因此,我正在设置一个程序,播放收到消息,mms或短信时设置的声音.我得到它与SMS工作,但MMS没有做任何事情.以下是运行BroadcastReceiver的类的代码:

/**
 * This class overrides the main BroadcastReceiver to play the tone
 * at the given textSoundPath.
 * @author Jesse Stewart
 *
 */
public class TextMonitor extends BroadcastReceiver {

    public static String textSoundPath;     //this is the sound set to play when
                                            //sms or mms is received.

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        MediaPlayer tonePlayer = new MediaPlayer();

        try {
            tonePlayer.setDataSource(textSoundPath);
        } catch (Exception e) {
            System.out.println("Couldn't set the media player sound!!!!!");
            e.printStackTrace();
        }

        try {
            tonePlayer.prepare();
        } catch (Exception e) {
            System.out.println("Couldn't prepare the tone player!!!!!");
            e.printStackTrace();
        }

        tonePlayer.start();
    }

}
Run Code Online (Sandbox Code Playgroud)

我在清单中设置如下:

<receiver android:name=".TextMonitor">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.provider.Telephony.MMS_RECEIVED" />
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

当然包括:

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
Run Code Online (Sandbox Code Playgroud)

我也尝试在清单中做接收器,如下所示:

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

<receiver android:name=".TextMonitor">
    <intent-filter>
            <action android:name="android.provider.Telephony.MMS_RECEIVED" />
    </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

我也尝试过接收器:

<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
Run Code Online (Sandbox Code Playgroud)

但这没有任何效果.

任何帮助,将不胜感激.谢谢.另外,为什么你有时会在清单中放一个句号而不是其他的?像android:name =".TextMonitor"然后有时候android:name ="TextMonitor".

Vip*_*hah 8

您还需要指定数据方案.

清单入口应该是

<receiver android:name=".PushReceiver">
  <intent-filter>
    <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
    <data android:mimeType="application/vnd.wap.mms-message" />
  </intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)