SocketException: "access denied" while opening port using UdpClient - c#

I'm trying to start listening on one of UDP ports on Android device. I'm using Xamarin.Forms and I'm testing it on physical android phone.
public void StartListening(int port = 13000)
{
ListenerPort = port;
udpClient = new UdpClient(ListenerPort);
udpClient.BeginReceive(new AsyncCallback(handleIncomingMessages), null);
}
This function is being used on application start:
public partial class App : Application
{
[...]
protected override void OnStart()
{
network.StartListening(LISTENING_ON_PORT);
}
}
The are many similar questions on SO, but most of them were solved by adding INTERNET permission to android manifest. Here is mine:
AndroidManifest.xml
<?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.ddand">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="ddAnd.Android" android:theme="#style/MainTheme"></application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
</manifest>
What I see after deploying my app is:
System.Net.Sockets.SocketException: 'Access denied'
and no other details provided.
I've thought my port is being used by another process, but I've check many of them (outside of 1-1024 range) and using all of them gave the same results.
Are there any other reasons for this exception? Do you have any ideas how can I throubleshoot the problem (e.g. how to find available port)?
EDIT:
As suggested in comments, I tried to gain access at runtime (though it should not be necessary, INTERNET permission is granted by default by Xamarin in Debug mode).
This line returns information that permission is granted.
var havePermission = ContextCompat.CheckSelfPermission(this, Manifest.Permission.Internet);
Nevertheless I tried to manually get access at runtime
ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Internet }, 1);
Result is the same as before.

Can you try with the following code? (adapted from the documentation)
public void StartListening(int port = 13000)
{
ListenerPort = port;
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, ListenerPort);
udpClient = new UdpClient(ipEndPoint);
UdpState udpState = new UdpState();
udpState.e = ipEndPoint;
udpState.u = udpClient;
udpState.BeginReceive(new AsyncCallback(handleIncomingMessages), udpState);
}

Related

Directory.GetFiles does not return files copied from a computer (Android MAUI)

