0

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

清单.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>

WakeReminderIntentService.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();
        }
    }
   }
  }

OnAlramReceive.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)
        {
        }
    }

   }
    }
4

1 回答 1

1

您无需手动编辑AndroidManifest.xml文件。一切都应该用[Activity],[Intent][Service]标志注册。

于 2013-09-30T07:42:56.440 回答