Android 在 Xamarin 中协助 API?

Android Assist API in Xamarin?

你好,我有一个 android 应用程序,它有一个 activity 我想使用辅助 API 所以当用户按住或滑动主页按钮时,它会打开应用

这是我的应用代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace ToolBelt.Droid
{
    [Activity(Label = "ToolBelt")]
    public class ToolBelt : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
        }

//apps main code 

    }


}

这是我的清单:

?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.d4a.toolbelt" android:versionName="1.6" android:installLocation="auto" android:versionCode="6">
        <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" />
        <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
            <activity android:name="com.d4a.toolbelt.ToolBelt" android:launchMode="singleInstance" android:theme="@style/Theme.Transparent">
                <intent-filter>
                    <action android:name="android.intent.extra.ASSIST_PACKAGE" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    </manifest>

该应用程序可以运行,但辅助功能不起作用不知道为什么?

提前致谢

Xamarin.Android 在您构建项目时生成一个新的 AndroidManifest.xml 文件。因此,如果您手动修改该文件,尤其是 <application> 条目,那么它们将被覆盖并且您的手动更改将消失。

所以如果你想给你的 Activity 添加一个 IntentFilter 你需要使用 IntentFilterAttribute 来完成它并用它装饰你的 Activity

XML可以翻译成:

[Activity (LaunchMode = LaunchMode.SingleInstance, Theme = "@style/Theme.Transparent")]
[IntentFilter(new []{Intent.ActionAssist}, Categories = new []{Intent.CategoryDefault})]
public class AssistActivity : Activity
{
}