gpt4 book ai didi

android - RemoteViewsFactory grantUriPermission 获取数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:31:55 25 4
gpt4 key购买 nike

有一个带有 Listview 的 AppWidget,我想用 RemoteViewsService.RemoteViewsFactory 填充它。

我有以下错误

E/AndroidRuntime(1203): java.lang.SecurityException: Permission Denial: reading com.crbin1.myapp.data.ProviderLTD uri content://com.crbin1.myapp.data.ProviderLTD/TB_WIDGET3P from pid=413, uid=10013 requires the provider be exported, or grantUriPermission()

如果我在 list 中导出 ProviderLTD(我的内容提供商),它会起作用,但我想避免导出它。

另一个解决方案是 grantUriPermission()。我在 list 中将 grantUriPermissions 设置为 true,但现在我不明白我必须在我的代码中的哪个位置授予权限。

public class Widget3pService extends RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new StackRemoteViewsFactory(this.getApplicationContext(), intent);
}
}


class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private List<ObjW3Task> mWidgetItems = new ArrayList<ObjW3Task>();
private Context mContext;
private int mAppWidgetId;

public StackRemoteViewsFactory(Context context, Intent intent) {
mContext = context;
mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}

public RemoteViews getViewAt(int position) {
// use mWidgetItems to populate ListView
// fillInIntent for listeners
return myRemoteViews;
}

public void onDataSetChanged() {
mWidgetItems = new ArrayList<ObjW3Task>();
// create mWidgetItems by accessing my ContentProvider class
}
}

最佳答案

不确定这是否仍然相关;通过设置“android:exported = true”,我发现它对我有效:

<provider android:name="WeatherDataProvider" android:exported="true">

看这个: Android Permission denial in Widget RemoteViewsFactory for Content

关于android - RemoteViewsFactory grantUriPermission 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17649544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com