android - 通过数据链接打开 MvvmCross 应用程序

标签 android android-intent xamarin mvvmcross intentfilter

在 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/

相关文章:

android - 使用 ACTION_GET_CONTENT 和 setType 或 Intent.EXTRA_MIME_TYPES 选择特定文件类型

c# - 如何使用 Embeddinator-4000 创建 .aar 文件

android - 什么时候 Intent 额外在 Activity 之间变为空?

android - 加载文本时,Android EditText 会成为 XSS 的目标吗?

android - 在运行时将 edittext 更改为下拉列表的方法?

java - 定义一个与 scala 中的类同名的方法是否安全?

android - Titanium android 对特定应用程序的外部 Intent

c# - 如何使用 android 在 Xamarin 中获取根布局?

xamarin - Xamarin iOS 构建的 DevOps CI 错误 在钥匙串(keychain)中找不到有效的 iOS 代码签名 key

android - GridView 与 TableLayout |安卓