Forum Xamarin.Android

"Problem while parsing the package" error trying run apk installation from code.

Hi ,
I have the same problem as many another ppl: "There was a problem while parsing the package." when I try to install package from app. Package installs from Download folder without problem, reinstall from this folder works as well. But start installation from app gives error. Googling for three days without result.

Code is:

    Intent intent = new Intent(Intent.ActionView);
    string fileApk = "com.packagename.apk";

    Java.IO.File file = new Java.IO.File(Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath.ToString(), fileApk));
`//file = {/storage/emulated/0/Download/com.packagename.apk}`

      Android.Net.Uri uri = FileProvider.GetUriForFile(Android.App.Application.Context, "com.packagename.provider", file);
`//uri = {content://com.packagename.provider/ex_storage/Download/com.packagename.apk} `



    intent.SetDataAndType(uri, "application/");



<manifest xmlns:android="" android:versionCode="2" android:versionName="2.0" package="com.packagename" android:installLocation="preferExternal">
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="24" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application android:label="Application" android:icon="@drawable/icon48">
        <provider android:name="" android:authorities="com.packagename.provider" android:exported="false" android:grantUriPermissions="true">
            <meta-data android:name="" android:resource="@xml/provider_path" />


<paths xmlns:android="">
             <external-path path="." name="ex_storage" />


  • BillyLiuBillyLiu Member, Xamarin Team Xamurai


    Please try to use following code to install the apk:

            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            Intent intent = new Intent(Intent.ActionView);
            intent.SetDataAndType(Uri.FromFile(new File(Environment.ExternalStorageDirectory + "/download/" + "test.apk")), "application/");

    You could refer to the following links for more detail:

  • JustAlexJustAlex Member ✭✭

    @BillyLiu Thank you trying to help. Your proposed code will not work for for SDKversion >22 (method Uri.FromFile). Should use FileProvider.
    I resolved my problem after phone factory reset only. I do not know why, but one of my app's version did not uninstall correctly. Even with adb I could not uninstall it. So, the way only was to reset my phone. Now all is OK. Tnx.

  • edcsuscribedcsuscrib Member

    I have the same problem and can't get it to work.

    The file that is downloaded by system and that would be the update of the app, if I execute it manually it works, if I execute it from the same app it does not work.

    Any ideas?

Sign In or Register to comment.