Android-只收到通知声音,没有实际的文本通知

Android-只收到通知声音,没有实际的文本通知,android,notifications,Android,Notifications,这是我正在使用的代码。我能听到通知正在运行,但没有文本 @Override public void onReceive(Context context, Intent arg1) { showNotification(context); } private void showNotification(Context context) { PendingIntent contentIntent = PendingIntent.getActivity(context, 0,

这是我正在使用的代码。我能听到通知正在运行,但没有文本

@Override
public void onReceive(Context context, Intent arg1) {
    showNotification(context);
}

private void showNotification(Context context) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, MyActivity.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
            .setContentTitle("My notification")
            .setContentText("Hello World!");
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    mBuilder.setAutoCancel(true);
    NotificationManager mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());

}  

如果您使用的是support-v4库,请使用此代码

private void showNotification(Context context) {
    PendingIntent pIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, DashBoard.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("My notification")
            .setContentText("Hello World!");
    mBuilder.setContentIntent(pIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.getNotification());
}  

如果您使用的是support-v4库,请使用此代码

private void showNotification(Context context) {
    PendingIntent pIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, DashBoard.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("My notification")
            .setContentText("Hello World!");
    mBuilder.setContentIntent(pIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.getNotification());
}  

您需要添加一个图标
新建NotificationCompat.Builder(此)

.setSmallIcon(R.drawable.ic_发射器)

您需要添加一个图标
新建NotificationCompat.Builder(此)

.setSmallIcon(R.drawable.ic_发射器)

如果没有声音,那么你怎么能听到?有声音,没有文字,对不起,让我们通过实现来尝试这个如果没有声音,那么你怎么能听到?有声音,没有文字,对不起,让我们通过实现来尝试这个我得到声音,没有视觉通知,对不起,我得到声音,没有视觉通知,对不起