Android Notification not fired with no small icon or has no message if small icon set - android-notifications

I'm creating a notification as per the code below. When I run it all I get across the top of the device (avd) is the small icon with no text (I'd have thought 'From Neil' to be displayed) but the notification is full and complete when I drag down to show the notification page.
However, if I comment out the setSmallIcon the notification isn't even created and nothing happens. What's going wrong?
Thanks.
private void doNotification() {
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setContentTitle("From Neil");
b.setContentText("Hello email from neil");
b.setSmallIcon(android.R.drawable.ic_dialog_alert);
//do not want an intent fired
pIntent = PendingIntent.getActivity(this, 0, new Intent(),
PendingIntent.FLAG_UPDATE_CURRENT);
b.setContentIntent(pIntent);
Notification n=b.build();
n.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
}

What you're seeing is correct behavior: The status bar simply adds your small icon to the notification area. You're probably thinking of the tickerText, which if set will cause some text to scroll by when the notification is first posted. Call setTicker("From Neil"), or perhaps more informatively "Neil: Hello email from neil" on your Notification.Builder.

Related

alarm manager local notification - how to cancel specific notification?

i am scheduling my customer through alarm manager to get notification on time that i set. Now everything is working fine i get local notification, but i am not able to cancel that specific notification its keep coming after every minute.
here is my viewmodel code PCL
for cancel :
void Switch_Toggled()
{
if (NotificationONOFF == false)
{
MessageText = string.Empty;
SelectedTime = DateTime.Now.TimeOfDay;
SelectedDate = DateTime.Today;
DependencyService.Get<ILocalNotificationService>().Cancel(Convert.ToInt32(Settings.Customerid));
}
}
for save alarm
DependencyService.Get<ILocalNotificationService>().LocalNotification("Local Notification", MessageText, Convert.ToInt32(Settings.Customerid) , selectedDateTime);
code in xamarin.android
for canel:
public void Cancel(int id)
{
var intent = CreateIntent(id);
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, Convert.ToInt32(_randomNumber), intent, PendingIntentFlags.Immutable);
var alarmManager = GetAlarmManager();
alarmManager.Cancel(pendingIntent);
var notificationManager = NotificationManagerCompat.From(Application.Context);
notificationManager.CancelAll();
notificationManager.Cancel(id);
}
i am sending customer id to cancel but its not working.
According to your description, you have xamarin.forms sample, sending Local Notification With A Repeat Interval using Alarm Manager, like this sample:
https://www.c-sharpcorner.com/article/how-to-send-local-notification-with-repeat-interval-in-xamarin-forms/
There are two solution, but I don't know what you are.
Solution 1:
When you run project and set one alarm Manager to send local notification with a repeat interval, this app is background now.
When time is up, you go into this background app, you find switch is unselect, but alarm still exist. So you want to cancel this alarm when you go into this app, am I right?
If yes, I suggest you can call Switch_Toggled() event in LocalNotificationPageViewModel constructor.
public LocalNotificationPageViewModel(){
SaveCommand = new Command(() => SaveLocalNotification());
Switch_Toggled();
}
Solution 2:
If you run project and set one alarm Manager to send local notification with a repeat interval, and this app still active, now time is up, you can unselect switch to cancel this alarm, it works fine.

Xamarin.Auth Google not auto close when done login

I follow guide enter link description here
I have a issue when I done login my google account it show toast
And browser not auto close to back my.
Thanks!
In you CustomUrlSchemeInterceptorActivity page replace inside OnCreate.
base.OnCreate(savedInstanceState);
global::Android.Net.Uri uri_android = Intent.Data;
Uri uri_netfx = new Uri(uri_android.ToString());
// load redirect_url Page
AuthenticationState.Authenticator.OnPageLoading(uri_netfx);
var intent = new Intent(this, typeof(MainActivity));
intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
StartActivity(intent);
this.Finish();
return;
This is the warning message shown in the toast.
We can make it null by adding a piece of code in MainActivity just after initializing Xamarin.Auth.
CustomTabsConfiguration.CustomTabsClosingMessage = null;
And for closing the CustomTab login screen and navigating back to your app, set the LaunchMode of your Custom URL activity to SingleTask.
LaunchMode = LaunchMode.SingleTask
Hope this will help.
Worked for me as well in avoiding the toast:
global::Xamarin.Auth.CustomTabsConfiguration.CustomTabsClosingMessage = null

how to replace a fragment with another fragment in android 4.0.4

I try to replace a fragment with another fragment by pressing a button.
This is Successfull on android 4.1.2,but is failed on android 4.0.4
The code is:
if(f13!=null)
{
transaction.remove(f13);
transaction.replace(R.id.place,f10,"f10");
transaction.commit();
}
where f13 and f10 are fragments.
I added this statment:
transaction.addBackstack(null);
transaction.replace(R.id.place,f10,"f10");
transaction.commit();
The app is running,but when i click back button in my mobile to return f13, the fragment f10 show under f13.
I want when i am clicking back button the app close.
Let me be clear, you want to manage your backstack so that when you hit the Back button, your app should close. For that issue, use popBackStack method of FragmentManager class. Code example using your pseudo code:
Fragment newFragment = new ExampleFragment(); // "f10" fragment
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.place,f10, newFragment);
transaction.commit();
manager.popBackStack();
If you want to remove all items in the stack:
manager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
I never tried POP_BACK_STACK_INCLUSIVE. Pls keep us posted. Good luck, Tommy Kwee

