我有一个应用程序,它在应用图标上的小红点上显示通知号。这在所有型号上都很好,三星Galaxy S9除外。我尝试过许多解决方案,但总是会出错。
权限拒绝:从com.sec.android.provider.badge.permission.WRITE,编写com.sec.android.provider.badge.BadgeProvider uri内容://com.sec.徽章/应用程序,uid=10233需要pid=32464或grantUriPermission()
该项目是VisualStudio2017中的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" />The C#
try
{
var context = Android.App.Application.Context;
// This is the content uri for the BadgeProvider
var uriPath = "content://com.sec.badge/apps"; //"com.sec.android.app.launcher";
Android.Net.Uri uri = Android.Net.Uri.Parse(uriPath); //new Uri("content://com.sec.badge/apps");
ICursor cursor = context.ContentResolver.Query(uri, new string[] { "_id" }, "package=?", new string[] { context.PackageName }, null);
if (cursor == null || !cursor.MoveToFirst())
{
ContentValues cv = new ContentValues();
cv.Put("package", context.PackageName);
cv.Put("class", context.PackageManager.GetLaunchIntentForPackage(context.PackageName).Component.ClassName);
cv.Put("badgecount", count);
context.ContentResolver.Insert(uri, cv); //Errors here
}
else
{
int idColumnIndex = cursor.GetColumnIndex("_id");
ContentValues cv = new ContentValues();
cv.Put("badgecount", count);
context.ContentResolver.Update(uri, cv, "_id=?", new string[] { cursor.GetInt(idColumnIndex).ToString() });
}
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}就像我说的,这一切对早期的模型都很好,但是对于新的模型却是错误的。是否有需要添加到权限中的内容,还是我缺少了其他内容?
发布于 2018-07-20 13:39:48
我已经解决了我的问题。现在,您需要将NotificationChannel与您的NotificationManager结合使用。我用一个按钮创建了一个小测试应用程序。在按钮单击中,我调用下面的代码。我还没有把它移到我的实时应用程序中,但是它在这个测试应用程序中运行得很好。
首先,为NotificationChannel的id参数添加一个const。
public const string CLICKS_CHANNEL = "com.yourcompany.SamsungBadgeTest.clicks";现在:
别忘了把这个加到你的声明里
<uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />https://stackoverflow.com/questions/51431348
复制相似问题