Giter VIP home page Giter VIP logo

toasts.forms.plugin's Introduction

Toasts Notification Plugin for Xamarin and Windows

A simple way of showing notifications inside your Xamarin or Windows application. In windows phone world we call them "Toasts". This plugin uses the platforms native toast / notification API's.

Setup and usage

Setup

Platform Support

Platform Supported Version
Xamarin.iOS No
Xamarin.iOS Unified Yes iOS 10+
Xamarin.Android Yes API 16+ (AppCompat Only)
Windows Phone Silverlight No
Windows Phone RT No
Windows Store RT No
Windows 10 UWP Yes 10+
Xamarin.Mac No

Now uses .NET Standard 1.3, does support PCL 111.

iOS Support Version 3+ of this plugin requires iOS10 to display the toast notification. If you require support for iOS7+ then please use version 2.0.4.

I you want to use the latest plugin with a version less than iOS 10 you can hook into the ReceivedLocalNotification in the AppDelegate to display an Alert.

Setup

In your iOS, Android, WinRT and UWP projects please call:

DependencyService.Register<ToastNotification>(); // Register your dependency
ToastNotification.Init();

// If you are using Android you must pass through the activity
ToastNotification.Init(this);

If you are using Xamarin Forms, you must do this AFTER your call to Xamarin.Forms.Init();

Usage

Use dependency service in order to resolve IToastNotificator.

var notificator = DependencyService.Get<IToastNotificator>();

var options = new NotificationOptions()
            {
                Title = "Title",
                Description = "Description"
            };

var result = await notificator.Notify(options);

The result that is returned is a NotificationResult with an Action inside with one of the following values.

[Flags]
public enum NotificationAction
{
    Timeout = 1, // Hides by itself
    Clicked = 2, // User clicked on notification
    Dismissed = 4, // User manually dismissed notification
    ApplicationHidden = 8, // Application went to background
    Failed = 16 // When failed to display the toast
}

If you want the Clicked NotificationAction you must set IsClickable = true in the NotificationOptions.

Permissions

In iOS you must request permission to show local notifications first since it is a user interrupting action.

// Request Permissions
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
    // Request Permissions
    UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (granted, error) =>
    {
        // Do something if needed
    });
}
else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
    var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null);

    app.RegisterUserNotificationSettings(notificationSettings);
}

Contributors

Thanks!

License

Licensed under MIT

toasts.forms.plugin's People

Contributors

adamped avatar breyed avatar canab avatar dcasbonne avatar diego-suarez avatar egorbo avatar haroldma-zz avatar kmormysh avatar knxrb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toasts.forms.plugin's Issues

WP8 solution does not build with XF 1.3.3

Hi @EgorBo !

I REALLY REALLY REALLY like your plugin and it works perfectly, but everytime Xamarin.Forms gets updated, the build for the WP8 version of the app breaks... iOS and Android works perfectly well.

Is there anything wrong with my setup ?

Thx !

Error when init in Xamarin.iOS AppDelegate class

When I init the plugin in a Xamarin.Forms iOS project I get the following error:

Error MT0034: Cannot include both 'monotouch.dll' and 'Xamarin.iOS.dll' in the same Xamarin.iOS project - 'monotouch.dll' is referenced explicitly, while 'Xamarin.iOS.dll' is referenced by 'Toasts.Forms.Plugin.iOS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. (MT0034) (MyProjectName)

Initilization like:

            public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {
        Forms.Init ();

        ToastNotificatorImplementation.Init ();

        window = new UIWindow (UIScreen.MainScreen.Bounds);

        ...
        return true;
    }

How could I solve this?

I am using Xamarin.Forms 1.3.0 (stable)

PS. thanks for sharing this awesome plugin

Recommendation: Rename NuGet Packages

Wondering if you could update the name of the package to "Toasts Plugin for Xamarin.Forms". Will help with discoverability and things we will be doing to highlight plugins.

Thanks! and this is awesome.

Toast is compatible with the new Windows 8.1 projects? i am getting an error

The error:

