2016-04-27 11 views
0

Implementiert Individuelle Benachrichtigung mit diesem tutorialbenutzerdefinierte Benachrichtigung

Problem erhält 2-Benachrichtigungen jetzt. Eins ist Standard Benachrichtigung und andere ist benutzerdefinierte Benachrichtigung.

So deaktivieren Sie Standardbenachrichtigung.

Code:

public void showNotificationMessages(String title, String message, Intent intent) { 
     int icon = R.mipmap.ic_launcher; 
     PendingIntent resultPendingIntent = 
       PendingIntent.getActivity(
         mContext, 
         0, 
         intent, 
         PendingIntent.FLAG_UPDATE_CURRENT 
       ); 
     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) 
       .setSmallIcon(icon) 
       .setContentTitle("Project") 
       .setContentText(""+title+" custom notification") 
       .setContentIntent(resultPendingIntent) 
       .setAutoCancel(true); 
     int mNotificationId = 001; 
     NotificationManager mNotifyMgr = 
       (NotificationManager) mContext. getSystemService(Context.NOTIFICATION_SERVICE); 
     mNotifyMgr.notify(mNotificationId, mBuilder.build()); 
} 

Manifest

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

Screenshot

Screenshot

CustomReceiver

@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()); 
    } 
} 
private void parsePushJson(Context context, JSONObject json) { 
    try { 

     String title = json.getString("alert"); 

     Intent resultIntent = new Intent(context, MainActivity.class); 
     showNotificationMessage(context, title, "", resultIntent); 


    } catch (JSONException e) { 
     Log.e(TAG, "Push message json exception: " + e.getMessage()); 
    } 
} 
    private void showNotificationMessage(Context context, String title, String message, Intent intent) { 

    notificationUtils = new NotificationUtils(context); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    notificationUtils.showNotificationMessages(title, message, intent); 
} 
+0

Können Sie Ihren '.receiver.CustomPushReceiver' bitte teilen? –

+0

teilen Sie jetzt diesen Methodencode 'parsePushJson' .. teilen Sie den vollen Code, wo die Benachrichtigungen aufbauen. – Bharatesh

+0

Überprüfen Sie meine bearbeitete Antwort @JPn bitte –

Antwort

1

Wahrscheinlich versuchen Sie Ihre Parse-Benachrichtigungen zu manipulieren.

Also, wenn Sie Ihre ändern onPushReceive

@Override 
protected void onPushReceive(Context context, Intent intent) { 
    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()); 
} 
    return; 
} 

Sie werden nicht in der Lage sein, Ihre Push-Benachrichtigung von Parse zu erhalten, indem super.OnPushReceive() entfernen, so dass Sie nur

Ihre individuelle Push-Benachrichtigung sehen
0

Es wäre toll Wenn Sie Ihren CustomReceiver teilen, aber aus meiner Erfahrung, sollten Sie GcmReceiver oder jede andere Klasse erweitern, die es möglicherweise bereits erweitern.

Verwandte Themen