I'm developing an app in VS MAUI which is supposed to handle files and subfolders in the Download folder (external card) on an Android. The phones File Manager app reports 3 files in the folder, but my app lists only 1.
var f1 = Directory.GetFiles("/storage/8186-1418/Download");
The listed file has been created by the app itself, using File.WriteAllText, so I know I have access to the folder. The 2 files that aren't listed have been copied from a computer over USB to this folder, so I'm suspecting I'm missing some permissions.
The following permissions have been specified in AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_USB" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.MOUNT_FORMAT_FILESYSTEMS" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
What do I need to do to see all files?
This is related to the manage_external_storage permission in your file so you need to use the ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page where they can enable the following option for your app: Allow access to manage all files.
Firstly, use following code to judge current version and pop a in method of .SnackbarOnCreateMainActivity
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
if (Android.OS.Build.VERSION.SdkInt >=
Android.OS.BuildVersionCodes.R)
{
if (!Environment.IsExternalStorageManager)
{
Snackbar.Make(FindViewById(Android.Resource.Id.Content),
"Permission needed!", Snackbar.LengthIndefinite)
.SetAction("Settings", new
ClickHandler(this)).Show();
}
}
}
Then you can achieve the ( execute ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION intent action to direct users to a system settings page) to grand the permission.MyClickHandlerManage_External_Storage
internal class ClickHandler:Java.Lang.Object ,View.IOnClickListener
{
private MainActivity mainActivity;
public ClickHandler()
{
}
public ClickHandler(MainActivity mainActivity)
{
this.mainActivity = mainActivity;
}
public void OnClick(View v)
{
try
{
Uri uri = Uri.Parse("package:" +
Application.Context.ApplicationInfo.PackageName);
Intent intent = new
Intent(Android.Provider.Settings.
ActionManageAppAllFilesAccessPermission,
uri);
mainActivity.StartActivity(intent);
}
catch (Exception ex)
{
Intent intent = new Intent();
intent.SetAction
(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
mainActivity.StartActivity(intent);
}
}
}

UWP application unable to access USB drive even though permissions are set

I am working on an app that is responsible for formatting a USB drive and prepare it for further use on an embedded system.
I am formatting the drive using the following method that I found on stack overflow (unfortunately I did not save the link. I'll post it there if I find it again)
public static bool FormatUSB(string driveLetter, string fileSystem = "FAT32", bool quickFormat = true,
int clusterSize = 4096, string label = "USB_0000", bool enableCompression = false)
{
//add logic to format Usb drive
//verify conditions for the letter format: driveLetter[0] must be letter. driveLetter[1] must be ":" and all the characters mustn't be more than 2
if (driveLetter.Length != 2 || driveLetter[1] != ':' || !char.IsLetter(driveLetter[0]))
return false;
//query and format given drive
//best option is to use ManagementObjectSearcher
var files = Directory.GetFiles(driveLetter);
var directories = Directory.GetDirectories(driveLetter);
foreach (var item in files)
{
try
{
File.Delete(item);
}
catch (UnauthorizedAccessException) { }
catch (IOException) { }
}
foreach (var item in directories)
{
try
{
Directory.Delete(item);
}
catch (UnauthorizedAccessException) { }
catch (IOException) { }
}
ManagementObjectSearcher searcher = new ManagementObjectSearcher(#"select * from Win32_Volume WHERE DriveLetter = '" + driveLetter + "'");
foreach (ManagementObject vi in searcher.Get())
{
try
{
var completed = false;
var watcher = new ManagementOperationObserver();
watcher.Completed += (sender, args) =>
{
Console.WriteLine("USB format completed " + args.Status);
completed = true;
};
watcher.Progress += (sender, args) =>
{
Console.WriteLine("USB format in progress " + args.Current);
};
vi.InvokeMethod(watcher, "Format", new object[] { fileSystem, quickFormat, clusterSize, label, enableCompression });
while (!completed) { System.Threading.Thread.Sleep(1000); }
}
catch
{
}
}
return true;
}
I also added all the capabilities that should be required (I think) in order to access a removable drive in my manifest:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces="uap mp rescap iot">
<Identity
Name="7b9becad-6afd-4872-bcb7-7f414c098edf"
Publisher="CN=vitto"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="7b9becad-6afd-4872-bcb7-7f414c098edf" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>DiskMakerApp</DisplayName>
<PublisherDisplayName>vitto</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="DiskMakerApp.App">
<uap:VisualElements
DisplayName="DiskMakerApp"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="DiskMakerApp"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="broadFileSystemAccess" />
<rescap:Capability Name="appCaptureSettings" />
<Capability Name="internetClient" />
<uap:Capability Name="removableStorage" />
<iot:Capability Name="systemManagement"/>
<DeviceCapability Name="usb"/>
</Capabilities>
</Package>
And also allowed access to the file system in Window's settings page:
But I am still getting:
I am wondering if I am missing anything. Is there a way I could run the app as an administrator^ Would that solve the issue? (In any case, only admins would be able to run that app in a real life scenario)
UWP application unable to access USB drive even though permissions are set
Directory.GetFiles can't not use to access file with path in UWP platform. And you can only use Windows Storage API to access file with path (enable broadFileSystemAccess ), by the way, System.Management Namespace is not work for UWP platform, and if you want to format USB device within UWP app, please use desktop extension to process. for more please refer stefan' blog UWP with Desktop Extension

Showing PDF-File with MVVM Cross on Android and IOS

I want to open a PDF on the Phone via the File-Path but i cant figure out how i could do this properly without using 3rd party packages.
You have any suggestion for this?
I already tried to use this on Android:
public void OpenFile(string filePath)
{
var fileToOpen = new Java.IO.File(filePath);
var uri = FileProvider.GetUriForFile(Application.Context, Application.Context.PackageName + ".fileprovider", fileToOpen);
var intent = new Intent();
var mime = IOUtil.GetMimeType(uri.ToString());
intent.SetAction(Intent.ActionView);
intent.SetDataAndType(uri, mime);
intent.SetFlags(ActivityFlags.NewTask);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
Application.Context.StartActivity(intent);
}
But i get the following Error:
Unhandled Exception:
Java.Lang.NullPointerException: Attempt to invoke virtual method
'android.content.res.XmlResourceParser
android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager,
java.lang.String)' on a null object reference
first you should addd this code to your manifest file :
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.easyphotopicker.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths"
tools:replace="android:resource"/>
</provider>
and create filepaths :
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<root-path name="root" path="" /> //root directory of the device new File("/");
<files-path name="files" path="" /> //context.getFilesDir()
<cache-path name="cache" path="" /> //context.getCacheDir()
<external-path name="external" path="" /> //Environment.getExternalStorageDirectory()
<external-files-path name="name" path="path" /> //context.getExternalFilesDirs()
<external-cache-path name="name" path="path" /> //getExternalCacheDirs()
</paths>
Your error is telling us that there is no file at the location matching that's passed into the function. There's a few ways of doing this, one of them is as shown. After accepting permissions to access folders and files, this should be one of the simplest ways. You seem to be close:
public void OpenPdfFile(string filename)
{
var f = new Java.IO.File(filename);
if (f.Exists())
{
System.Diagnostics.Debug.WriteLine("File exists!");
try
{
var openFileIntent = new Intent(Intent.ActionView);
openFileIntent.SetDataAndType(Android.Net.Uri.FromFile(f), "application/pdf");
openFileIntent.SetFlags(ActivityFlags.NoHistory);
StartActivity(Intent.CreateChooser(openFileIntent, "Open pdf file"));
}
catch (ActivityNotFoundException)
{
//handle when no available apps
}
}
}
I haven't tested your work, but the first thing would be to see if you added this to the Manifest file
android:authorities="com.{package}.{name}.fileprovider"
since your code says Application.Context.PackageName + ".fileprovider"

UWP DeviceWatcher skips from Created to EnumerationComplete

I've written a UWP class library that doesn't seem to scan for BLE devices. Looking at the DeviceWatcher, it skips from the status Created to EnumerationComplete. I've tried creating a manifest for my library but the issue persists. Below is some of the code, and my manifest.
Adapter.cs
private DeviceWatcher deviceWatcher;
public override IList<IDevice> ConnectedDevices => ConnectedDeviceRegistry.Values.ToList();
/// <summary>
/// Used to store all connected devices
/// </summary>
public Dictionary<string, IDevice> ConnectedDeviceRegistry { get; }
/// <summary>
/// Registry used to store device instances for pending operations : connect
/// </summary>
public Dictionary<string, IDevice> DeviceOperationRegistry { get; }
public Adapter(DeviceWatcher deviceWatcher)
{
Platform = PLATFORM.WINDOWS;
DeviceOperationRegistry = new Dictionary<string, IDevice>();
ConnectedDeviceRegistry = new Dictionary<string, IDevice>();
this.deviceWatcher = deviceWatcher;
/*DeviceInformation.CreateWatcher(
aqsAllBluetoothLEDevices,
requestedProperties,
DeviceInformationKind.AssociationEndpoint);*/
deviceWatcher.Added += DeviceWatcher_Added;
deviceWatcher.Updated += DeviceWatcher_Updated;
deviceWatcher.Removed += DeviceWatcher_Removed;
deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
deviceWatcher.Stopped += DeviceWatcher_Stopped;
}
protected override Task StartScanningForDevicesNativeAsync(Guid[] serviceUuids, bool allowDuplicatesKey, CancellationToken scanCancellationToken)
{
// clear out the list
DiscoveredDevices.Clear();
deviceWatcher.Start();
return Task.FromResult(true);
}
BleImplementation.cs
string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.Bluetooth.Le.IsConnectable" };
// BT_Code: Example showing paired and non-paired in a single query.
string aqsAllBluetoothLEDevices = "(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")";
DeviceWatcher deviceWatcher;
protected override IAdapter CreateNativeAdapter()
{
deviceWatcher = DeviceInformation.CreateWatcher(
aqsAllBluetoothLEDevices,
requestedProperties,
DeviceInformationKind.AssociationEndpoint);
return new Adapter(deviceWatcher);
}
Package.appxmanifest
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Prerequisites>
<OSMinVersion></OSMinVersion>
<OSMaxVersionTested></OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="" />
</Resources>
<Applications>
<Application Id="" StartPage="">
<VisualElements DisplayName="" Description=""
Logo="" SmallLogo=""
ForegroundText="" BackgroundColor="">
<SplashScreen Image="" />
</VisualElements>
</Application>
</Applications>
<Identity Name="MyCompany.MySuite.MyApp"
Version="1.0.0.0"
Publisher="CN=MyCompany, O=MyCompany, L=MyCity, S=MyState, C=MyCountry"/>
<Properties>
<DisplayName>MyApp</DisplayName>
<PublisherDisplayName>MyCompany</PublisherDisplayName>
<Logo>images\icon.png</Logo>
</Properties>
<Capabilities>
<Capability Name="internetClient" />
<!--BT_Code: Always declare the bluetooth capability when using Bluetooth-->
<DeviceCapability Name="bluetooth" />
</Capabilities>
</Package>

PushWoosh Xamarin Forms Android exception on registration

I've been trying to implement PushWoosh's push notifications system in my existing Xamarin Forms (PCL) project and so far, it works perfectly with iOS.
When it comes to adding it to Android, I'm facing a crash at launch despite the fact that I have followed letter by letter the guide for Xamarin Forms for Android.
The app simply crashes on launch due to an Unhandled exception.
I've had fun commenting line by line to find what caused this error and it seems it is manager.RegisterForPushNotifications(); that executes the code responsible for that crash.
After further investigation in the debug log, it seems to be a problem with the ShortcutBadger being unable to resolve an intent.
I've ran the app on physical devices, fully up-to-date:
Samsung Galaxy S4
(Asus) Google Nexus 7
I am using Visual Studio 2017 Community.
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.awesome"
android:versionCode="1"
android:versionName="4.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<!-- Badges -->
<!-- Common -->
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS"/>
<!-- Apex -->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/>
<!-- Samsung -->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ" />
<uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />
<!-- Sony -->
<uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />
<!-- HTC -->
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT" />
<!-- Solid -->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/>
<!-- Huawei -->
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE"/>
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS"/>
<!-- ZUK -->
<uses-permission android:name="android.permission.READ_APP_BADGE"/>
<!-- OPPO -->
<uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS"/>
<!-- EvMe -->
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_READ"/>
<uses-permission android:name="me.everything.badger.permission.BADGE_COUNT_WRITE"/>
<!-- /Badges -->
<!-- Location tracking -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Boot permission for rescheduling local notifications and location tracking -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!-- GCM Part -->
<permission android:name="com.package.awesome.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.package.awesome.permission.C2D_MESSAGE"/>
<application android:label="#string/app_name"
android:icon="#mipmap/ic_launcher">
<meta-data android:name="com.google.android.gms.version"
android:value="8487000" />
<meta-data android:name="PW_APPID"
android:value="A1B2C-3D4E5" />
<meta-data android:name="PW_PROJECT_ID"
android:value="awesome-app" />
<!-- GCM Part -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.package.awesome" />
</intent-filter>
</receiver>
</application>
</manifest>
MainActivity.cs:
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Pushwoosh;
using Android.Content.PM;
using Android.Util;
namespace Project.Droid
{
class LocalMessageBroadcastReceiver : BasePushMessageReceiver
{
public MainActivity activity { get; set; }
protected override void OnMessageReceive(Intent intent)
{
activity.doOnMessageReceive(intent.GetStringExtra(BasePushMessageReceiver.JsonDataKey));
}
}
[Activity(Label = "#string/app_name", Theme = "#style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new string[] { "com.package.awesome.MESSAGE" }, Categories = new string[] { "android.intent.category.DEFAULT" })]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
LocalMessageBroadcastReceiver mMessageReceiver;
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
mMessageReceiver = new LocalMessageBroadcastReceiver();
mMessageReceiver.activity = this;
registerReceivers();
PushManager manager = PushManager.GetInstance(this);
manager.OnStartup(this);
// Register for push!
manager.RegisterForPushNotifications();
// Reset application icon badge number
manager.BadgeNumber = 0;
checkMessage(Intent);
}
protected override void OnNewIntent(Intent intent)
{
checkMessage(intent);
}
public void checkMessage(Intent intent)
{
if (null != intent)
{
if (intent.HasExtra(PushManager.PushReceiveEvent))
{
doOnMessageReceive(intent.Extras.GetString(PushManager.PushReceiveEvent));
}
resetIntentValues();
}
}
public void doOnMessageReceive(String message)
{
// hadle push open here
Log.Debug("PushwooshSample", "Push opened: " + message);
}
private void resetIntentValues()
{
Intent mainAppIntent = Intent;
if (mainAppIntent.HasExtra(PushManager.PushReceiveEvent))
{
mainAppIntent.RemoveExtra(PushManager.PushReceiveEvent);
}
else if (mainAppIntent.HasExtra(PushManager.RegisterEvent))
{
mainAppIntent.RemoveExtra(PushManager.RegisterEvent);
}
else if (mainAppIntent.HasExtra(PushManager.UnregisterEvent))
{
mainAppIntent.RemoveExtra(PushManager.UnregisterEvent);
}
else if (mainAppIntent.HasExtra(PushManager.RegisterErrorEvent))
{
mainAppIntent.RemoveExtra(PushManager.RegisterErrorEvent);
}
else if (mainAppIntent.HasExtra(PushManager.UnregisterErrorEvent))
{
mainAppIntent.RemoveExtra(PushManager.UnregisterErrorEvent);
}
Intent = mainAppIntent;
}
protected override void OnResume()
{
base.OnResume();
registerReceivers();
}
protected override void OnPause()
{
base.OnPause();
unregisterReceivers();
}
public void registerReceivers()
{
IntentFilter intentFilter = new IntentFilter(PackageName + ".action.PUSH_MESSAGE_RECEIVE");
RegisterReceiver(mMessageReceiver, intentFilter);
}
public void unregisterReceivers()
{
UnregisterReceiver(mMessageReceiver);
}
}
}
Crash log:
07-31 10:12:09.182 D/Pushwoosh(29231): [RequestManager] Try To send: getInApps
07-31 10:12:09.185 V/Pushwoosh(29231): [GCMRegistrationService] Intent action = com.pushwoosh.gcm.intent.REGISTER
07-31 10:12:09.190 E/Pushwoosh(29231): [ShortcutBadger] Unable to execute badge
07-31 10:12:09.190 E/Pushwoosh(29231): com.pushwoosh.thirdparty.a.b: Unable to execute badge
07-31 10:12:09.190 E/Pushwoosh(29231): at com.pushwoosh.thirdparty.a.c.b(Unknown Source)
07-31 10:12:09.190 E/Pushwoosh(29231): at com.pushwoosh.thirdparty.a.c.a(Unknown Source)
07-31 10:12:09.190 E/Pushwoosh(29231): at com.pushwoosh.internal.PushManagerImpl$2.run(Unknown Source)
07-31 10:12:09.190 E/Pushwoosh(29231): at android.os.Handler.handleCallback(Handler.java:739)
07-31 10:12:09.190 E/Pushwoosh(29231): at android.os.Handler.dispatchMessage(Handler.java:95)
07-31 10:12:09.190 E/Pushwoosh(29231): at android.os.Looper.loop(Looper.java:148)
07-31 10:12:09.190 E/Pushwoosh(29231): at android.app.ActivityThread.main(ActivityThread.java:5417)
07-31 10:12:09.190 E/Pushwoosh(29231): at java.lang.reflect.Method.invoke(Native Method)
07-31 10:12:09.190 E/Pushwoosh(29231): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
07-31 10:12:09.190 E/Pushwoosh(29231): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-31 10:12:09.190 E/Pushwoosh(29231): Caused by: com.pushwoosh.thirdparty.a.b: unable to resolve intent: Intent { act=android.intent.action.BADGE_COUNT_UPDATE (has extras) }
07-31 10:12:09.190 E/Pushwoosh(29231): at com.pushwoosh.thirdparty.a.a.d.a(Unknown Source)
07-31 10:12:09.190 E/Pushwoosh(29231): ... 10 more
Please note that I've renamed the project name, package, PushWoosh app ID and FCM app ID for confidentiality purposes.
I solved my problem by updating the Xamarin.GooglePlayServices.Gcm dependency to the latest version 42.1021.1 while mine was 29.x.x.
As Mike said in the comments, I had to make sure that everything is up-to-date since PushWoosh does not require a high version of critical dependencies such as Google Play Services while they could potentially crash the app if obsolete. They should be more restrictive on that point !

Categories

Resources