无法启动服务意图 {cmp=保险提醒.保险提醒/保险提醒.未找到提醒服务(有附加功能)

本文关键字:保险 服务 功能 cmp 意图 启动 | 更新日期: 2023-09-27 18:33:13

我正在尝试开发提醒应用程序,但在启动意图服务时遇到问题,我在清单中添加了所需的标记.xml但仍然收到错误无法启动服务意图 {cmp=保险提醒.保险提醒/保险提醒。未找到提醒服务(有附加功能)。有人可以帮助解决这个问题吗?

清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
 android:installLocation="auto">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<application>
    <activity android:name=".MainScreen" android:debuggable="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER"  
                />
        </intent-filter>
    </activity>
    <activity android:name=".AddNewReminder" android:label="Edit Activity" />
    <receiver android:name=".OnAlarmReceiver" />
   <service android:enabled="true" android:name=".ReminderService"></service>
    <activity android:name=".TaskPreferences" android:label="app_name" />
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
   </manifest>

唤醒提醒意图服务.cs

   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;
  using System.Runtime.CompilerServices;
namespace InsuranceReminder
{
public abstract class WakeReminderIntentService : IntentService
{
    internal abstract void doReminderWork(Intent intent);
    public const string LOCK_NAME_STATIC = "InsuranceReminder.Static";
    private static PowerManager.WakeLock lockStatic = null;
    public static void acquireStaticLock(Context context)
    {
        try
        {
            getLock(context).Acquire();
        }
        catch (Exception ex)
        {
        }
    }
    [MethodImpl(MethodImplOptions.Synchronized)]
    private static PowerManager.WakeLock getLock(Context context)
    {
        if (lockStatic == null)
        {
            PowerManager mgr = 
     (PowerManager)context.GetSystemService(Context.PowerService);
            lockStatic = mgr.NewWakeLock(WakeLockFlags.Partial, LOCK_NAME_STATIC);
            lockStatic.SetReferenceCounted(true);
        }
        return (lockStatic);
    }
    public WakeReminderIntentService()
        : base("WakeReminderIntentService")
    {
    }
    public WakeReminderIntentService(String name) : base(name)
    {
    }

    protected override void OnHandleIntent(Intent intent)
    {
        try
        {
            doReminderWork(intent);
        }
        finally
        {
            getLock(this).Release();
        }
    }
   }
  }

OnAlaramReceive.cs

     using System;
    using System.Collectons.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 InsuranceReminder
    {
    [BroadcastReceiver]
    public class OnAlarmReceiver : BroadcastReceiver
    {
    public override void OnReceive(Context context, Intent intent)
    {
        try
        {
            Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
            long rowid = intent.Extras.GetLong(SQLiteHelper.Column_id);
            WakeReminderIntentService.acquireStaticLock(context);
            Intent i = new Intent(context, typeof(ReminderService));
            i.PutExtra(SQLiteHelper.Column_id, rowid);
            context.StartService(i);
        }
        catch (Exception ex)
        {
        }
    }
   }
    }

无法启动服务意图 {cmp=保险提醒.保险提醒/保险提醒.未找到提醒服务(有附加功能)

您无需手动编辑AndroidManifest.xml文件。所有内容都应注册[Activity][Intent][Service]标志。