如何制作带有声音的提醒通知,例如whatsapp通知



我是安卓编程的新手。我希望我的应用程序在屏幕顶部显示弹出通知(它可能称为提醒通知(,无论是在后台还是前台,并为其添加声音,但不知道如何。代码非常基本。

我的火基消息服务.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。

Toast.makeText(getApplicationContext(),"Your message",Toast.LENGTH_SHORT).show();  

有关通知栏通知,请查看通知生成器。 您也可以使通知发出声音。

相关内容

  • 没有找到相关文章

最新更新