Xamarin Android Background Notification Custom Sound - xamarin

is it possible to use custom sounds in xamarin android for background notification? I didnt find any examples.

Yep! Here's an example:
var pathToPushSound = $"android.resource://com.your.package/raw/{soundName}";
var soundUri = Android.Net.Uri.Parse(pathToPushSound);
var builder = new NotificationCompat.Builder(_context)
.SetContentTitle("TITLE")
.SetContentText("TEXT")
.SetPriority(1)
.SetSmallIcon(Resource.Drawable.TransparentLogo)
.SetOngoing(true)
.SetSound(soundUri);
builder.Build();
The URI is the path to the resource where your sound file lives, then you set that URI in your NotificationBuilder using the SetSound method.

Related

What to fill into ServerUris property for Windows UWP vpn profile

Microsoft official UWP vpn sample: UwpVpnPluginSample, in CreateAppProfile() part function as bellow.
// Hard coding parameters for the profile
VpnPlugInProfile profile = new VpnPlugInProfile();
...
**profile.ServerUris.Add(new Uri("http://10.137.192.135"));**
var returnedStatus = await agent.AddProfileFromObjectAsync(profile);
...
I don't kown what url to fill into "ServerUris" property, and what content should be provide in that url.
And :
var connectStatus = await agent.ConnectProfileAsync(pluginProfile);
the connectStatus always return Other or CannotFindProfile.

iOS equivalent of accessing Android asset files

I have a Xamarin Android application in which I've bundled up some files as assets and I can access them like this: Android.App.Application.Context.Assets.Open(fileName)).
How would I go about doing this in an iOS application?
The NSBundle class is the closest equivalent with using a BundleResource build action:
Example:
var path = NSBundle.MainBundle.BundlePath;
var filePath = Path.Combine(path, "someDataFile.xml");
var someFileContents = File.ReadAllBytes(filePath);
There are also FromBundle overloads on some classes:
var image = UIImage.FromBundle("myimage.png");

Converting to NotificationCompat breaks SetSmallIcon functionality?

I've been having some trouble moving Notification to the Compat library version: In the main library, I used to just convert an icon to a bitmap (api 23 and up) and do SetSmallIcon(icon) to show a dynamic notification icon.
But the Compat version has only an int argument (I assume it is the resource ID), and I cannot find any information as to how to generate/convert/add my bitmap and/or icon in it.
The bitmap Is basically generated text converted into a bitmap via a canvas which show the most vital information.
My question is: Is there a way to make a class variable into a resource, or get its ID that works like a resoource ID, or some other hack that will allow me to actually add my bitmap that I create at runtime?
You can use this code. Refer the line where icon is being used
var notificationBuilder = new NotificationCompat.Builder(this)
.SetSmallIcon(Resource.Drawable.NotifIconSis).SetColor(Android.Graphics.Color.Rgb(33, 150, 243))
.SetContentTitle(user.Organization)
.SetSubText(user.ModuleName).SetStyle(new NotificationCompat.BigTextStyle().BigText(user.BodyText))
.SetContentText(user.BodyText)
.SetAutoCancel(true)
.SetContentIntent(pendingIntent)
.Build();
var notificationManager = NotificationManagerCompat.From(Application.Context);
//var notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
//var mp = MediaPlayer.Create(ApplicationContext, notification);
//mp.Start();
//notificationManager.Notify(redomId, notificationBuilder);

Is it possible to launch native apps using Microsoft bot framework?

I am creating a Cortana skill on the Cortana canvas, I have a button.
I wanted to know if it possible to have an 'imback' type of button to open a webpage.
Ye, for example
var message = context.MakeMessage() as IMessageActivity;
message.ChannelData = JObject.FromObject(new
{
action = new { type = "LaunchUri", uri = "skype:echo123?call" }
});
await context.PostAsync(message);
this code will start a call with echo123 user on skype
Reference: https://learn.microsoft.com/en-us/cortana/tutorials/bot-skills/bot-entity-channel-data
You can supply an openUrl to a card action, or even use ChannelData to send a LaunchUri command, deep linking to an application. (I haven't tried this, but I assume 'http://websitename.com' will launch in the Cortana host platform's default browser.)
activity.ChannelData = new {
action = new { type = "LaunchUri", uri = "http://websitename.com"}
};

How do I change the "NativeHost" string on Windows Phone 7 webclient requests

I use WebClient for most of my requests from my WP7 app.
According to Google App Engine logs, the UserAgent is "NativeHost".
I would like to use appname, appversion + phone instead.
Is it possible to change this string when using a WebClient, or a GZip WebClient?
Okay, current working solution:
var headers = new WebHeaderCollection();
// http://dotnetbyexample.blogspot.fi/2011/03/easy-access-to-wmappmanifestxml-app.html
var am = new Util.AppManifest(); // gets appmanifest as per link above
var maker = Microsoft.Phone.Info.DeviceStatus.DeviceManufacturer;
var model = Microsoft.Phone.Info.DeviceStatus.DeviceName;
headers["user-agent"] = string.Format("{0} {1} {2} AppVersion {3}",
maker, model, "WP7.5", am.Version);
WebClient c = new WebClient();
c.Headers = headers;
Now, let's see how much info I can get on what make of phone the app is running on...
Yes, you will have to manually specify the UserAgent string on the WebClient class.
WebClient client = new WebClient ();
client.Headers.Add ("user-agent", "My App; V=2.1, PhoneType");
Obviously you will need to specify/derive the values you want to use in the UserAgent (AppName, Version and Phone).

Resources