![](/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.