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
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);
}
Können Sie Ihren '.receiver.CustomPushReceiver' bitte teilen? –
teilen Sie jetzt diesen Methodencode 'parsePushJson' .. teilen Sie den vollen Code, wo die Benachrichtigungen aufbauen. – Bharatesh
Überprüfen Sie meine bearbeitete Antwort @JPn bitte –