所以我正在设置一个程序,播放收到消息,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();
}
}
我在清单中将其设置为:
<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”。
答案 0 :(得分: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>