android - 如何使用 Xamarin android 打开另一个带有 onclick 监听器的已安装应用程序

标签 android xamarin xamarin.android

您好,我正在开发一个应用程序,该应用程序有一个分配给它的 onclick 值的按钮我的问题是如何打开另一个我已经安装在设备上的应用程序我知道如何在 java 中执行此操作但需要知道如何在 Xamarin 中做到这一点

这是我的按钮布局代码:

<Button
            android:text="Tools"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button1"
            android:onClick="tools" />

这是我的按钮的 C# 代码:

 //Code That Opens The Tools App!

    [Java.Interop.Export("tools")] // The value found in android:onClick attribute.
    public void btnOneClick2(View v) // Does not need to match value in above attribute.
    {
        var intent = new Intent(Android.Content.Intent.ActionSend);
        var uri = Android.Net.Uri.Parse("com.d4a.toolbelt");
        StartActivity(intent);
    }

com.d4a.toolbelt 是我要打开的应用程序的包名称。

任何帮助都会很棒!

提前致谢

最佳答案

您可以使用 PackageManager:

Intent i;
PackageManager manager = PackageManager;
try {
    i = manager.GetLaunchIntentForPackage("com.d4a.toolbelt");
    if (i == null)
        throw new PackageManager.NameNotFoundException();
    i.AddCategory(Intent.CategoryLauncher);
    StartActivity(i);
} catch (PackageManager.NameNotFoundException e) {

}

关于android - 如何使用 Xamarin android 打开另一个带有 onclick 监听器的已安装应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32056958/

相关文章:

android - sqlite数据库没有得到更新

java - Android,创建自定义 ImageView 形状

Android Studio 运行/调试配置错误 : Module not specified

xamarin - 对于 Xamarin Forms 应用程序,我应该如何决定 App 构造函数或 OnStart() 中的内容?

c# - Xamarin SimpleAudioPlayer返回System.NullReferenceException

android - CheckBoxPreference .isChecked() 返回相反的值

c# - Xamarin iOS - Mapkit ArgumentNullException : Value cannot be null

.net - “System.ComponentModel.DataAnnotations.dll”可用于 Android 和 iOS 吗?

exception - 如何解决ResolveLibraryProjectImports“任务意外失败异常

android - Webview 不是每次都加载