Adding 'Toasts.Forms.Plugin 1.0.6.18' to Useall.E2.Comercial.AV.Mobile.Windows.
Install-Package : Could not install package 'Toasts.Forms.Plugin 1.0.6.18'. You are trying to install this package into a project that targets 'WindowsPhoneApp,Version=v8.1', but the package does not contain
any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1

  • Install-Package Toasts.Forms.Plugin -Version 1.0.6.18
  • - CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    - FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
    
    

Someone know about?
Thanks

using Toasts.Forms.Plugin.iOS

"using Toasts.Forms.Plugin.iOS" can't be resolved within an iOS project. Is this a known issue?

Project info:
Xamarin.Forms v1.3.2
Unified API
Toasts plugin v1.0.0.9

Increase Height

Good Morning,
I have a question here:
When my messages are large, and it's not possible to reduce it,
it's possible to increase the height of the Toast Box ?

Windows Store

Hi,

I like this plugin quite a lot, is there any chance this will or could be extended to the Xamarin.Forms windows store preview?

Cheers

Feature request: Is Sticky Mode

Can we have one more property for IsSticky when set the Toast shows until tapped or until we hide it from code?
This would be a great feature to have.

Thanks
ST

MessageBarStyleSheet is read only?

I'm trying to call Init in Xamarin.iOS with ToastNotificatorImplementation.Init(new MessageBarStyleSheet() { ??? } );

However, it looks like none of the parameters of the "custom" style sheet can actually be altered. Am I missing something?

android: Java.Lang.NullPointerException if next notification is shown before previous is hiding

varsion: 1.0.6.18

I always call notificator.HideAll() before showing any notification to dismiss previous one;
On iOS it works OK.
But on Android it does not hide previous and shows a new one on top instead. After last notification is hidden an exception is thrown:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
[MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1978/f98871a9/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
[MonoDroid] at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue*) [0x00063] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571
[MonoDroid] at Android.Views.View.StartAnimation (Android.Views.Animations.Animation) [0x0005a] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:18992
[MonoDroid] at Toasts.Forms.Plugin.Droid.Manager.RemoveCrouton (Toasts.Forms.Plugin.Droid.Crouton) [0x00016] in c:\Projects\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:227
[MonoDroid] at Toasts.Forms.Plugin.Droid.Manager.HandleMessage (Android.OS.Message) [0x00044] in c:\Projects\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:108
[MonoDroid] at Android.OS.Handler.n_HandleMessage_Landroid_os_Message_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/1978/f98871a9/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.OS.Handler.cs:356
[MonoDroid] at (wrapper dynamic-method) object.faa8fdcb-fad5-40a2-ad29-238ec4e97112 (intptr,intptr,intptr) <IL 0x00017, 0x00027>
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] java.lang.NullPointerException
[MonoDroid]     at android.view.View.startAnimation(View.java:16790)
[MonoDroid]     at md5ec11fdb01388465a68addaebc5a82d67.Manager.n_handleMessage(Native Method)
[MonoDroid]     at md5ec11fdb01388465a68addaebc5a82d67.Manager.handleMessage(Manager.java:52)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:102)
[MonoDroid]     at android.os.Looper.loop(Looper.java:136)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5001)
[MonoDroid]     at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[MonoDroid]     at dalvik.system.NativeStart.main(Native Method)

Add support for iOS classic API.

Add support for Classic API until we port it to Unified API

We can't test the iOS app as I get the error :

with version 1.0.0.9 :
cannot include both 'monotouch.dll' and 'xamarin.ios.dll' in the same xamarin.ios project - 'xamarin.ios.dll' is referenced explicitly, while 'monotouch.dll' is referenced by 'toasts.forms.plugin'

with latest stable version,
there is no Toasts.Forms.Plugin.iOS assembly

Information Needed For Swag Bag

I first want to personally thank you for creating a Plugin for Xamarin for our holiday contest. To get your exclusive Xamarin Swag Bag out to you I just need a bit more information from you. If you can email: [email protected] with the following information we will get the bag out to you.

Name
Street Address
City, State, Zip Code
Country
Phone Number
The URL to this repo

Thank you again and I hope to see even more plugins from you in the future. Always feel free to reach out if you need anything.

Would you consider flattening your namespaces?

Hi Egor,

Would you consider flattening your namespaces from:

