gpt4 book ai didi

android - 自定义通知

转载 作者:行者123 更新时间:2023-11-30 01:22:28 26 4
gpt4 key购买 nike

使用此 tutorial 实现自定义通知

问题 现在收到 2 个通知。 一种是默认通知,另一种是自定义通知

如何禁用默认通知。

代码:

 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());
}

list

  <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

自定义接收者

@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);
}

最佳答案

可能您正试图操纵您的解析通知。

所以如果你改变你的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;
}

您将无法通过删除 super.OnPushReceive() 从解析中获取您的推送通知,因此您将只能看到您的自定义推送通知

关于android - 自定义通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36890425/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com