Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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
C# Xamarin在Galaxy 8&;9_C#_Android_Xamarin_Mobile_Samsung Mobile - Fatal编程技术网

C# Xamarin在Galaxy 8&;9

C# Xamarin在Galaxy 8&;9,c#,android,xamarin,mobile,samsung-mobile,C#,Android,Xamarin,Mobile,Samsung Mobile,我有一个应用程序,在应用程序图标上的小红点上显示通知号码。除三星Galaxy S9外,其他所有型号均可使用。我尝试了很多解决方案,但总是出错 权限拒绝:写入com.sec.android.provider.badge.BadgeProvider uricontent://com.sec.badge/apps 从pid=32464开始,uid=10233需要com.sec.android.provider.badge.permission.WRITE或grantUriPermission() 该项

我有一个应用程序,在应用程序图标上的小红点上显示通知号码。除三星Galaxy S9外,其他所有型号均可使用。我尝试了很多解决方案,但总是出错

权限拒绝:写入com.sec.android.provider.badge.BadgeProvider uricontent://com.sec.badge/apps 从pid=32464开始,uid=10233需要com.sec.android.provider.badge.permission.WRITE或grantUriPermission()

该项目是Visual Studio 2017中的一个Xamarin Android项目,下面是适用于除S9之外的所有型号的代码

在舱单上

<uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />

正如我所说的,这一切都适用于早期的模型,但在新模型中会出现错误。是否有需要添加到权限中的内容,或者我是否缺少其他内容?

我有一个解决问题的方法。您现在需要在NotificationManager中使用NotificationChannel。我已经创建了一个带有一个按钮的小测试应用程序。在按钮点击中,我调用下面的代码。我还没有将其移动到我的live应用程序,但它在这个测试应用程序中运行良好

首先,添加一个常量,用于NotificationChannel的id参数

public const string CLICKS_CHANNEL = "com.yourcompany.SamsungBadgeTest.clicks";
现在:

  • 将NotificationManager的声明移动到NotificationBuilder之上
  • 创建NotificationChannel
  • 调用管理器的CreateNotificationChannel,将通道作为参数传递
  • 发出通知。生成器
  • 构建()

  • 别忘了把它添加到你的清单上

    <uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
    <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />
    
    
    
    Android Oreo推出了自己的徽章,即通知点,因此默认情况下,制造商/OEM设备不再需要定制每台设备的“hacks”来显示徽章。Oreo中的默认方式是在应用程序图标上显示一个点,然后长按它查看详细信息,三星当然在其版本中对此进行了更改,以允许最终用户将其切换为徽章计数(全局、每个应用程序或完全禁用)。查看三星开发者网站,了解他们具体的启动器更改和谷歌Android Oreo关于如何应用badge Counts的更改Hanks@SushiHangover,你让我走上了正确的轨道,我认为我有一个很好的工作解决方案。我将在下面为其他有同样问题的人发布。
        try
        {
            //This is declared at the class level and initially set to 0
            //Incrementing with each button click
            clickCount++;
    
            int defaults = 0;
            defaults |= (int)NotificationDefaults.Sound;
            defaults |= (int)NotificationDefaults.Lights;
            defaults |= (int)NotificationDefaults.Vibrate;
    
            var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
    
            var chan = new NotificationChannel(CLICKS_CHANNEL, "Button Click", NotificationImportance.Default)
            {
                LockscreenVisibility = NotificationVisibility.Private
            };
    
            notificationManager.CreateNotificationChannel(chan);
    
            var notificationBuilder = new NotificationCompat.Builder(this, CLICKS_CHANNEL)
                .SetAutoCancel(true)
                .SetContentText("You've received new messages.")
                .SetContentTitle("A New Message")
                .SetNumber(clickCount)
                //You need to add a icon to your project and get it here
                .SetSmallIcon(Resource.Drawable.ic_stat_button_click)
                .SetBadgeIconType(NotificationCompat.BadgeIconSmall)
                .SetDefaults(defaults); //.Build();
    
            notificationManager.Notify(0, notificationBuilder.Build());
        }
        catch(System.Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message);
        }
    
    <uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
    <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />