简体   繁体   中英

monodroid receiver PACKAGE_REMOVED java.lang.ClassNotFoundException

I am using monodroid. I keep receiving java.lang.ClassNotFoundException error when the PACKAGE_REMOVED action is trapped. I have searched and attempted many things on stackflow and other sites, but can not get this working. Any help would be appreciated.

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>

Broadcast Receiver (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);  
            }
        }
    }
}
}

I Contacted Xamarin ( Monodroid ) directly. It seems my mistake was in editing the manifest manually. I had done a web search looking for solutions and added entries to the manifest. However, this did not connect with the monodroid code. Since monodroid autobuilds the manifest, you have to use attributes on the broadcast receiver like so:

[BroadcastReceiver] 
[IntentFilter(new string[] { Intent.ActionPackageRemoved }, Priority = (int)IntentFilterPriority.HighPriority, DataScheme="package")] 
public class PackageChangeReceiver : BroadcastReceiver 
{

Hope this helps others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM