Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在状态栏中显示通知文本-Android_Android_Android Notifications_Google Cloud Messaging - Fatal编程技术网

在状态栏中显示通知文本-Android

在状态栏中显示通知文本-Android,android,android-notifications,google-cloud-messaging,Android,Android Notifications,Google Cloud Messaging,在我的应用程序中,我需要向用户显示通知。下面的代码片段在Android设备标题栏中显示图标和内容标题,效果非常好 var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; var uiIntent = new Intent(this, typeof(MainActivity)); var notification = new Notification(Resour

在我的应用程序中,我需要向用户显示通知。下面的代码片段在Android设备标题栏中显示图标和内容标题,效果非常好

var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
var uiIntent = new Intent(this, typeof(MainActivity));
var notification = new Notification(Resource.Drawable.AppIcon, title);
notification.Flags = NotificationFlags.AutoCancel;
notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));
notificationManager.Notify(1, notification);
当我尝试构建用于部署应用程序的包时,出现以下错误:

Android.App.Notification.setLateStevenInfo(Android.Content.Context, string,string,Android.App.pendingent)“”已过时:“已弃用”

所以我找到了这个我应该使用的代码片段,它在状态栏中显示图标,而不是内容标题

Intent resultIntent = new Intent(this, typeof(MainActivity));

PendingIntent pi = PendingIntent.GetActivity(this, 0, resultIntent, 0);

NotificationCompat.Builder builder = new NotificationCompat.Builder(Forms.Context)
    .SetContentIntent(pi) 
    .SetAutoCancel(true) 
    .SetContentTitle(title)
    .SetSmallIcon(Resource.Drawable.AppIcon)
    .SetContentText(desc); //This is the icon to display

NotificationManager nm = GetSystemService(Context.NotificationService) as NotificationManager;
nm.Notify(_TipOfTheDayNotificationId, builder.Build());

我需要在新的代码段中设置什么才能在android设备状态栏中显示内容标题?

我需要将
.setTicker()
添加到第二个代码段中,以便在android设备状态栏中显示以下代码中的文本。第二个片段中的一些更正

Intent resultIntent = new Intent(this, TestService.class); 

    PendingIntent pi = PendingIntent.getActivity(this, 0, resultIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
        .setContentIntent(pi) 
        .setAutoCancel(true) 
        .setContentTitle("title")
        .setSmallIcon(R.drawable.ic_notif) //add a 24x24 image to the drawable folder
                                           // and call it here 
        .setContentText("desc"); 

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(0, builder.build());

setcontenttitle不是这样做的吗?可能重复(不同的语言,但相同的api,所以可能重复?)我在这里回答了这个问题:这应该是公认的答案!另一个问题的答案是你应该给一个小图标,但它们是无用的。