如何使声音像whatsapp通知声音
问题描述:
我是新的android编程。我希望我的应用程序显示弹出通知(它可能称为抬头通知)在屏幕的顶部是否它在背景或前景中,并添加声音,但不知道如何。代码是非常基本的。如何使声音像whatsapp通知声音
MyFirebaseMessageService.java
public class MyFirebaseMessageService extends FirebaseMessagingService {
public static final String TAG = "FCM";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message: " + remoteMessage.getNotification().getBody());
}
}
MyFirebaseIdService.java
public class MyFirebaseIDService extends FirebaseInstanceIdService {
private static String TAG = "INSTANCEID";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed Token: " + refreshedToken);
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
}
}
答
你想让你的通知在屏幕上,或在通知栏上?
对于简单的屏幕上的通知使用吐司。
Toast.makeText(getApplicationContext(),"Your message",Toast.LENGTH_SHORT).show();
For a notification bar notification take a look at NotificationBuilder. You can make your notification make sound as well.
+0
nope。它没有工作 –
+0
我希望它在屏幕上 –
您所提供的代码只是从快速入门出来。什么在这里没有为你工作? –