Hi, I´ve started recently with Xamarin and I´m trying to generate an .apk using Xamarin Studio using Android that it checks an ip address and in this address check an .txt file with versión data of the .apk if the .apk in my server is bigger then it must be reinstall the new version in the android phone. It´s going to be a .apk for internal use (we don´t want to use Play store) for scanning a delivery document (this phone has one scanner), take a photo with the signature of the transport company driver.
My first problem is than when I´m checking the .apk in the android mobile android gives me an error (Parse error) : There is a problem parsing the package.
But I don´t know if the problem cames from my code in C# with Xamarin of it´s a problem with android´s grants.
Grants that I have used it:
- ACCESS_NETWORK_STATE
- CAMERA
- INSTALL_PACKAGES
- INTERNET
- WRITE_EXTERLNAL_STORAGE
I have been reading this links:
http://stackoverflow.com/questions/4967669/android-install-apk-programmatically
http://stackoverflow.com/questions/23309080/android-file-path-xamarin
http://stackoverflow.com/questions/18871203/android-install-apk-intent-monodroid
https://forums.xamarin.com/discussion/15658/xamarin-android-app-autoupdate
http://stackoverflow.com/questions/4967669/android-install-apk-programmatically
http://stackoverflow.com/questions/23870712/install-apk-from-runtime-using-xamarin
http://stackoverflow.com/questions/4835925/unsigned-apk-can-not-be-installed
http://stackoverflow.com/questions/13808845/how-to-programmatically-install-apk-with-monodroid
http://www.itrickbuzz.com/there-is-a-problem-parsing-the-package-error-android/
Any help or advise ???? Thanks in advance.
My code:
SplahScreen
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Java.IO;
using System.Net.NetworkInformation;
using Android.Util;
namespace MovilLogistica.Screens
{
[Activity(Label = "MovilLogistica", MainLauncher = true, NoHistory = true, Theme =
"@style/Theme.Splash", Icon = "@drawable/icon")]
public class SplashScreen : Activity
{
File apkFile;
Intent intent;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.Splash);
//Check Ip address
int timeout = 100;
Ping ping = new Ping();
PingReply reply = ping.Send("192.230.3.182", timeout);
if (reply != null && reply.Status == IPStatus.Success)
Log.Info("PRUEBA IP", reply.RoundtripTime.ToString());
if (reply != null && reply.Status == IPStatus.TimedOut)
Log.Info("PRUEBA IP", reply.RoundtripTime.ToString());
//Install .apk
apkFile = new File("192.230.3.182/Instalac/MovilLogistica.MovilLogistica.apk");
intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Android.Net.Uri.FromFile(apkFile), "application/vnd.android.package-archive");
//intent.SetFlags(ActivityFlags.NewTask);
StartActivity(intent);
Thread.Sleep(4000);
StartActivity(typeof(MainScreen));
}
}
}