using Toasts.Forms.Plugin.iOS;
using Toasts.Forms.Plugin.Droid;
using Toasts.Forms.Plugin.WP8;
using Toasts.Forms.Plugin.Abstractions;

To just:

using Toasts;

This will cement your library as the library for toasts when using Xamarin and greatly improve developer accessibility when using MonoDevelop.

Toast should show up from the bottom of the screen

Hi ,

I am using this toasts.forms.plugin, i need this toast message to show up at the bottom of the screen. just need to know where exactly i should change the position of the toast.
please help!!
Thanks in advance.

Issue with Toasts.IToastNotificator reference (iOS)

Hi, fantastic plugin, thank you. I recently updated the Nuget reference to ver 2.0.1 however now the project refuses to build due to to the following error:

Error CS7069: Reference to type Toasts.IToastNotificator' claims it is defined assemblyToasts.Forms.Plugin.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', but it could not be found (CS7069)

This only started happening with this latest version. The issue occurs on the following line in the AppDelegate "DependencyService.Register();"

Any input on this?

Unhandled Exception under Xamarin.iOS

I'm using your latest version of this plugin and under iOS I don't get it to work. It always throws an unhandled exception, which I can't catch, without any information.

I'm running Xamarin.Forms 1.3.1 in the TestApplication I made to show the problem.
In this code it doesn't even execute the button clicked event. Am I doing something wrong?

I noticed, that when I install the plugin via nuget package manager, in the iOS project the wrong Toast.Forms.Plugin.Abstractions.dll gets referenced (its referencing the pcl version) and the Toast.Forms.Plugin.iOS.dll is not referenced at all. So I added them by myself. May this be the problem?

AppDelegate.cs



using Foundation;
using Toasts.Forms.Plugin.iOS;
using UIKit;

namespace XFTest.iOS
{
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            ToastNotificatorImplementation.Init();
            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
    }
}
App.cs

using Xamarin.Forms;

namespace XFTest
{
    public class App : Application
    {
        public App()
        {                       
            // The root page of your application
            MainPage = new TestPage();
        }
    }
}
TestPage.cs

using Toasts.Forms.Plugin.Abstractions;
using Xamarin.Forms;

namespace XFTest
{
    public class TestPage : ContentPage
    {
        public TestPage()
        {
            var layout = new StackLayout();

            var button = new Button
            {
                Text = "Notifier"
            };
            button.Clicked += ButtonOnClicked;

            layout.Children.Add(button);

            Content = layout;
        }

        private async void ButtonOnClicked(object sender, EventArgs eventArgs)
        {
            var notifier = DependencyService.Get<IToastNotificator>();

            bool tapped = await notifier.Notify(ToastNotificationType.Info, "Test", "test", TimeSpan.FromSeconds(5));
        }
    }
}

///Edit: I installed it with the console and now I get this exception:

System.NotImplementedException: The requested feature is not implemented

The Toasts.Forms.Plugin.Abstractions.dll is referenced wrong again. It's the PCL profile one. Not the Monotouch10.

///Edit2: When I add the correct references the DependecyService.Get is working. But when I try to display an toast notification I get an Unhandled.Exception of type System.NullReferenceExcpetion: Object reference not set to an instance of an object

Question/Request

Hi,
first of all, thank you for this plugin. It's really cool.
So my question: Would it be possible to create a notification with an ActivityIndicator?
I would contribute to this but currently I can't support all 3 platforms (VS2012/Win7)

notificator.HideAll(); does not work on android (Sample Code included)

Hi
If i show the notification for 25 seconds & after 10 seconds I call the HideAll method, it works fine on iOS 8.3 but the notification remains open in Android 4.4.4 for another 15 seconds.
Seems like calling HideAll does not work in Android?
Anyone else who has used it & found this to be working?
Let me know your observations please.

Thanks
ST

NullReferenceException

On iOS, crash with the error message below. Bits from 1.0.7.19-pre1 (nuget)

Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object

2015-04-01 09:08:51.906 TheAppIos[11654:431130] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
at Toasts.Forms.Plugin.iOS.MessageView.Draw (CGRect rect) [0x00000] in :0
at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
at TheApp.iOS.Application.Main (System.String[] args) [0x00001] in c:\Users\johankarlsson\Source\Repos\TheApp\TheApp\TheApp.iOS\Main.cs:17

