2017-06-22 85 views
-1

我正在處理同時處理電子郵件和聊天功能的項目。對於聊天,我使用套接字和郵件功能,我正在使用Java Mail Api。現在,這裏的問題,「對於這兩種功能,我需要一個廣播接收器,這樣我就可以在一個單一的應用程序中使用兩個廣播接收器可以在Android應用程序中使用多少個廣播接收器?

下面是代碼

Android清單: - 。

<receiver android:name=".receivers.ChatMsgReceiver"> 
    <intent-filter android:priority="500"> 
     <action android:name="android.intent.action.BOOT_COMPLETED"/> 
    <action android:name="android.intent.action.QUICKBOOT_POWERON"/> 
</intent-filter> 

<receiver android:name=".receivers.EmailReceiver"> 
     <intent-filter android:priority="500"> 
      <action android:name="android.intent.action.BOOT_COMPLETED"/> 
     <action android:name="android.intent.action.QUICKBOOT_POWERON"/> 
    </intent-filter> 
</receiver> 

電子郵件接收器類文件。

public class EmailReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 

    //My rest code goes here's 

} 
} 

聊天接收器類文件。

public class ChatMsgReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 

    //My rest code goes here's 

} 
} 
+1

您是否遇到此代碼的問題,使您認爲您不能? – codeMagic

+0

是的,因爲我無法收聽廣播,但是當我將它們合併爲單曲廣播時,它可以工作,但我需要兩個獨立的廣播接收器。 –

+0

好的,那麼你需要在你的文章中更好地解釋,因爲你當然可以使用倍數。在一個應用程序中,我有幾個按預期運行和工作。 – codeMagic

回答

2

所以可以使用兩個廣播接收器中的單個應用程序。

是的,你可以。

相關問題