ios8 customizing interactive push notifications

I'm trying to find an updated doc that includes any info / code samples on the new interactive push notifications. The guide I found on Local & Remote Push Notifications still shows the payload size is 256 bytes. My understanding is that in ios8 that limit has been raised to 2k.
I'm also trying to find documentation on how to add custom buttons to make my notifciations interactive. I don't see very much in the push notification programming guide.
How do I setup a category to add custom buttons with colors? Any documentation on this would be useful.
You can create interactive notifications by defining the action buttons in iOS8.
Create UIMutableUserNotificationAction buttons.
Then Create UIMutableUserNotificationCategory and group above actions into category.
Add all categories into set.
Create UIUserNotificationSettings with this category set.
Register notifications with this settings
Add category field in push payload and send notification
Please find below the sample code:
- (void) registerRemoteNotificationWithActions{
//1. Create action buttons..:)
UIMutableUserNotificationAction *shareAction = [[UIMutableUserNotificationAction alloc] init];
shareAction.identifier = #"SHARE_IDENTIFIER";
shareAction.title = #"Share";
shareAction.activationMode = UIUserNotificationActivationModeForeground;
shareAction.destructive = NO;
shareAction.authenticationRequired = YES;
//2. Then create the category to group actions.:)
UIMutableUserNotificationCategory *shareCategory = [[UIMutableUserNotificationCategory alloc] init];
shareCategory.identifier = #"SHARE_CATEGORY";
[shareCategory setActions:#[shareAction] forContext:UIUserNotificationActionContextDefault];
[shareCategory setActions:#[shareAction] forContext:UIUserNotificationActionContextMinimal];
//3. Then add categories into one set..:)
NSSet *categories = [NSSet setWithObjects:shareCategory, nil];
//4. Finally register remote notification with this action categories..:)
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
Sample payload format :
{
"aps": {
"badge": 1,
"alert": "Hello world!",
“category”: “SHARE_CATEGORY”
}
}
And handle the actions using the following method :
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
if ([identifier isEqualToString:#"SHARE_IDENTIFIER"] ){
}
}
You can check this link for more info.
This is a tutorial I found in youtube for custom action push notification. It is done in swift.
https://www.youtube.com/watch?v=Yh3lLpV1k_Y

How to switch to a different window using selenium webdriver java?

I am trying to switch to a New window which gets displayed when I click on the Debt Pricing Template. But I am unable to do that as a result of which I am not able to proceed with further scripting... The problem is I am not able to know what should I pass in the switchTo.window() because Pricing Approval Gateway window displays and following is the HTML for the new window:
<*h1 class="pageType noSecondHeader">Pricing Approval Gateway<*/h1>
Following is the code:
LoginPage2.driver.findElement(By.linkText("TEST ORG")).click();
System.out.println("3.Select Dept pricing template button from the organization detail page.");
if(LoginPage2.driver.findElement(By.name("debt_pricing_template")).isDisplayed())
System.out.println("User should able to navigate to Dept pricing template and template display few question, user have answer these question for further navigation.");
LoginPage2.driver.findElement(By.name("debt_pricing_template")).click();
LoginPage2.driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
LoginPage2.driver.switchTo().window("bPageTitle");
Please advise what needs to be added?
I never used it because in my tests I am not using any new windows, but this should help:
Set<string> handlers = driver.getWindowHandles();
if (driver.getWindowHandles().size()>= 1){
for(String handler : handlers){
driver.switchTo().window(handler);
if (driver.getElement(By.tagName("h1")).contains("Pricing")){
System.out.println("Get focus on Popup window");
break;
}
}
}
else System.out.println("No windows founded!");
I am not quite sure with the h1 approach. So if it does not help, try before opening new window storing current window to String:
String mainWindow = driver.getWindowHandle();
Then click the link (or do something else as you are doing now) to open new window. Then to switch to the new window:
Set<string> handlers = driver.getWindowHandles();
for (String handler : handlers){
if (!handler.equals(mainWindow)){
driver.switchTo(handler);
break;
}
}
And then to switch back to original window just do:
driver.switchTo(mainWindow);
Ofcourse the driver variable is expected live instance of
WebDriver
driver.findElement(By.linkText("Go to Billing Summary")).click();
driver.findElement(By.linkText("01 Mar 2016")).click();
Thread.sleep(5000);
driver.findElement(By.linkText("AMS TAX")).click();
driver.findElement(By.linkText("00842")).click();
Set<String> instancewindow= driver.getWindowHandles();
Iterator<String> it = instancewindow.iterator();
String parent =it.next();
String child = it.next();
driver.switchTo().window(child);
driver.switchTo().frame("modalSubWindow");
driver.findElement(By.linkText("View More Vehicle Details>>")).click();
driver.switchTo().window(parent);

Resources