Cannot install Toasts.Form.Plugin 1.0.6.18 in Xamarin portable project

The error is:

Install-Package : Could not install package 'Toasts.Forms.Plugin 1.0.6.18'. You are trying to install this package into a project that targets
'.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For
more information, contact the package author.
At line:1 char:1

  • Install-Package Toasts.Forms.Plugin -Version 1.0.6.18
  • - CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    - FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
    

Type Custom with DefaultToastLayoutRenderer

I implemented the DefaultToastLayoutRenderer with type ToastNotificationType.Custom passing an url (small profile image from web) and a color.
The problem is it takes a little time to load the image the first time (I cache it for reuse) and while retrieving the image, the default image ("Resource.Drawable.error") is shown.
Could this be changed so that there is no default image when using the Action<object, ImageView> imageSetterForCustomType = null.

Thanks in advance and keep up the good work.

Dismiss possible?

Is it possible to add the possibility that when the user "ticks" the toast that it is dismissed (even when the duration is not yet expired)?

Exception System.MissingMethodException

Hey Egor,
i got this error when I want to use the toast.

Android 4.4/5.0
Xamarin Forms 1.4.0.6341
Toasts.Forms.Plugin 1.0.6.18

public static void Error(string text, string description = null, int duration = 3) 
{
    DependencyService.Get<IToastNotificator>().Notify(
       ToastNotificationType.Error, 
       text, 
       description, 
       TimeSpan.FromSeconds(duration)
    );
}
{System.MissingMethodException: Default constructor not found for type Toasts.Forms.Plugin.Droid.ToastNotificatorImplementation   
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0    
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0    
at Xamarin.Forms.DependencyService.Get[IToastNotificator] (DependencyFetchTarget fetchTarget) [0x00000] in <filename unknown>:0    
at Foo.Common.Views.Toast.Error (System.String text, System.String description, Int32 duration) [0x00002] in /Users/armintelker/git/universal-app/Foo/Common/Views/Toast.cs:21    
at Foo.Green.Search.Pages.ScannerSearchPage+<searchBarcode>c__async0.MoveNext () [0x000d9] in /Users/armintelker/git/universal-app/Foo/Green/Search/Pages/ScannerSearchPage.xaml.cs:111 }   
System.MissingMethodException

Do you have maybe a idea?
Thanks :)

Toast goes trough statusbar with appcompat

I am writing an Xamarin.Forms app that implements appcompat (here is how).

untitled

However as you can see, this also makes the toast dialog clip trough. A feature to set a offset would be nice if there aren't any other fixes.

Migrate to Xamarin Plugin instead of Forms

Can you remove Xamarin.Forms dependency and make it compatibel with Xamarin native projects and PCL?

I tried to do it myself by somehow get top activity context is not working.

Conflict between Toasts and StatusBar Height (UIKit.UIApplication.SharedApplication.StatusBarFrame.Height)

Using the Toasts.Forms.Plugin has an unexpected conflict with Xamarin.iOS asking the operating system for the height of the Status Bar.

In Xamarin Forms I ask the OS for the height of the Status Bar every time there is a SizeChanged event and then adjust my screen layout (the XamForms StackLayout padding)
I use UIKit.UIApplication.SharedApplication.StatusBarFrame.Height to get the height.

This works perfectly in my apps but fails after the first Toast has been generated using Toasts.Forms.Plugin.

Before the Toast, the call to UIKit.UIApplication.SharedApplication.StatusBarFrame.Height gives me 20 pixels for portrait and 0 pixels for landscape (on iPhone). On iPad it is always 20 pixels in both orientations.

After the Toast the call to UIKit.UIApplication.SharedApplication.StatusBarFrame.Height gives me 0 pixels for portrait and 20 pixels for landscape on iPhone,

Something has happened so that when Xamarin Forms and Xamarin.iOS asks for the height, it gets incorrect values if a Toast has been generated.

My code is like this in a Xamarin Forms app

        this.SizeChanged += (object sender, EventArgs e) => 
            {
                // iOS on phones hides the Status Bar in Landscape (iPad does not)
                if (Device.OS == TargetPlatform.iOS) {
                    int sbHeight = (int)UIKit.UIApplication.SharedApplication.StatusBarFrame.Height);
                    stackLayout.Padding = new Thickness (0, sbHeight, 0, 0);
                }
            };

