所以我正在设置一个程序,当你收到一条信息、彩信或短信时,它会播放设置好的声音。我得到了它的工作与短信,但彩信不做任何事情。下面是运行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”。
发布于 2012-07-02 15:49:08
您还需要指定数据方案。
清单条目应为
<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>https://stackoverflow.com/questions/11289568
复制相似问题