在 native Android 应用中,您可以为 Manifest 文件中的 Activity 定义一个 intent-filter
,当特定链接(例如 myprotocol://mysite.com/操作/数据
)是通过网站或电子邮件访问的。
<intent-filter>
<data android:scheme="myprotocol" android:host="mysite.com"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
当我尝试将其添加到 MvvmCross 应用程序中的 AndroidManifest 文件时,似乎只加载了 View ,而没有链接到它的 ViewModel。我似乎找不到任何有关如何加载 ViewModel 并获取我的 Intent 数据(网址的 data
部分)的信息。
以前有人这样做过吗?
最佳答案
我有一个可以响应扫描 NFC 标签的应用程序,我也有类似的情况。
我的解决方案是在调用 base.OnCreate(bundle)
之后立即在我的 OnCreate
覆盖中添加以下内容:
if (null == ViewModel)
{
//This should only happen when the Intent is not an Mvx one. I.e. when having scanned
//NFC tag. We need to load the ViewModel manually.
var loaderService = Mvx.Resolve<IMvxViewModelLoader>();
ViewModel = (ScanViewModel) loaderService.LoadViewModel(
new MvxViewModelRequest(typeof (ScanViewModel), null, null, null), null);
}
正如评论所说,该 Intent 不是来自 MvvmCross。这意味着告诉 MvvmCross 要加载哪个 ViewModel 的包不存在。所以我所做的就是自己创建 ViewModel。
关于android - 通过数据链接打开 MvvmCross 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35288628/