2

因此,我正在设置一个程序,该程序播放在您收到消息、彩信或短信时设置的声音。我让它与 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();
    }

}

我在清单中这样设置它:

<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>

当然包括:

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

我还尝试像这样在清单中执行接收器:

<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>

我还尝试放入接收器:

<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />

但这只是没有任何效果。

任何帮助,将不胜感激。谢谢。附带说明一下,为什么有时在清单中的类名之前放一个句点而不是其他的?像 android:name=".TextMonitor" 有时是 android:name="TextMonitor"。

4

1 回答 1

10

您还需要指定数据方案。

清单条目应该是

<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>
于 2012-07-02T07:49:07.727 回答