How to solve parse error while installing android app? - xamarin.android

I'm creating an app using Xamarin.Forms .
This app runs correctly on emulator (android version 7.1) in Visual Studio 2017.
But gives "Parse Error : There was problem parsing the package." while installing it on my phone (Android version : 5.1).
Can anyone please help in solving this issue ????
Thanks in advance !!!!
ToastService Class
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;
namespace XamService.Droid.Services
{
[Service(Exported = true , Name = "XamService.ToastService")]
class ToastService : Service
{
public override IBinder OnBind(Intent intent)
{
throw new NotImplementedException();
}
[return: GeneratedEnum]
public override StartCommandResult OnStartCommand(Intent intent, [GeneratedEnum] StartCommandFlags flags, int startId)
{
Toast.MakeText(Android.App.Application.Context, "This is a toast from service !", ToastLength.Long).Show();
return StartCommandResult.Sticky;
}
}
}
ServiceCaller class
using Android.App;
using Android.Content;
using XamService.Interfaces;
using XamService.Droid.Services;
using XamService.Droid;
using Xamarin.Forms;
[assembly:Dependency(typeof(ServiceCaller))]
namespace XamService.Droid
{
class ServiceCaller : Activity, ICaller
{
public void serviceCaller()
{
Intent intent = new Intent(Forms.Context, typeof(ToastService));
Forms.Context.StartService(intent);
}
}
}
AndoridManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.companyname.XamService"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<application android:label="XamService.Android">
<service android:name="ToastService" enabled="true"></service>
</application>
</manifest>

Related

How to write a blank service binary for Windows?

I'm trying to create a service that does absolutely nothing for testing purposes. For that I need a binary that does absolutely nothing but services don't seem to start for just any executable, only ones specifically designed to be service binaries. I've tried to find information as to how to make service binaries but can't seem to find anything. Thanks in advance.
Check out the demo service in this little nuget library:
https://github.com/wolfen351/windows-service-gui
It should give you a good starting point for making a test service to use, it is a trivial implementation of a windows service that does nothing. Also the nuget package will help you run it! :)
Here is the heart of the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
namespace DemoService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
Timer t1 = new Timer(AutoStopCallback, null, 15000, -1); // auto stop in 15 seconds for testing
}
private void AutoStopCallback(object state)
{
Stop();
}
protected override void OnStart(string[] args)
{
Thread.Sleep(2000);
base.OnStart(args);
}
protected override void OnStop()
{
Thread.Sleep(2000);
base.OnStop();
}
protected override void OnContinue()
{
Thread.Sleep(2000);
}
protected override void OnPause()
{
Thread.Sleep(2000);
}
}
}

Xamarin Android app hangs on in splash screen