Other tests...
I have tested with the pre release of 1.7.x.x and there is no change.
I have tested with the current Alpha of Xamarin.iOS 8.13.x.x and no change.
ACR's Toast library works fine so currently use your library for Android and ACR for iOS

Thanks
Roger

Monotouch10

I see that you migrated the package from Monotouch 10 to Xamarin.IOS, Are there any possibility to put this plugin in Monotouch, I tried to use it but I not got it.

System.IO.FileNotFoundException: /Icons/icon-error.png does not exist

Throw this error after update to 1.0.9.21

Error 365 System.IO.FileNotFoundException: /Users/local_admin/Library/Caches/Xamarin/mtbs/builds/MyMobileiOS/6a1077279d715fb26949d0c771bd85c4/obj/iPhone/Debug/Icons/icon-error.png does not exist
File name: '/Users/local_admin/Library/Caches/Xamarin/mtbs/builds/MyMobileiOS/6a1077279d715fb26949d0c771bd85c4/obj/iPhone/Debug/Icons/icon-error.png'
at System.IO.File.Copy (System.String sourceFileName, System.String destFileName, Boolean overwrite) <0x19ff7f0 + 0x00333> in :0
at Xamarin.MacDev.Tasks.SmartCopyTaskBase.CopyFile (System.String source, System.String target, System.String targetItemSpec) <0x38e0640 + 0x000c7> in :0
at Xamarin.MacDev.Tasks.SmartCopyTaskBase.Execute () <0x38dfe20 + 0x00227> in :0 C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 377 3 MySIT.Mobile.iOS

Incompatible with Xamarin.Forms 1.3.1.6296

I upgraded my project's nuget packages - Xamarin.Forms and Toasts Plugin. My Win Phone project then failed to build.

Uninstalling Toasts resolved the issue.

The error I got was:

Cannot resolve dependency to assembly Xamarin.Forms.Core, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null because it has not been preloaded

"Target _CopyMdbFiles" issue when packaging on console

When packaging our android app using xbuild on the console, the _CopyMdbFiles target tries to copy Toast.Forms.Plugin related dll files from the bin/ directory that are not existing. It seems that the path is missing a slash before the file name, because all names are prefixed with Release like bin/ReleaseToasts.Forms.Plugin.Abstractions.dll. Checking the bin/ directory i can confirm that the files do not exist, but they are available in the bin/Release/ subfolder. I am not 100% sure if the path is broken or the missing files do not get generated.

Do you have any idea where this issue comes from and how to fix it? My theory is that it is linker related, which would be weird because we added Toasts.Forms.Plugin.Droid to our linker description file and it works.

Enclosed is the output of the _CopyMdbFiles target:

Target _CopyMdbFiles:

:  warning : Could not find file "//path-to-app/bin/ReleaseToasts.Forms.Plugin.Abstractions.dll".  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at Mono.Cecil.ModuleDefinition.GetFileStream (System.String fileName, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName) [0x00000] in <filename unknown>:0
  at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName) [0x00000] in <filename unknown>:0
  at Pdb2Mdb.Converter.Convert (System.String filename) [0x00000] in <filename unknown>:0
  at Xamarin.Android.Tasks.CopyMdbFiles.Execute () [0x00000] in <filename unknown>:0
:  warning : Could not find file "//path-to-app/bin/ReleaseToasts.Forms.Plugin.Droid.dll".  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at Mono.Cecil.ModuleDefinition.GetFileStream (System.String fileName, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x00000] in <filename unknown>:0
  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName) [0x00000] in <filename unknown>:0
  at Mono.Cecil.AssemblyDefinition.ReadAssembly (System.String fileName) [0x00000] in <filename unknown>:0
  at Pdb2Mdb.Converter.Convert (System.String filename) [0x00000] in <filename unknown>:0
  at Xamarin.Android.Tasks.CopyMdbFiles.Execute () [0x00000] in <filename unknown>:0

Assembly could not be found

Using the latest version on Nuget. Trying to set up the Toasts plugin in iOS gives the following error:

