首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在安卓系统上像SMS_RECEIVED一样监控MMS_RECEIVED

在安卓系统上像SMS_RECEIVED一样监控MMS_RECEIVED
EN

Stack Overflow用户
提问于 2012-07-02 15:44:41
回答 1查看 3.6K关注 0票数 2

所以我正在设置一个程序,当你收到一条信息、彩信或短信时,它会播放设置好的声音。我得到了它的工作与短信,但彩信不做任何事情。下面是运行BroadcastReceiver的类的代码:

代码语言:javascript
复制
/**
 * 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();
    }

}

我在清单中这样设置:

代码语言:javascript
复制
<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>

当然还包括:

代码语言:javascript
复制
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />

我还试着在清单中这样做接收器:

代码语言:javascript
复制
<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>

我也试着把听筒放进去:

代码语言:javascript
复制
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />

但这并没有起到任何作用。

任何帮助都将不胜感激。谢谢。另外,为什么有时在清单中的类名前加一个句点,而不是其他的呢?比如android:name=".TextMonitor“,然后有时是android:name="TextMonitor”。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-02 15:49:08

您还需要指定数据方案。

清单条目应为

代码语言:javascript
复制
<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>
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11289568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档