![](/img/trans.png)
[英]java.lang.RuntimeException and java.lang.classNotFoundException
[英]monodroid receiver PACKAGE_REMOVED java.lang.ClassNotFoundException
我正在使用monodroid。 捕获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);
}
}
}
}
}
我直接联系Xamarin(Monodroid)。 看来我的错误在于手动编辑清单。 我进行了一次网络搜索以寻找解决方案,并在清单中添加了条目。 但是,这与monodroid代码无关。 由于monodroid自动构建清单,因此您必须像下面这样在广播接收器上使用属性:
[BroadcastReceiver]
[IntentFilter(new string[] { Intent.ActionPackageRemoved }, Priority = (int)IntentFilterPriority.HighPriority, DataScheme="package")]
public class PackageChangeReceiver : BroadcastReceiver
{
希望这对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.