2017-10-16 1 views
0

내 맞춤 구문 푸시 알림 클래스에서 FCM 푸시 알림에 등록한 Android 애플리케이션에서 작업 중입니다. Parse Dashboard에서 푸시를 보낼 때 리시버에 들어 있지만 내 화면의 알림 표시 줄에 표시하지 않습니다. Manifest 및 코드와 함께 사용자 정의 클래스가 아래에 나와 있습니다. 나는 비슷한 질문을 많이했지만 행운은 찾지 못했다.Android 8.0에서 sdk 구문 분석을 사용하여 푸시 알림 표시 안 함

내 매니페스트 :

<receiver android:name="com.parse.GcmBroadcastReceiver" 
      android:permission="com.google.android.c2dm.permission.SEND"> 
      <intent-filter> 
       <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
       <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
       <category android:name="com.kolbeh" /> 
      </intent-filter> 
     </receiver> 
     <meta-data android:name="com.parse.push.gcm_sender_id" 
      android:value="id:854901#####" /> 

     <service android:name="com.parse.PushService" /> 

     <receiver 
      android:name="dinewhere.fcm.CustomPushReceiver" 
      android:exported="false"> 
      <intent-filter> 
       <action android:name="com.parse.push.intent.RECEIVE" /> 
       <action android:name="com.parse.push.intent.OPEN" /> 
       <action android:name="com.parse.push.intent.DELETE" /> 
      </intent-filter> 
     </receiver> 

내 사용자 정의 수신기 :

public class CustomPushReceiver extends ParsePushBroadcastReceiver { 
    private final String TAG = CustomPushReceiver.class.getSimpleName(); 

    private NotificationUtils notificationUtils; 

    private Intent parseIntent; 

    public CustomPushReceiver() { 
     super(); 
    } 

    @Override 
    protected void onPushReceive(Context context, Intent intent) { 
     //super.onPushReceive(context, intent); 

     if (intent == null) 
      return; 

     try { 
      JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); 

      Log.e(TAG, "Push received: " + json); 

      parseIntent = intent; 

      parsePushJson(context, json); 

     } catch (JSONException e) { 
      Log.e(TAG, "Push message json exception: " + e.getMessage()); 
     } 
    } 

    @Override 
    protected void onPushDismiss(Context context, Intent intent) { 
     super.onPushDismiss(context, intent); 
    } 

    @Override 
    protected void onPushOpen(Context context, Intent intent) { 
     super.onPushOpen(context, intent); 
     System.out.println("asdf"); 
    } 

    /** 
    * Parses the push notification json 
    * 
    * @param context 
    * @param json 
    */ 
    private void parsePushJson(Context context, JSONObject json) { 
     try { 
      String message = json.getString("alert"); 

      Intent resultIntent = new Intent(context, MainActivity.class); 
      resultIntent.putExtra("Chat", true); 
      showNotificationMessage(context, "Hello", message, resultIntent); 

     } catch (JSONException e) { 
      Log.e(TAG, "Push message json exception: " + e.getMessage()); 
     } 
    } 


    /** 
    * Shows the notification message in the notification bar 
    * If the app is in background, launches the app 
    * 
    * @param context 
    * @param title 
    * @param message 
    * @param intent 
    */ 
    private void showNotificationMessage(Context context, String title, String message, Intent intent) { 

     notificationUtils = new NotificationUtils(context); 

     intent.putExtras(parseIntent.getExtras()); 

     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

     notificationUtils.showNotificationMessage(title, message, intent); 
    } 
} 

내 showNotificationMessage 방법 :

public void showNotificationMessage(String title, String message, Intent intent) { 

     // Check for empty push message 
     if (TextUtils.isEmpty(message)) 
      return; 

     if (airportAssistUtil.isAppIsInBackground(mContext)) { 
      // notification icon 
      int icon = R.mipmap.ic_launcher_round; 



      PendingIntent resultPendingIntent = 
        PendingIntent.getActivity(
          mContext, 
          0, 
          intent, 
          PendingIntent.FLAG_CANCEL_CURRENT 
        ); 

      NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); 

      PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 

      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
        mContext); 
      Notification notification = mBuilder.setSmallIcon(icon).setTicker("Kolbeh").setWhen(0) 
        .setAutoCancel(true) 
        .setStyle(inboxStyle) 
        .setContentTitle("Kolbeh") 
        .setContentIntent(resultPendingIntent) 
        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 
        .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon)) 
        .setContentText(message) 
        .build(); 

      mBuilder.setContentIntent(contentIntent); 

      NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); 
      notificationManager.notify(count++, notification); 
     } 
    } 

답변

2

앱이 Android O를 타겟팅하는 경우 알림 채널로 알림을 표시해야합니다. android O 각 알림은 채널 Read here 안에 있어야합니다.

+0

답장을 보내 주셔서 감사합니다. 내 코드에 따라 알림 채널의 예를 들어 주시겠습니까? 나는 그걸 혼동하지 않는다. –

+0

앱이 Android O를 타겟팅하는 경우? 그런 다음 Android O 알림 채널을 탐색하는 [예] (https://medium.com/exploring-android/exploring-android-o-notification-channels-94cd274f604c)입니다. 그것으로 끝까지 가십시오. git의 [Sample] (https://github.com/googlesamples/android-NotificationChannels)도 있습니다. – ADM

+0

아직도 작동하지 않습니다 @ADM –

관련 문제