How to set animation on Notification Badge in Xamarin Android - animation

I want to set animation on Notification Badge and how to display the badge infront of the imageview(Z axis)

According to the following thread, we can see that Android does not allow changing of the application.
How to display count of notifications in app launcher icon
But If you still want to animation for notification, I suggest you can implement animation for Android Notification bar.
It needs one animationfile.xml
<?xml version="1.0" encoding="utf-8" ?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/icaon" android:duration="10000" />
<item android:drawable="#drawable/ic_stat_button_click" android:duration="10000" />
</animation-list>
int icon = Resource.Drawable.animationfile;
// Build the notification:
var builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.SetAutoCancel(true) // Dismiss the notification from the notification area when the user clicks on it
.SetContentIntent(resultPendingIntent) // Start up this activity when the user clicks the intent.
.SetContentTitle("Button Clicked") // Set the title
.SetNumber(count) // Display the count in the Content Info
//.SetSmallIcon(Resource.Drawable.ic_stat_button_click) // This is the icon to display
.SetSmallIcon(icon)
.SetContentText($"The button has been clicked {count} times."); // the message to display.
// Finally, publish the notification:
var notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(NOTIFICATION_ID, builder.Build());
Here is the same thread, you can take a look:
How to blink notification icon in android? [DONE]

Related

SwiftUI ColorPicker Fails In Background (Menubar) App

Context
I have an app that runs only from the macOS menubar. (The LSUIElement property in info.plist is set to YES).
Instead of a menu, this app shows an NSPopover when the menubar button is clicked. The popover holds an NSHostingView which has an extremely simple SwiftUI view:
struct PopoverContentView: View
{
#State private var color: CGColor = .white
var body: some View
{
ColorPicker(selection: $color) {
Text("Pick a Color:")
}
}
}
Problem
Clicking on the ColorPicker() does not open the macOS color picker window. The UI of the ColorPicker() button changes, to show the "selected" border state but the color-picker window never appears.
However, if I change LSUIElement to be NO and then make the app active by clicking its Dock icon (so that it takes over the menubar), THEN clicking on the ColorPicker() in the popover actually reveals the color-picker window.
Do you know of a way to force macOS to show the color-picker window for a background application?
The answer turned out to be simple. In the AppKit ViewController that opens the popover when the menubar button is clicked (PopoverController, for me), I simply did this:
extension PopoverController: NSPopoverDelegate
{
func popoverWillShow(_ notification: Notification)
{
NSApp.activate(ignoringOtherApps: true)
}
}
The ColorPicker now correctly shows the standard macOS system color panel on click.

Nativescript - How to bring app to foreground when notification is pressed

I'm writing a native Android code to open my app when a notification is pressed. If the app is already opened (whether running in foreground or in background), I want clicking the notification to bring the app to front, without restarting it, so that its state is preserved.
I tried the following code (showing only relevant code):
///////// Create an activity on tap (intent)
const Intent = android.content.Intent;
const PendingIntent = android.app.PendingIntent;
// Create an explicit intent for an Activity in your app
const intent = new Intent(context, com.tns.NativeScriptActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
const pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
///////// Creating a notification
var NotificationCompat = android.support.v4.app.NotificationCompat;
const builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(android.R.drawable.btn_star_big_on)
.setContentTitle(title)
.setContentText(message)
.setStyle(
new NotificationCompat.BigTextStyle()
.bigText("By default, the notification's text content is truncated to fit one line.")
)
.setPriority(NotificationCompat.PRIORITY_HIGH)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.setAutoCancel(true);
///////// Show the notification
notificationManager.notify(NOTIFICATION_ID, builder.build());
But that opened the application without preserving its state.
Following recommendations here, I also tried emulating pressing the app icon from the launcher - so that the app is just brought to the frontground and the Nativescript activity is not recreated.
const packageName = context.getPackageName();
console.log('Package name: ',packageName);
const emulateLaunchByAppIconIntent = context.getPackageManager()
.getLaunchIntentForPackage(packageName)
.setPackage(null)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
const pendingIntent_emulated = PendingIntent.getActivity(context, 0, emulateLaunchByAppIconIntent, 0);
///////// Creating a notification
var NotificationCompat = android.support.v4.app.NotificationCompat;
const builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(android.R.drawable.btn_star_big_on)
.setContentTitle(title)
.setContentText(message)
.setStyle(
new NotificationCompat.BigTextStyle()
.bigText("By default, the notification's text content is truncated to fit one line.")
)
.setPriority(NotificationCompat.PRIORITY_HIGH)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent_emulated)
.setAutoCancel(true);
///////// Show the notification
notificationManager.notify(NOTIFICATION_ID, builder.build());
This indeed made the app come to front, but didn't preserve its state (even if the app was already in foreground - it reloaded the app).
Then I tried pressing a Nativescript application app icon (manually), when the app has just been sent to the background - and I found that it would restart the app, and not just bring it to the foreground.
My question is - why does a Nativescript application behave like this?
How can I make Android just bring the app to foreground and not re-build a new nativescript activity?
The code in the question above, actually works - and does bring the app to the foreground without restarting the app, preserving its state.
The reason the app was restarting, even by clicking the Nativescript application app icon (manually) was related to the development environment.
This happened when I was running the app on a physical device while connected to my Mac running tns run android --bundle, or
Running the app in an emulator (either by running tns run android --bundle or by launching the app directly from the app icon)
Running the app on a physical device that is not connected to the nativescript development environment - showed the real behavior - and the app was brought to the foreground without restarting after clicking the notification.
More info with code examples:
I found that there's no need to launch the app by simulating an icon press using this code
const emulateLaunchByAppIconIntent = context.getPackageManager()
.getLaunchIntentForPackage(packageName)
.setPackage(null)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
const pendingIntent_emulated = PendingIntent.getActivity(context, 0, emulateLaunchByAppIconIntent, 0);
as PendingIntent.FLAG_UPDATE_CURRENT or Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED in the code below, is sufficient to bring app to the foreground without restarting after clicking the notification:
const openActivityIntent = new Intent(context, com.tns.NativeScriptActivity.class);
openActivityIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
const openActivityPendingIntent = PendingIntent.getActivity(context, 0, openActivityIntent, 0);
///////// Creating a notification
const notificationManager = <NotificationManager> context.getSystemService(NotificationManager.class);
var NotificationCompat = android.support.v4.app.NotificationCompat;
const builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSound(soundUri)
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
.setContentTitle(title)
.setContentText(message)
.setStyle(
new NotificationCompat.BigTextStyle()
.bigText('More explaination text if needed. Disabled for now.')
)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(openActivityPendingIntent)
.setWhen(scheduledTime)
.setAutoCancel(true)
.build();
///////// Show the notification
notificationManager.notify(NOTIFICATION_ID, builder);
Hope this helps you if you got into the same issue.

