gpt4 book ai didi

android - 在 android 上像 SMS_RECEIVED 一样监控 MMS_RECEIVED

转载 作者:太空狗 更新时间:2023-10-29 15:55:36 25 4
gpt4 key购买 nike

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

}

我在 list 中这样设置它:

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

我也试过像这样在 list 中做接收器:

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

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

如有任何帮助,我们将不胜感激。谢谢。还有一个旁注,为什么有时在 list 中的类名前加一个句点,而其他的则不加?像 android:name=".TextMonitor"然后有时 android:name="TextMonitor".

最佳答案

您还需要指定数据方案。

list 条目应该是

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

关于android - 在 android 上像 SMS_RECEIVED 一样监控 MMS_RECEIVED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11289568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com