当我的Xamarin表单应用程序运行时,它已经停止了?

发布于 2025-02-12 18:08:01 字数 1654 浏览 2 评论 0 原文

我为Android创建一个以Xamarin形式的空白应用程序。当我在模拟器中运行空白应用程序时,但是当将xamarin.form.googlemaps添加到我的页面并在模拟器显示错误中运行时, 错误消息=“应用程序已停止”
我做了以下操作来添加xamarin.form.googlemaps。

1-从Nuget下载最新版本Xamarin.form.googlemaps。



2-添加 &lt; meta-data android:name =“ com.google.android.maps.v2.api_key” android:value =“我的api键” /&gt; < /code> to androidmanifest.xml > 3-添加我需要的所有许可!许可列表
&lt; use-permission android:name =“ android.permission.access_network_state” /&gt; < /code>


&lt &lt;允许.access_coarse_location“ /&gt; < /code>

&lt; use-permission android:name =“ android.permission.access_fine_location” /&gt; < /code>


&lt; use-permission android:name =“ android.permision.access_location_extra_extra_extra_extra_commands” / &lt;用法permission android:name =“ android.permission.access_mock_location” /&gt; < /code>

&lt; use-permission android:name =“ android.permision.access_wifi_state” &lt; use-permission android:name =“ android.permission.internet” /&gt; < /code>

&lt; use-permission android:name =“ android.permission.write_extern_storage” /&gt; < /code>

4-添加 xmlns:maps =“ clr-namespace:xamarin.forms.googlemaps; assembly = xamarin.forms.googlemaps” 到我的页面
5-

5-



















&lt ;地图:Map verticaloptions =“填充” Morizo​​ntalOptions =“ fill”/&gt;

朋友,我该如何解决关闭该应用程序的问题?

I create a blank app in xamarin form for Android. when i run blank app in emulator thas work exactly, but when add Xamarin.Form.GoogleMaps to my page and run in emulator show error!
error message = "Application has stopped"
I did the following to add Xamarin.Form.GoogleMaps .

1- download latest version Xamarin.Form.GoogleMaps from Nuget.

2- Add
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="my api key" /> to AndroidManifest.xml

3- add all permission i need! list of permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

4- add xmlns:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps" to my page

5- and add <maps:Map VerticalOptions="Fill" HorizontalOptions="Fill"/>

Friends, how can I solve this problem of closing the app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

西瑶 2025-02-19 18:08:01

您缺少Android项目中的插件初始化。

using Xamarin.Forms.GoogleMaps.Android;
namespace App.Droid
{
   public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
       protected override void OnCreate(Bundle savedInstanceState)
       {
            // more stuff here...
            var platformConfig = new PlatformConfig
            {
               BitmapDescriptorFactory = new CachingNativeBitmapDescriptorFactory()
            };
            Xamarin.FormsGoogleMaps.Init(this, savedInstanceState, 
            platformConfig); // initialize for Xamarin.Forms.GoogleMaps
            }
            LoadApplication(new App());
        }
    }
}

You are missing the plugin initialization in the Android project.

using Xamarin.Forms.GoogleMaps.Android;
namespace App.Droid
{
   public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
       protected override void OnCreate(Bundle savedInstanceState)
       {
            // more stuff here...
            var platformConfig = new PlatformConfig
            {
               BitmapDescriptorFactory = new CachingNativeBitmapDescriptorFactory()
            };
            Xamarin.FormsGoogleMaps.Init(this, savedInstanceState, 
            platformConfig); // initialize for Xamarin.Forms.GoogleMaps
            }
            LoadApplication(new App());
        }
    }
}
飘逸的'云 2025-02-19 18:08:01

首先,您可以下载Android Studio并检查模拟器中的日志,以查找出现哪种类型的错误并导致应用程序崩溃。

此外,GitHub中的Nuget软件包已经有一个样本,您是否尝试过?

最后,在第四步中,您不仅需要将这些权限添加到AndroidManifest.xml中,而且还需要用户授予危险的权限,例如自己的位置许可。

因此,您可以根据官方文件进行运行时许可检查并申请许可: https://learn.microsoft.com/en-us/xamarin/android/App-fundamentals/permissions?tabs=windows

At first, you can download the android studio and check the log in the emulator to find what type of error appears and causes the app crash.

In addition, there is already a sample in the github for this nuget package, have you tried that?

Finally, at the 4th step, you not only need to add these permissions into the AndroidManifest.xml, but also need the user to grant the dangerous permissions such as the location permission by himself.

So you can do a run-time permission check and request the permission according to the official document:https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/permissions?tabs=windows
and https://learn.microsoft.com/en-us/xamarin/essentials/permissions?tabs=android

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文