Reference to type 'Toasts.IToastNotificator' claims it is defined assembly 'Toasts.Forms.Plugin.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', but it could not be found.

This is from

DependencyService.Register<Toasts.ToastNotificatorImplementation>();

in AppDelegate.cs

Feature Request: no title

Would be nice if you could define (of evaluate) that there is no title and that all text is rendered from the top. Leaving the title empty leaves an empty line in the toast.

Android 5 Crashes On Notify

Hey Egor,
I have a problem with the Android Toast on Android 5 (LG Nexus 5 5.01).
For Android 4.x devices everything is fine.

Example Code:

DependencyService.Get<IToastNotificator>().Notify(
    ToastNotificationType.Success, 
    text, // "Foo"
    description, //"Bar" 
    TimeSpan.FromSeconds(duration) // 1
);
System.Diagnostics.Debugger.Mono_UnhandledException_internal () in 
System.Diagnostics.Debugger.Mono_UnhandledException (ex={Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00068>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
at Android.Runtime.JNIEnv.FinishCreateInstance (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:288
at Java.Lang.String..ctor (string) [0x000fc] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.String.cs:464
at Toasts.Forms.Plugin.Droid.Manager.AnnounceForAccessibilityCompat (Android.Content.Context,string) [0x00044] in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:277
at Toasts.Forms.Plugin.Droid.Manager/<>c__DisplayClass1.<CallOnGlobalLayout>b__0 () [0x0005a] in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:173
at Toasts.Forms.Plugin.Droid.Manager/GlobalLayoutListener.OnGlobalLayout (System.Action) [0x00000] in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:293
at Toasts.Forms.Plugin.Droid.Manager.CallOnGlobalLayout (Toasts.Forms.Plugin.Droid.Crouton,Android.Views.View) [0x00026] in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:159
at Toasts.Forms.Plugin.Droid.Manager.AddCroutonToView (Toasts.Forms.Plugin.Droid.Crouton) [0x00070] in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:151
at Toasts.Forms.Plugin.Droid.Manager.HandleMessage (Android.OS.Message) [0x0003c] in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:104
at Android.OS.Handler.n_HandleMessage_Landroid_os_Message_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.OS.Handler.cs:312
at (wrapper dynamic-method) object.2d792a2f-481d-41bb-bab2-5c909adab5b6 (intptr,intptr,intptr) <IL 0x00017, 0x00043>

  --- End of managed exception stack trace ---
java.lang.NullPointerException: Attempt to read from field 'char[] java.lang.String.value' on a null object reference
    at java.lang.String.<init>(String.java:421)
    at toasts.forms.plugin.droid.Manager.n_handleMessage(Native Method)
    at toasts.forms.plugin.droid.Manager.handleMessage(Manager.java:52)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
}) in 
object.2d792a2f-481d-41bb-bab2-5c909adab5b6 (arg0=0xffffffffb5051240, arg1=0xffffffffbefb52bc, arg2=0xffffffffbefb52c0) in 
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () in 
Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (jobject=0x100b9e, jclass=0x30050e, jmethod=0x707657d8, parms={Android.Runtime.JValue[1]}) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
Android.Runtime.JNIEnv.FinishCreateInstance (instance=0x100b9e, jclass=0x30050e, constructorId=0x707657d8, constructorParameters={Android.Runtime.JValue[1]}) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:288
Java.Lang.String..ctor (toCopy=(null)) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.String.cs:464
Toasts.Forms.Plugin.Droid.Manager.AnnounceForAccessibilityCompat (context={rebuyapp.android.MainActivity@1875637f}, text=(null)) in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:277
Toasts.Forms.Plugin.Droid.Manager. () in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:173
Toasts.Forms.Plugin.Droid.Manager.GlobalLayoutListener.OnGlobalLayout (action={System.Action}) in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:293
Toasts.Forms.Plugin.Droid.Manager.CallOnGlobalLayout (crouton={toasts.forms.plugin.droid.Crouton@2eff453f}, croutonView={android.widget.LinearLayout{2827474 V.E...C. ......ID 0,0-0,0}}) in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:159
Toasts.Forms.Plugin.Droid.Manager.AddCroutonToView (crouton={toasts.forms.plugin.droid.Crouton@2eff453f}) in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:151
Toasts.Forms.Plugin.Droid.Manager.HandleMessage (message={{ when=-632ms what=12714097 obj=toasts.forms.plugin.droid.Crouton@2eff453f target=toasts.forms.plugin.droid.Manager }}) in d:\tohoto\GitHub\Toasts.Forms.Plugin\Toasts.Forms.Plugin.Droid\Manager.cs:104
Android.OS.Handler.n_HandleMessage_Landroid_os_Message_ (jnienv=0xffffffffb5051240, native__this=0xffffffffbefb52bc, native_msg=0xffffffffbefb52c0) in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.OS.Handler.cs:312
object.2d792a2f-481d-41bb-bab2-5c909adab5b6 (arg0=0xffffffffb5051240, arg1=0xffffffffbefb52bc, arg2=0xffffffffbefb52c0) in 

Question for use this plugin

I want to use it in android dependecy (ZXing barcode scanner), but it doesn't work. in iOS works perfectly. Can you tell me how to operate it ?

Thanks very much for your plugin

WP8 solution does not build with XF 1.4.0

After upgrade of Xamarin.Forms to 1.4.0 the WP8 solution does not build anymore because of missing dependency to XF 1.3.1. Android and iOS build fine.

Same as:

Could we have a fix? Thank you for your good work :)