Nativescript swipe gesture not working on Android with ScrollView

I am using a swipe gesture to turn pages. It works great on ios. However, the Android version isn't working where there is a scrollview in play.
I am using Nativescript Pro UI to have a side-drawer. I want to put the gesture on the
Inside of the tkMainContent there is a scrollview.
Swipe doesn't even log a console.log event when I swipe inside the scrollview area. Is there a way to get it to work for Android?
Here is my typescript code:
let cbView = this.contentbody.nativeElement;
cbView.on('swipe', (args: SwipeGestureEventData) =>{
console.log("Swipe Direction: " + args.direction);
let topNextView = cbView.getViewById('topNext');
let topBackView = cbView.getViewById('topBack');
this.playerService.setIsBusyLoading(false);
if(args.direction === 1) {
topBackView.notify({eventName: 'tap', object: topBackView});
}
if(args.direction === 2) {
topNextView.notify({eventName: 'tap', object: topNextView});
}
});
}
As I said I"m not getting Swipe Direction 2 when swiping on Android. If I swipe above where I have the scrollview start, such as in the heading of my document, then it picks up the swipe.

Push sharp Notification with Title and View Close Buttons

I am using push sharp to create remote notification.
But I get the notification with out a title and a View/Close buttons.
I am using a code adapted from
Here
Here is how I create my alert
AppleNotificationAlert alert = new AppleNotificationAlert();
alert.ActionLocalizedKey = "View Alert";
alert.Body = message;
alert.AddLocalizedArgs(new object[] { "title", "Test Title"});
pushBroker.QueueNotification(new AppleNotification() .ForDeviceToken(deviceToken).WithAlert(alert).WithBadge(1).WithSound("sound.caf").WithCustomItem("level", level).WithContentAvailable(1));
I also tried just specifying the Alert body as follows but it does not show View/Close buttons
pushBroker.QueueNotification(new AppleNotification() .ForDeviceToken(deviceToken).WithAlert("Alert Body").WithBadge(1).WithSound("sound.caf").WithCustomItem("level", level).WithContentAvailable(1));
Your code is right. I just spinned it out and it worked ! In your IOS device settings choose your app and then notifications and then change the notification type from banner to an alert and you will get your custom Buttons and Title!

The simplest way to show a toast notification in WP7?

I've been looking for a way to show an offline (not pushed from a server) toast notification on WP7 for a while now. Any ideas?
If you're trying to show the notification while your application is running, you can use the ToastPrompt from the coding4fun toolkit: http://coding4fun.codeplex.com/
If you want to show the notification while your app isn't running, you can use the ShellToast class from a background agent: http://msdn.microsoft.com/en-us/library/microsoft.phone.shell.shelltoast(v=vs.92).aspx
Within a background task, simply call this method:
public static void makeToast(string toastText)
{
//Make a new toast with content "text"
ShellToast toast = new ShellToast();
toast.Title = "Toast Title: ";
toast.Content = toastText;
//toast.NavigationUri = new Uri();
toast.Show();
}

Resources