我正在尝试开发一个提醒应用程序,但是在启动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)
{
}
}
}
}
答案 0 :(得分:1)
您无需手动编辑AndroidManifest.xml
文件。所有内容都应使用[Activity]
,[Intent]
和[Service]
标记进行注册。