在阅读有关小部件的 Android 文档时,我偶然发现了这段代码,其目的是启动一项服务来检索 StackView 项目的工厂。
// Set up the intent that starts the StackViewService, which will
// provide the views for this collection.
Intent intent = new Intent(context, StackWidgetService.class);
// Add the app widget ID to the intent extras.
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
// Instantiate the RemoteViews object for the App Widget layout.
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
// Set up the RemoteViews object to use a RemoteViews adapter.
// This adapter connects
// to a RemoteViewsService through the specified intent.
// This is how you populate the data.
rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);
你可以找到它here
我无法理解你为什么需要打电话
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
我理解它给 URI 一个前缀intent://,但是这里有必要吗?
最佳答案
这很容易。
简介:如果不使用:如果您不使用 setData,它将为小部件的所有实例显示相同的 ID。
关于android - 为什么要使用 Intent.URI_INTENT_SCHEME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13688138/