Error while installing application in android device

SubramaniamKuppusamySubramaniamKuppusamy Member ✭✭
edited July 2018 in Xamarin.Android

I need to download some files in background for that i used the job service . when i try to deployed the application in android device version 7.0, an error occur saying "There was a problem while parsing the package". Here is my code

    namespace SampleTestApp.Helper
    {
        public class RegisterJobService:Activity
        {
            public static void RegisterJob(Context context)
            {
                try
                {
                    long REFRESH_INTERVAL = 90 * 1000;
                    JobInfo.Builder builder;
                    JobInfo jobInfo;
                    Java.Lang.Class javaClass = Java.Lang.Class.FromType(typeof(BackgroundAgentService));
                    ComponentName component = new ComponentName(context, javaClass);
                    builder = new JobInfo.Builder(0, component).SetPeriodic(REFRESH_INTERVAL);

                    jobInfo = builder.Build();
                    JobScheduler jobScheduler = (JobScheduler)context.GetSystemService(JobSchedulerService);
                    jobScheduler.Schedule(builder.Build());
                }
                catch (System.Exception ex)
                {
                }
            }
        }
    }

Code used For Background Service

    [Service(Name = "SampleTestApp.Helper.BackgroundAgent", Permission = "android.permission.BIND_JOB_SERVICE")]   //  When i remove this line there is no parser error 

public class BackgroundAgentService : JobService

  {
        public override bool OnStartJob(JobParameters @params)
        {
            Log.Debug("BATest", "BackgroundAgentService/OnStartJob");
            return true;
        }
        public override bool OnStopJob(JobParameters @params)
        {

            Log.Debug("BATest", "BackgroundAgentService/OnStop");
            return true;
        }
    }

I found that when i remove this code[Service(Name = "SampleTestApp.Helper.BackgroundAgent", Permission = "android.permission.BIND_JOB_SERVICE")] There is no parser error . And also i have added the permission in manifest file. If i suppose to remove the above line SchelduleJob method, it goes to exception ** Java.Lang.IllegalArgumentException: No such service ComponentInfo**. Anyone have solution for this please?

Answers

  • BillyLiuBillyLiu Member, Xamarin Team Xamurai
    edited July 2018

    @SubramaniamKuppusamy

    If i suppose to remove the above line SchelduleJob method, it goes to exception ** Java.Lang.IllegalArgumentException: No such service ComponentInfo**.

    The code you remove is an Attribute which is used to register the service in the manifest at build time with the necessary XML attribute.

    I found that when i remove this code[Service(Name = "SampleTestApp.Helper.BackgroundAgent", Permission = "android.permission.BIND_JOB_SERVICE")] There is no parser error .

    I have tested your provided code, I could not reproduce your issue. Have you tried to test it on other devices?
    And please provide detail error message?
    You could refer to the following blog for how to use jobservice in xamarin.android:
    https://blog.xamarin.com/replacing-services-jobs-android-oreo-8-0/

  • @BiliLiu

    I am getting error 'There was a problem Parsing the package' when I tried to install the app in Andriod 7.0 and 6.0. But I am able to install it in Android 8.0.

Sign In or Register to comment.