【问题标题】:Unable to start service intent {cmp=insurancereminder.insurancereminder/insurancereminder.ReminderService (has extras) not found无法启动服务意图 {cmp=insurancereminder.insurancereminder/insurancereminder.ReminderService (has extras) not found
【发布时间】:2013-09-30 15:42:56
【问题描述】:

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

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

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

   }
    }

【问题讨论】:

    标签: c# android xamarin.android


    【解决方案1】:

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

    【讨论】:

    • 谢谢 Cheesebaron。我现在创建了一个全新的解决方案,没有手动修改清单文件,我再也看不到这个错误了。如何在下面的通知代码中无法打开内容的 fd:/settings/systems/notifcations_sound。你也可以在这里指导我吗? note.Defaults |= NotificationDefaults.Sound;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-26
    • 2018-12-16
    • 2011-03-27
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多