2012-07-02 64 views
2

上監聽MMS_RECEIVED like SMS_RECEIVED因此,我正在設置一個播放設置,當您收到一條消息,毫米或短信時設置的聲音的程序。我將它與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」。

回答

8

您還需要指定數據方案。

Manifest條目應該

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

真棒,那工作。謝謝。 –

+0

@ dj.lnxss如果它解決了你的問題,那麼請關閉這個問題。 –

+0

@ dj.lnxss如果這是完美的解決方案,那麼你爲什麼不接受答案。 PL標記爲綠色標記:p – swiftBoy