Xamarin Android app hangs on in splash screen - xamarin.android

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

Related

How to solve parse error while installing android app?

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>

Xamarin.Forms Bluetooth Interface choices

I am attempting to write dependency injection methods, with an interface, so that I would be able to really have a single user interface for both Android and UWP.
Processing and testing one feature at a time. The schema is working, but my problem is that on the UWP side, most functions are asynchrone, while they are not on Android.
So my question is, should I "fake" async functions on the android side, and if yes, how?
Here is my example:
using System.Collections.Generic;
using System.Threading.Tasks;
namespace XamarinBTArduinoLed
{
public interface IBlueTooth
{
// as a first test, I will try to get a list of paired devices in both Android and UWP
List<string> PairedDevices();
}
}
This works with Android, but for UWP, it would need to be
public interface IBlueTooth
{
// as a first test, I will try to get a list of paired devices in both Android and UWP
Task<List<string>> PairedDevices();
}
Which does not work for my current Android implementation. So, how should I modify this, to "fake" an asynchrone method, assuming it would be the best choice? Or is there any other way I am not thinking about?
[assembly: Xamarin.Forms.Dependency(typeof(XamarinBTArduinoLed.Droid.BlueToothInterface))]
namespace XamarinBTArduinoLed.Droid
{
public class BlueToothInterface : IBlueTooth
{
public List<string> PairedDevices()
{
List<string> BTItems = new List<string>();
BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
if (adapter == null) throw new Exception("No BlueTooth Adapter Found.");
if (!adapter.IsEnabled)
{
adapter.Enable();
}
//if (!adapter.IsEnabled)
//{
// throw new Exception("BlueTooth adapter is NOT enabled.");
//}
foreach (var item in adapter.BondedDevices)
{
BTItems.Add(item.Name + " - " + item.Type.ToString());
}
return BTItems;
}
}
}
I found what seems to be the best way to go:
-1- I changed the interface to get a Task returned:
public interface IBlueTooth
{
// as a first test, I will try to get a list of paired devices in both Android and UWP
Task<List<string>> PairedDevices();
}
-2- I modified the Android implementation accordingly:
public Task<List<string>> PairedDevices()
{
List<string> BTItems = new List<string>();
BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
if (adapter == null) throw new Exception("No BlueTooth Adapter Found.");
if (!adapter.IsEnabled)
{
adapter.Enable();
}
var t = Task.Factory.StartNew(() =>
{
foreach (var item in adapter.BondedDevices)
{
BTItems.Add(item.Name);
}
return BTItems;
});
return t;
}
-3- I implemented INotifyPropertyChanged to display in XAML
This is now working perfectly, I get my list of USB/Serial devices from both Android and Windows UWP. Will certainly take a while to create the whole process for both platforms, but at least it looks like I am on a good start.
Don't hesitate if you have any comments, recommendations,maybe a better way.....

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" />

Change Switch Color in Xamarin.Forms?

I want to change the color of switch in android and created custom renderer just like as one of the post from stack overflow:
Below is the code
public class CustomSwitchRenderer : SwitchRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.TextOn = "Yes";
Control.TextOff = "No";
Android.Graphics.Color colorOn = Android.Graphics.Color.Rgb(239, 201, 6);
Android.Graphics.Color colorOff = Android.Graphics.Color.LightGray;
Android.Graphics.Color colorDisabled = Android.Graphics.Color.Gray;
Android.Graphics.Color textColor = Android.Graphics.Color.Black;
Control.SetTextColor (ColorStateList.ValueOf (textColor));
Control.SetTextColor (textColor);
StateListDrawable drawable = new StateListDrawable();
drawable.AddState(new int[] { Android.Resource.Attribute.StateChecked }, new ColorDrawable(colorOn));
drawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, new ColorDrawable(colorDisabled));
drawable.AddState(new int[] { }, new ColorDrawable(colorOff));
Control.ThumbDrawable = drawable;
}
}
}
This code isn't working for me ? Do i need to add some items in drawable folder as well ?
With Forms 2.1, there are now effects which can remove the need for a custom renderer in situations where only minor visual changes are being made. See the linked guide for getting started on using them.
You can create your own control in your UI project:
public class MySwitch : Switch
{
}
After that change your forms where you used Switch control to MySwitch control.
And then you need to tell Xamarin.Forms infrastructure that you are providing renderer for MySwitch control.
In your *.Droid project add following attribute at assembly level (above your namespace declaration or in AssemblyInfo.cs file)
[assembly: ExportRenderer(typeof(MySwitch), typeof(CustomSwitchRenderer))]
For Android you can change the propery "colorAccent" on your "styles.xml" file
<item name="colorAccent">#008000</item>

Resources