android - 为什么要使用 Intent.URI_INTENT_SCHEME

标签 android android-intent

在阅读有关小部件的 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/

相关文章:

android - 使用 Android NDK 进行原生游戏开发推荐使用哪个操作系统平台?

android - 在 Android 中使用数据报的简单网络

android - SupportMapFragment 在 Android 4.1+ 上因 NullPointerException 而崩溃

android - 将多个 subview 添加到父 View

安卓分享图片不工作

java - 如何检查java中的不同类中是否单击了按钮?

android - Android onTouchEvent MotionEvent 中的坐标是如何基于的?

android - Flutter 中的 Agora-在视频聊天中禁用一个人的视频并让另一个人的视频全屏

android - 如何实时查看Android APP的后台堆栈?

java - Android - 无法通过 fragment 中的 Intent 启动 Activity