gpt4 book ai didi

Android:推送通知没有声音/振动/灯光

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:34 27 4
gpt4 key购买 nike

我在收到通知时听不到声音、振动或灯光。有人可以告诉我我缺少什么吗?

还有一些问题:

1.) 我只在应用程序打开时得到指定的图标。当应用程序关闭时,我会看到 android Logo 图标(我想那是因为我还没有定义应用程序图标)。

2.) 代码文本仅在应用程序打开时显示。

3.) 当应用程序打开时,我没有得到内容文本,只有内容标题。

解决方案:发生这种情况是因为我在以前的版本上使用 com.google.android.gms:play-services-gcm:8.4.0

确保在服务器上发送的通知数组仅包含键/值对 e=0,同时在数据数组中发送消息信息。

这个问题在这里已经有了很好的答案:After updating Google play services to 8.4.0 push notifications displayed by themselves

这是我的来源:

public class MyGcmListenerService extends GcmListenerService {

private final static String TAG = "GCM_Listener";

@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from + " (" + message);

// Sets an ID for the notification
SharedPreferences sharedPreferences = getSharedPreferences(getString(R.string.sharedPreferenceStore_default), Context.MODE_PRIVATE);

int mNotificationId = sharedPreferences.getInt("id_notification", 0);
mNotificationId++;

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.all_picks_made_indicator)
.setAutoCancel(true)
.setContentTitle("Product - " + mNotificationId)
.setContentText(message)
.setTicker("Product Notification received");



// Because clicking the notification opens a new ("special") activity, there's no need to create an artificial back stack.
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DetectLoginActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);

// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
Notification notification = mBuilder.build();
notification.defaults = Notification.DEFAULT_ALL;
mNotifyMgr.notify(mNotificationId, notification);

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("id_notification", mNotificationId);
editor.commit();
}
}

最佳答案

推送通知的自定义声音

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pop);

在你的代码更改中

    Notification notification = mBuilder.build();
notification.defaults = Notification.DEFAULT_ALL;
mNotifyMgr.notify(mNotificationId, notification);

到。

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.pop);
notification.defaults |= Notification.DEFAULT_VIBRATE;

关于Android:推送通知没有声音/振动/灯光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36868126/

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