How can I display a custom notification message with Malcom Android SDK? - android

I would like to display the notification message inside the app but not as it is displayed by the Malcom SDK by default, which displays a predefined dialog when I open the app.
Can I modify the default behavior of the library to show the message my own way?
Thank you very much

In the latest Malcom Android SDK 2.0.5 things have changed. Now you can use a NotificationHandler if you want to handle the notification in a custom way.
See the documentation about that:
https://github.com/MyMalcom/malcom-lib-android/blob/master/doc/Notifications.md#check-notification

You can avoid the default behavior using the moduleNotificationsRegister() method with false in the showAlert param.
Then, to get the notification's message, you just need to add this on the onCreate() of your launch Activity:
String message = null;
if(getIntent()!=null && getIntent().getExtras()!=null){
message = (String)getIntent().getExtras().get(MCMNotificationModule.ANDROID_MESSAGE_KEY);
}

Related

How to open Android Outlook application from an external one

I'm currently developing an Android application in order to display home screen widgets. Those ones are related to Microsoft Outlook (Events + Messages) in order to show incoming events and unread new messages in a kind of dynamic tiles.
The Msal graph library helps me a lot to authenticate and retrieve in formations which contains an identifier for each event / message results
But now I want to know if the outlook application is installed on the user device and if there is a way to open Outlook when the user click on the widget. Moreover if the user can open the corresponding clicked event or message with the identifier.
For example the Event widget currently displaying a birthday event. The user click on it. Then it opens Outlook and display directly that birthday event.
Regards
I don't think this is officially documented somewhere. But here's what you can do to find out about it.
You can list all Microsoft applications installed on your device...
val packages = context.packageManager
.getInstalledApplications(PackageManager.GET_META_DATA)
for (info in packages) {
if(info.packageName.startsWith("com.microsoft", true)){
Log.d("package name:" + info.packageName)
Log.d("Launch Activity: " + context.packageManager.getLaunchIntentForPackage(info.packageName))
}
}
Take a note of the "launch intent" displayed in the LogCat. You can use that to launch Outlook. Just make sure you don't hard-code those values because Microsoft can change those values at any point, for example the activity class can change. So, instead of doing this...
context.startActivity(
Intent().apply {
action = Intent.ACTION_MAIN
addCategory(Intent.CATEGORY_LAUNCHER)
setPackage("com.microsoft.office.outlook")
component = ComponentName("com.microsoft.office.outlook", "com.microsoft.office.outlook.MainActivity")
}
)
Do this...
context.startActivity(
Intent().apply {
action = Intent.ACTION_MAIN
addCategory(Intent.CATEGORY_LAUNCHER)
component = ComponentName(
outlookLaunchIntent?.component?.packageName,
outlookLaunchIntent?.component?.className
)
setPackage(outlookLaunchIntent.package)
}
)
Also, remember that getLaunchIntentForPackage and component can return null, so make sure you check for null values properly
I am relaying a suggestion from a couple of internal folks:
Please try to open the event using one of the following URLs:
ms-outlook://events/open?restid=%s&account=test#om.com (if you have a regular REST id)
ms-outlook://events/open?immutableid=%s&account=test#om.com (if you are using an immutable id)
Since immutable IDs are still in preview stage in Microsoft Graph, and customers should not use preview APIs in their production apps, I think option #1 applies to your case.
Please reply here if the URL works, or not, and if you have other related questions. I requested the couple of folks to keep an eye on this thread as well.
Well, i managed to open the outlook android application with the help of your code #Leo. As im not developping with Kotlin, ill post the JAVA code below :
Intent outlookLaunchIntent = context.getPackageManager().getLaunchIntentForPackage("com.microsoft.office.outlook");
if (outlookLaunchIntent != null) {
context.startActivity(outlookLaunchIntent );
}
Below code to open event/message in a web browser provided by webLink property of the graph API. (I only test for event and the url provided not working. Ill post a new issue on StackOverFlow for that but you already see the issue over there : https://github.com/microsoftgraph/microsoft-graph-docs/issues/4203
try {
Intent webIntent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(calendarWebLink));
webIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(webIntent);
} catch (RuntimeException e) {
// The url is invalid, maybe missing http://
e.printStackTrace();
}
However im still stuck on the decicive goal of my widget item click which is to open the relative event/email in the Microsoft Outlook Android application.
Microsoft Outlook Android app contains widgets which can achieve what im looking for. So i wonder if it is possible to list its broadcast receivers.
The best thing i found is an old manifest for that app but it doesnt help me.
https://gist.github.com/RyPope/df0e61f477af4b73865cd72bdaa7d8c2
Hi may you try to open the event using one of the url:
ms-outlook://events/open?restid=%s&account=test#om.com (If the
user is having rest id)
ms-outlook://events/open?immutableid=%s&account=test#om.com (If
the user is having immutable id)

Initialize Instabug without showing hint prompt

