2016-10-26 2 views
0

앱이 더 이상 활성화되지 않은 경우 FCM에서 푸시 알림을 수신하는 방법 (최근 작업이 아님). 나는 gmail을 본다, whatsapp는이 특징을 가지고있다. 푸시 알림에 FCM을 사용하고 있습니다. 나는 장치 깨우기를 위해 WakefulBroadcast 수신기를 사용했다. 어떻게 사용합니까?앱이 더 이상 활성 상태가 아닐 때 푸시 알림 받기

서비스 클래스 :

@Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     // [START_EXCLUDE] 
     // There are two types of messages data messages and notification messages. Data messages are handled 
     // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type 
     // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app 
     // is in the foreground. When the app is in the background an automatically generated notification is displayed. 
     // When the user taps on the notification they are returned to the app. Messages containing both notification 
     // and data payloads are treated as notification messages. The Firebase console always sends notification 
     // messages. For more see: 
     // [END_EXCLUDE] 

     // TODO(developer): Handle FCM messages here. 
     // Not getting messages here? See why this may be: 

     try { 
      if (remoteMessage.getData().size() > 0) { 
       Log.d(TAG, "Message data payload: " + remoteMessage.getData()); 
      } 

      // Check if message contains a notification payload. 
      if (remoteMessage.getNotification() != null) { 
       Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); 
      } 
      sendNotification(remoteMessage); 
      // Also if you intend on generating your own notifications as a result of a received FCM 
      // message, here is where that should be initiated. See sendNotification method below. 
     } catch (Exception ex) { 
      Log.e(TAG, ex.getMessage()); 
     } 
     // Check if message contains a data payload. 

    } 

수신기 :

public class FCMBroadcastReceiver extends BroadcastReceiver { 
    public static final String TAG = FCMBroadcastReceiver.class.getSimpleName(); 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.i(TAG+"~~~~~~~", "On Boot Completed"); 
     // ComponentName comp = new ComponentName(context.getPackageName(), 
       //YumigoBidMessagingService.class.getName()); 
     // Start the service, keeping the device awake while it is launching. 

     //startWakefulService(context, (intent.setComponent(comp))); 
     //setResultCode(Activity.RESULT_OK); 

     Intent intent1 = new Intent(context, YumigoBidMessagingService.class); 
     context.startService(intent1); 

    } 
} 

ManifestFile :

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    package="in.yumigo.yumigovendor" 
    android:versionCode="2" 
    android:versionName="1.0.1"> 

    <permission android:name="in.yumigo.yumigovendor.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 
    <uses-permission android:name="in.yumigo.yumigovendor.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.READ_SMS" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="android.permission.RECEIVE_SMS" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.READ_LOGS" /> 
    <uses-feature android:name="android.hardware.camera"/> 
    <uses-feature android:name="android.hardware.location.gps" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

    <application 
     android:name=".YumigoVendorApplication" 

     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
<receiver 
      android:name="in.yumigo.yumigovendor.receivers.FCMBroadcastReceiver" 
      > 
      <intent-filter> 

       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <!--<action android:name="android.intent.action.QUICKBOOT_POWERON" /> 
       <category android:name="android.intent.category.DEFAULT" />--> 
       <!-- <category android:name="com.android.recognition" /> 
       <category android:name="in.yumigo.yumigovendor.receivers" />--> 
      </intent-filter> 
     </receiver> 

답변

0

응용 프로그램이 한 번 호출해야하고 FCM 코드 (서비스로 구현) Play 상담원이 호출합니다. 그런 다음 NotificationManager를 호출하여 메시지를 팝업 할 수 있습니다. FCM은 "통지"가 "데이터"페이로드와 구별되는 "통지"를 처리합니다. HTH, 행운을 빌어 요.

+0

응용 프로그램을 한 번 호출하는 방법, 여기에 거래가 있다고 생각합니다. 나는 또한 코드를 업데이트 할 것이다. – androider

+0

코드를 업데이트했다. – androider

관련 문제