安装Android应用程序时如何解决解析错误?

时间:2018-05-01 04:06:51

标签: xamarin.android

我正在使用Xamarin.Forms创建一个应用程序。 此应用程序在Visual Studio 2017中的模拟器(Android版本7.1)上正确运行。 但是给出了“解析错误:解析包时出现问题”。在我的手机上安装它(Android版本:5.1)。 任何人都可以帮助解决这个问题???? 在此先感谢!!!!

ToastService类

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 XamService.Droid.Services
{
    [Service(Exported = true , Name = "XamService.ToastService")]
    class ToastService : Service
    {
        public override IBinder OnBind(Intent intent)
        {
            throw new NotImplementedException();
        }

        [return: GeneratedEnum]
        public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
        {
            Toast.MakeText(Android.App.Application.Context, "This is a toast from service !", ToastLength.Long).Show();
            return StartCommandResult.Sticky;
        }

    }
}

ServiceCaller类

using Android.App;
using Android.Content;
using XamService.Interfaces;
using XamService.Droid.Services;
using XamService.Droid;
using Xamarin.Forms;

[assembly:Dependency(typeof(ServiceCaller))]
namespace XamService.Droid
{
    class ServiceCaller : Activity, ICaller
    {
        public void serviceCaller()
        {
            Intent intent = new Intent(Forms.Context, typeof(ToastService));
            Forms.Context.StartService(intent);
        }
    }
}

AndoridManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          android:versionCode="1" 
          android:versionName="1.0" 
          package="com.companyname.XamService" 
          android:installLocation="auto">
    <uses-sdk android:minSdkVersion="15" />
    <application android:label="XamService.Android">
        <service android:name="ToastService" enabled="true"></service>
    </application>
</manifest>

enter image description here

enter image description here

0 个答案:

没有答案