I need to initialize Instabug in my Android application but do now want it to show the hint prompt saying "Shake your device etc." when user just opened the app. Instead I want to show that after user has already logged in.
I initialize Instabug with the following code:
new Instabug.Builder(this, instaKey)
.setInvocationEvent(InstabugInvocationEvent.SHAKE)
.setShakingThreshold(1100)
.build();
So is there a way to disable that hint prompt in a first place place?
I tried to set .setPromptOptionsEnabled(false, false, false) but it seems this does not what I need.
I cannot find any documentation about this.
You can disable showing it by setting false to setIntroMessageEnabled(boolean) API example:
new Instabug.Builder(this, instaKey)
.setInvocationEvent(InstabugInvocationEvent.SHAKE)
.setShakingThreshold(1100)
.setIntroMessageEnabled(false)
.build();
and then whenever the User is logged in you can show the intro message by invoking it manually example:
Instabug.showIntroMessage();
And by the way the .setPromptOptionsEnabled(true, true, true) is used for controlling prompt Options visibility [talk to us, report a bug, send a feedback] as described in the official docs here: http://docs.instabug.com/docs/enabled-features

Capturing click event no redirect to app

I want to capture notification click event without redirecting to app it should stay on notification tray after clicking. App state could be foreground or background. Just like music app do in next, play and pause event.
Used Cordova Plugin: https://github.com/katzer/cordova-plugin-local-notifications
Depending on what you're trying to do, you may have to tweak the plugin a bit.
To keep the notification in place, I assume you've already set ongoing : true while you're scheduling it ?
If you're looking at the Android platform, you could try something like:
1) Install the plugin to a new folder or temporary project and take a look at "ClickActivity.java"
1.a) Remove the existing version of the plugin from your project
2) Modify the code to suppress or tweak the call as you need it:
public class ClickActivity extends de.appplant.cordova.plugin.notification.ClickActivity {
/**
* Called when local notification was clicked by the user.
*
* #param notification
* Wrapper around the local notification
*/
#Override
public void onClick(Notification notification) {
LocalNotification.fireEvent("click", notification);
super.onClick(notification);
if (notification.getOptions().isOngoing())
return;
String event = notification.isRepeating() ? "clear" : "cancel";
LocalNotification.fireEvent(event, notification);
}
3)Reinstall the version of the plugin from your custom directory
cordova plugin add de.appplant.cordova.plugin.local-notification --searchpath your-custom-path
For what I needed, I just suppressed the original calls - tacky, I know, but all I needed was a notification. Like you said, I didn't want it pulling the app to the foreground.
Will that do what you need ?

How to load a custom location in Cordova+Ember when user click on system notification?

I have an app made in Cordova using Ember framework.
When I receive a system notification I want to open a custom location based on id that notification send me. Notification call a method out of Ember route/controller system.
How I can call a ember router to load a custom location based on notification id if the method are not inside Ember managed code?
Regards.
You can check Ember.Instrumentation module which can be used for such scenarios.
http://emberjs.com/api/classes/Ember.Instrumentation.html
To send an event from outside Ember:
Ember.Instrumentation.instrument("eventGroup.notificationOccured", {id: 'id_which_you_got_from_notification'});
To subscribe the event inside Ember code:
Ember.Instrumentation.subscribe("eventGroup.notificationOccured", {
before: function(id, timestamp, payload) {
// Here you can do routing
},
after: function() {}
});
The subscribe can be inside Ember App codebase where you can transitionTo the route depending on the id.
You can probably put the subscribe code snippet in your IndexRoute's setupController or inside any controller method which would have already executed whenever notification arrives.
In case you want to put the code in controller then redirection can happen via controller.transitionToRoute(routeName);

phonegap android local notification cancelAll not working

hi I am using phonegap local notification plugin in my android project.
notification are working great.
i can delete a notification with ID
but in my app i have to delete all notification option, for which this plugin gives a method to cancelAll notification.
which is:-
plugins.localNotification.cancelAll();
but this is not working.
i am using this plugin from here
https://github.com/phonegap/phonegap-plugins/tree/master/Android/LocalNotification
any help will be appreciated.
I think this might be the answer to this one. As it says in the description of the cancelAllNotifications() method (LocalNotification.java line 124):
Android can only unregister a specific alarm. There is no such thing as cancelAll. Therefore we rely on the Shared Preferences which holds all our alarms to loop through these alarms and unregister them one by one.
However, take a look at the code where the cancelAllNotifications() method is called (line 59):
} else if (action.equalsIgnoreCase("cancelall")) {
unpersistAlarmAll();
return this.cancelAllNotifications();
}
Here's what unpersistAlarmAll() looks like (line 181):
private boolean unpersistAlarmAll() {
final Editor alarmSettingsEditor = this.cordova.getActivity().getSharedPreferences(PLUGIN_NAME, Context.MODE_PRIVATE).edit();
alarmSettingsEditor.clear();
return alarmSettingsEditor.commit();
}
What's happening is that the alarmIds are being cleared from sharedPreferences before cancelAllNotifications() is called, effectively leaving no alarms to be canceled.
I'm not sure where the best place to move the call to unpersistAlarmAll() is, and I'd be happy to get some suggestions. In the meantime I have moved it to within cancelAllNotifications(), after the result returned from alarm.cancelAll(alarmSettings) is tested (line 133), like so:
if (result) {
unpersistAlarmAll();
return new PluginResult(PluginResult.Status.OK);
So far this seems to be working fine. Perhaps another way to do this would be to scrap the whole unpersistAlarmAll() method and instead call unpersistAlarm(String alarmId) (line 168) after each individual alarm is successfully canceled.
Depending on what you are trying to do, you could use the "Statusbar notificaiton". This plugin will enable you to put message on the android status bar.
https://github.com/phonegap/phonegap-plugins/tree/master/Android/StatusBarNotification

Categories

Resources