ObjectDisposedException on iOS

I get ObjectDisposedException when I try to navigate from one page to another.
I am using Xamarin Forms. The navigation is made as so: Navigation.PushAsync(newPage, true);

Exception: Exception type: System.ObjectDisposedException
The object was used after being disposed.
at System.Net.Sockets.Socket.EndAccept (System.Byte[]& buffer, System.Int32& bytesTransferred, IAsyncResult asyncResult) [0x00000] in :0
at System.Net.Sockets.Socket.EndAccept (IAsyncResult result) [0x00000] in :0
at Mtb.Server.Proxy.LogProxy.VS_IncomingOutput (IAsyncResult result) [0x00000] in :0

Android.Views.InflateException

Tried to use this Plugin for a Xamarin Forms Shared Project. I have set the Toast Init after the Xamarin.Forms.Init() as stated in the docs. An exception of type "Android.Views.InflateException: can be used only with a valid ViewGroup root and attachToRoot=true" throws.

Is there something wrong with what Im doing?
Im using FormsAppCompatActivity by the way.

System.MissingMethodException: Method 'ViewTreeObserver.RemoveOnGlobalLayoutListener' not found.

When I use Toasts.Forms.Plugin V 1.0.6.18 on my Xamarin Forms Android App and I compile it with Android level 15 (4.0.3) and run it in a emulator running Android 4.0.3, I get this exception...

It is strange, should not

       if (Build.VERSION.SdkInt < Build.VERSION_CODES.JellyBean)
            {
                croutonView.ViewTreeObserver.RemoveGlobalOnLayoutListener(layoutListener);
            }
            else
            {
                croutonView.ViewTreeObserver.RemoveOnGlobalLayoutListener(layoutListener);
            }

prevent such errors?

WP8 solution does not build with XF 1.3.2

After upgrade of Xamarin.Forms to 1.3.2 the WP8 solution does not build anymore because of missing dependency to XF 1.3.1. Android and iOS build fine.

any workaround ?

The 'await' operator can only be used when its containing method is marked with the 'async' modifier

I was using the latest Toasts.Forms.Plugin in a shared asset project, trying the sample code you provided.

var notificator = DependencyService.Get<IToastNotificator>();
bool tapped = await notificator.Notify(ToastNotificationType.Error, "Error", "Something went wrong", TimeSpan.FromSeconds(2));

But this gives me the following error,

Error CS4033: The 'await' operator can only be used when its containing method is marked with the 'async' modifier (CS4033) (iRemote.iOS)

However, when I change the code to:

var notificator = DependencyService.Get<IToastNotificator>();
var tapped = notificator.Notify(ToastNotificationType.Error, "Error", "Something went wrong", TimeSpan.FromSeconds(2));

It works fine, although the dismiss on click doesn't work on Android (works fine in iOS).

Could you please direct me as to what I've done wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.