そこで、メッセージ、mms、または sms を受信したときに設定されたサウンドを再生するプログラムをセットアップしています。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" のようになります。