We are developing a Xamarin Android app using ReactiveUI. Following are the technical specifications,
Visual Studio 2017 15.7.4
Target framework - Mono Android 8.0
NetStandard 2.0
ReactiveUI 8.2
Xamarin Android Support 26.1.1
CompileSdkVersion - API level 26(Android 8.0)
TargetSdkVersion - API level 26(Android 8.0)
MinSdkVersion - API level 19(Android 4.4)
My Project Properties Release Configurations are below.
application
MANIFEST
android options
android_options_advanced
I tested whole development using Huawei API 19(INSTRUCTION SET - armeabi-v8a.) It went ok with debugging and release configurations.
I used custom theme from Theme.appCompat as application theme. And I have styles.xml in values and values-v21 folders. Both same name. I have used a ProcessDialog in Splashing screen which is determined as deprecated. Where is the issue? I am new to Xamarin Android. Thanks in advance.
Update:
Followings is how my MainActivity.cs Looks like.
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Support.Design.Widget;
using Android.Support.V4.View;
using Android.Support.V4.Widget;
using Android.Support.V7.App;
using Android.Util;
using Android.Views;
using Android.Widget;
using DistributrIII.Mobile.Droid.Activities.Errors;
using DistributrIII.Mobile.Droid.Activities.Login;
using DistributrIII.Mobile.Droid.Activities.PointOfSale;
using DistributrIII.Mobile.Droid.Fragments.CloseOfTheDay;
using DistributrIII.Mobile.Droid.Fragments.Common;
using DistributrIII.Mobile.Droid.Fragments.Lossess;
using DistributrIII.Mobile.Droid.Fragments.Orders;
using DistributrIII.Mobile.Droid.Fragments.Outlets;
using DistributrIII.Mobile.Droid.Fragments.PointOfSale;
using DistributrIII.Mobile.Droid.Fragments.Reports;
using DistributrIII.Mobile.Droid.Fragments.SaleOrder;
using DistributrIII.Mobile.Droid.Fragments.PurchaseOrder;
using DistributrIII.Mobile.Droid.Fragments.Settings;
using DistributrIII.Mobile.Droid.Util;
using DistributrIII.Mobile.Lib.Model.Common;
using DistributrIII.Mobile.Lib.Model.Login;
using DistributrIII.Mobile.Lib.Model.Sync;
using DistributrIII.Mobile.Lib.VM.MainActivity;
using DistributrIII.Mobile.Lib.VM.Util;
using Java.Interop;
using Java.IO;
using ReactiveUI;
using System;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using static Android.Support.V7.App.ActionBar;
using static Android.Support.V7.Widget.SearchView;
using Environment = Android.OS.Environment;
using SearchView = Android.Support.V7.Widget.SearchView;
using DistributrIII.Mobile.Droid.Fragments.OpenTransactions;
namespace DistributrIII.Mobile.Droid
{
[Activity(Label = "DistributrIII", MainLauncher = false, Theme = "#style/MainTheme")]
public class MainActivity : DistributrBaseActivity<MainActivityVM>
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
SetupUI(savedInstanceState);
}
#region UI Components
DrawerLayout drawerLayout;
NavigationView navigationView;
IMenuItem previousItem;
Android.Support.V7.Widget.Toolbar toolbar;
DisplayScreen PreviousMenuItemId = DisplayScreen.None;
SearchView searchControl;
ProgressDialog progress;
#endregion
#region UI Helper Methods
public override bool OnCreateOptionsMenu(IMenu menu)
{
return base.OnPrepareOptionsMenu(menu);
}
private void SetupUI(Bundle savedInstanceState) {
toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
toolbar.InflateMenu(Resource.Menu.main_menu);
searchControl = (SearchView)toolbar.Menu.FindItem(Resource.Id.distributr_search).ActionView ;
var textChangedObservable =
Observable
.FromEventPattern<QueryTextChangeEventArgs>(
x => searchControl.QueryTextChange += x,
x => searchControl.QueryTextChange -= x)
.Select(x => x.EventArgs.NewText)
.Throttle(TimeSpan.FromSeconds(1), TaskPoolScheduler.Default);
var querySubmitObservable =
Observable
.FromEventPattern<QueryTextSubmitEventArgs>(
x => searchControl.QueryTextSubmit += x,
x => searchControl.QueryTextSubmit -= x)
.Select(x => x.EventArgs.Query);
SubscriptionDisposables.Add(
Observable
.Merge(textChangedObservable, querySubmitObservable)
.Subscribe(async searchText => this.HandleSearch(searchText))
);
SetupNavigation(savedInstanceState);
BottomNavigationView navigationView = (BottomNavigationView)FindViewById(Resource.Id.bottom_navigation);
if (DIIIStaticStorage.LoginAccountType == LoginAccountType.Customer)
{
navigationView.InflateMenu(Resource.Menu.nav_bottom_customr);
}
else
{
navigationView.InflateMenu(Resource.Menu.nav_bottom);
}
navigationView.NavigationItemSelected += BottomNavigation_NavigationItemSelected;
Android.Support.Design.Internal.BottomNavigationMenuView menuView = (Android.Support.Design.Internal.BottomNavigationMenuView)navigationView.GetChildAt(0);
for (int i = 0; i < menuView.ChildCount; i++)
{
Android.Support.Design.Internal.BottomNavigationItemView itemView = (Android.Support.Design.Internal.BottomNavigationItemView)menuView.GetChildAt(i);
itemView.SetShiftingMode(false);
itemView.SetChecked(false);
}
//InvalidateOptionsMenu();
toolbar.Title = "Distributr";
}
}
I observed this stuck in debug mode also with some devices.log can someone show me whats the error.Thanks again

Unable to generate path to save image in iOS

I created a delegate on iOS (it works on Android) to save an image using the CrossDownloadManager plugin. I copied the code from the Xamarin documentation but when I run the method, "path" returns an empty string:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YHTS.iOS;
using Foundation;
using UIKit;
using System.IO;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: Dependency(typeof(ImageSaver_IOS))]
namespace YHTS.iOS
{
public class ImageSaver_IOS : IImageSaver
{
public ImageSaver_IOS() { }
public string Save(string imageName)
{
string fileName = (new NSUrl(imageName, false)).LastPathComponent;
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
return path;
}
}
}

How to detect IIS events in windows event logs and detemine its application pool according to this code?

I try to make a listener on windows event logs, but I need to recognize IIS events in it and determine its application pool.
could I do that according to this code ??? by process id for example or any thing else.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.DirectoryServices;
using Microsoft.Web;
using Microsoft.Web.Administration;
namespace EventLogEnt
{
class Program
{
static AutoResetEvent signal;
static void Main(string[] args)
{
// create new log
signal = new AutoResetEvent(false);
EventLog myNewLog = new EventLog("Application", "TIS3", "Outlook");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
myNewLog.WriteEntry("Test message", EventLogEntryType.Information);
signal.WaitOne();
Console.ReadKey();
}
public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
{
Console.WriteLine(e.Entry.Message);
Console.WriteLine("the entry type: " + e.Entry.EntryType);
Console.WriteLine("---------------------------------------------");
signal.Set();
}
}
}

Geolocation dont work on a desktop emulator (uwp)

Hello im trying to make a view containing a map in a Universal Windows platform
i did the fellowing :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Geolocation;
namespace Project
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Geolocation : Page
{
public Geolocation()
{
this.InitializeComponent();
}
public async void GetCords()
{
Geolocator locator = new Geolocator();
Geoposition pos = await locator.GetGeopositionAsync();
await new Windows.UI.Popups.MessageDialog(pos.CivicAddress.City).ShowAsync();
}
}
}
but i got a blank page! what am I missing here?
If you want to add a MapControl in your page, you must:
Create a key for your map
xmlns:maps="using:Windows.UI.Xaml.Controls.Maps <maps:MapControl
<maps:MapControl x:Name="map" MapServiceToken="YOUR_TOKEN_HERE" />

Resources