【问题标题】:Mono for Android, How to make an intent that passes dataMono for Android,如何制作传递数据的意图
【发布时间】:2012-02-11 08:30:45
【问题描述】:

我对 android 很陌生,我在 .NET 中编码已经有几年了 我正在尝试创建一个应用程序,该应用程序将启动另一个应用程序,同时将一些数据传递给它。 我一直在和另一个应用程序的开发人员聊天,他说

Following is what I wrote in the AndroidManifest.xml:

         <activity android:name=".EmulatorActivity"
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
                <data android:mimeType="application/x-n64-rom" />
            </intent-filter>
        </activity>

You should set the Intent URL to something like 'file://path/rom_file', and set its mime type to 'application-x-n64-rom'.

虽然我不知道该怎么做,但我可以使用成功启动他的应用程序

Intent intent = new Intent(Intent.ActionMain);
            intent.SetComponent(new ComponentName("com.androidemu.n64", "com.androidemu.n64.MainActivity"));
            intent.SetFlags(ActivityFlags.NewTask);
            StartActivity(intent);

但是如果我将 ActionMain 更改为 ActionView 并将 MainActivity 更改为 EmulatorActivity 它会尝试启动但崩溃 我也不知道如何传递变量:) 我尝试了很多组合,但知道我哪里出错了 我要传递的文件名位于 sd 卡调用 n64.zip 的根目录上

我试过了 intent.PutExtra(Intent.ExtraStream, Android.Net.Uri.Parse("file://sdcard/n64.zip"));

谢谢

学习

【问题讨论】:

    标签: android android-intent xamarin.android


    【解决方案1】:

    您可以试试这个,看看它是否有效:

    Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
    myIntent.setDataAndType(Uri.fromFile("filepath"), "application/x-n64-rom");
    startActivity(myIntent);
    

    【讨论】:

    • Android.Net.Uri.FromFile 没有过载需要 2 个参数
    【解决方案2】:

    需要更多信息。它在哪里崩溃?

    Intent 的构造函数应该是 new Intent(Intent.ACTION_MAIN)。我不知道 Intent.ActionMain 是什么,除非它是您正在使用的开发环境的一部分。

    你不能随意改变intent.SetComponent()。组件包和类名必须 与其他活动完全匹配。

    【讨论】:

    • 我正在使用 Mono for Android,它的 def Intent.ActionMain 但我假设它对应于 ACTION_MAIN。我的应用程序没有崩溃,而是我尝试启动的应用程序出现然后立即崩溃。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 2012-07-25
    • 2012-11-08
    • 2017-11-06
    • 1970-01-01
    • 2015-04-16
    相关资源
    最近更新 更多