【问题标题】:Monitoring MMS_RECEIVED like SMS_RECEIVED on android在 android 上监控 MMS_RECEIVED 就像 SMS_RECEIVED
【发布时间】:2012-07-02 07:44:40
【问题描述】:

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

【问题讨论】:

    标签: android broadcastreceiver telephony mms wap


    【解决方案1】:

    您还需要指定数据方案。

    清单条目应该是

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

    【讨论】:

    • @dj.lnxss 如果解决了您的问题,请关闭问题。
    • @dj.lnxss 如果这是完美的解决方案,那么您为什么不接受答案。 PL 标记为绿色勾号:p
    • @VipulShah MMS 或任何相关数据是否与 Intent 一起提供?如果是这样,你如何解析它?
    • @VipulShah 可以通过编程方式注册吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多