我正在使用单机器人。当 PACKAGE_REMOVED 操作被捕获时,我不断收到 java.lang.ClassNotFoundException 错误。我在 stackflow 和其他网站上搜索并尝试了很多东西,但无法正常工作。任何帮助,将不胜感激。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly">
<uses-sdk android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/Icon" android:label="App Store">
<receiver android:name=".PackageChangeReceiver" android:exported="true" android:enabled="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="package" />
</intent-filter>
</receiver>
</application>
</manifest>
广播接收器 (PackageChangeReceiver.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.Net;
using System.IO;
using Android.Util;
namespace AppStore
{
[BroadcastReceiver]
public class PackageChangeReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if ("android.intent.action.PACKAGE_REMOVED".Equals(intent.Action))
{
Boolean replacing = intent.GetBooleanExtra(Intent.ExtraReplacing, false);
if (replacing)
{
//do nothing because will be reinstalled again
}
else
{
Intent pushIntent = new Intent(context, typeof(UpdatesService));
pushIntent.PutExtra("appname", intent.Data.ToString());
context.StartService(pushIntent);
}
}
}
}
}