I'm specific about Outlook here because there is a way to do this with the native Windows Mail app. The problem is that I need to do this with Outlook which isn't a native UWP Windows app.
I'm aware of the EmailManager API that exists for UWP. But, as it's stated in the docs, it's not possible to use it with a HTML body.
My current workaround for the native Mail app uses the DataTransfer UWP API. With it I can open the Windows 10 share dialog:
var dtm = DataTransferManager.GetForCurrentView();
dtm.DataRequested += WindowsShare_DataRequested;
DataTransferManager.ShowShareUI();
And in the data request event I put the HTML body into the request data like this:
var request = args.Request;
var deferral = request.GetDeferral();
try
{
var htmlBody = HtmlFormatHelper.CreateHtmlFormat(<HTML body here>);
request.Data.SetHtmlFormat(htmlBody);
}
catch (Exception ex)
{
...
}
finally
{
deferral.Complete();
var dtm = DataTransferManager.GetForCurrentView();
}
This works but the share dialog only shows native apps like Windows Mail.
Related
I have a client that wants to have a local notification that the user can not dismiss and will be there until the app is closed. I can get this to work in android but not in iOS. I am working in xamarin and have had to break out of the pcl to accomplish this and the notifications in general. Is this something that can be accomplished(does apple allow this)? Or is a widget extension what I am in need of creating?
You can present a local notification on top of your running app
by implementing IUNUserNotificationCenterDelegate and calling the WillPresentNotification completionHandler with the UNNotificationPresentationOptions.Alert option.
But you can not prevent the user from dismissing it, thus is would be cleared from the Notification Center.
I'm not sure what information you are trying to show in the "permanent" notification, but it sounds like a Today View Widget is something you should look at. The downside of course is Today widgets require that the user manually adds the widget to the Today view and depending upon your needs that they enabled it for lock screen usage.
Here is how you would do a local notification and make it present itself on top of your app....
Implement IUNUserNotificationCenterDelegate:
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
completionHandler.DynamicInvoke( UNNotificationPresentationOptions.Alert );
}
Assign the UNUserNotificationCenter Delegate:
UNUserNotificationCenter.Current.Delegate = this;
Send a local notification:
var unAuthorizationOptions = UNAuthorizationOptions.Alert & UNAuthorizationOptions.Badge & UNAuthorizationOptions.Sound;
var authReply = await UNUserNotificationCenter.Current.RequestAuthorizationAsync(unAuthorizationOptions);
if (authReply.Item1 == true) // Xamarin.iOS does not label the tuple members ;-( (granted, error)
{
var content = new UNMutableNotificationContent
{
Title = "Local Notification",
Subtitle = "By SushiHangover",
Body = "StackOverflow rocks",
Badge = badgecount
};
var request = UNNotificationRequest.FromIdentifier("SushiHangover", content, null);
await UNUserNotificationCenter.Current.AddNotificationRequestAsync(request);
}
In my project I want to read the particular SMS message and delete that message it possible in universal windows phone 10..
Is is posible using Chat Message Access in manifest file?
You can use the chat messages api to access the SMS messages of your device. Using the ChatMessageStore you will be able to create/delete the messages but it might not be what you really want. The chat message api is more designed to create messaging application like WhatsApp.
If the message you want to receive is an app-directed message you can intercept it before it reaches the ChatMessageStore. The universal windows platform is exposing a new (restricted) API to intercept the messages before they reach the store using custom filtering rules. You can have a look at this sample. It is using the newest SmsMessageReceivedTrigger background task trigger.
Since this API is restricted, you will have to request the autorisation to use from Microsoft before being able to publish such an app to the store
Here is a sample about how to use the SmsMessageReceivedTrigger with the background task entry point and registration
public async void Run(IBackgroundTaskInstance taskInstance)
{
var smsDetails = taskInstance.TriggerDetails as SmsMessageReceivedTriggerDetails;
// consume sms
var from = smsDetails.TextMessage.From;
var body = smsDetails.TextMessage.Body;
// we acknoledege the reception of the message
smsDetails.Accept();
}
static IBackgroundTaskRegistration Register()
{
var taskNameAndEntryPoint = typeof(SmsInterceptor).FullName;
var task = BackgroundTaskRegistration.AllTasks.Values.FirstOrDefault(x => x.Name == taskNameAndEntryPoint);
if(task != null) return task;
var filterRule = new SmsFilterRule(SmsMessageType.App);
filterRule.SenderNumbers.Add("111111111");
filterRule.SenderNumbers.Add("222222222");
var filterRules = new SmsFilterRules(SmsFilterActionType.AcceptImmediately);
filterRules.Rules.Add(filterRule);
var taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = taskNameAndEntryPoint;
taskBuilder.TaskEntryPoint = taskNameAndEntryPoint;
taskBuilder.SetTrigger(new SmsMessageReceivedTrigger(filterRules));
return taskBuilder.Register();
}
Since it is using a restricted API, you will have to add the following restricted capability to your appx manifest
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:r="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp r">
<Capabilities>
<r:Capability Name="cellularMessaging" />
</Capabilities>
</Package>
You will find a complete sample here
If you want to use the ChatMessageStore API, you can have a look at this sample which should be a good start.
I am developing a WP8.1 app, when I try using ShareMediaTask to share a picture it shows me a list of apps where I will share the picture. Facebook, Twitter and other apps like Whatsapp are not included in the list; it shows me only share to OneNote. Taking note that I debug from device with Facebook and Twitter installed on it.
If someone could help me thankfully.
This is my simple code :
ShareMediaTask shareMediaTask = new ShareMediaTask();
shareMediaTask.FilePath = fileName;
shareMediaTask.Show();
Do I have to add something ?!
You'll want to take a look at Sharing content for Windows Runtime apps. Sharing is different between Silverlight and Runtime apps.
Here is a basic sample on how to share files:
When you are ready to share:
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareStorageItemsHandler);
And then populating the data:
private async void ShareStorageItemsHandler(DataTransferManager sender,
DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Share StorageItems Example";
request.Data.Properties.Description = "Demonstrates how to share files.";
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
StorageFile logoFile =
await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(logoFile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
Only apps that implement sharing will show up in the list. Currently Twitter and Facebook have not released an app that implements sharing.
For more information of receiving shared content, see this doc.
I am developing a Windows8 Metro App using c# xaml and I have to send the app link as an e-mail to someone using the share contract.
What I have tried is
private void RegisterForShare()
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.ShareLinkHandler);
}
private void ShareLinkHandler(DataTransferManager sender, DataRequestedEventArgs e) {
DataRequest request = e.Request;
request.Data.Properties.Title = "Sharing My Link";
request.Data.Properties.Description = "Add a link (URI) to share";
var _Uri = new Uri("https://login.live.com/");
Windows.System.Launcher.LaunchUriAsync(_Uri);
}
And also,
void App_QuerySubmitted(Windows.ApplicationModel.DataTransfer.DataTransferManager sender, Windows.ApplicationModel.DataTransfer.DataRequestedEventArgs args)
{
App.SettingsFlyout.Equals(args.Request, ApplicationExecutionState.Running);
}
But it works in a way where the specified link just opens and not a feature where the email of the link could be sent to soemone.
Any suggestions or solutions please?
While you can use the share charm to let the user sent text if you want to the user to definitely send email (as opposed to Twitter / Facebook) then you should use the mailto protocol.
await Launcher.LaunchUri(new Uri("mailto://test#address.com?subject=email"));
There's no built-in API for sending emails. Microsoft recommend to use share charm to send the email. Though if you want to send email via you need to go for commercial library called Mail.dll
Try this
var mailto = new Uri("mailto:?to=recipient#example.com&subject=Your subject&body=Your text");
await Windows.System.Launcher.LaunchUriAsync(mailto);
I am developing an application (Windows Store) to access SkyDrive content. To login to Live I am using the below code snippet.
try
{
var uri = "https://login.live.com/oauth20_authorize.srf";
var authorizeUri = new StringBuilder(uri);
authorizeUri.AppendFormat("?client_id={0}&", "000000004C0DE9B7"); //This is my Client ID
authorizeUri.AppendFormat("scope={0}&", "wl.signin");
authorizeUri.AppendFormat("response_type={0}&", "code");
authorizeUri.AppendFormat("redirect_uri={0}", ("")); //I don't have redirect URL.
LiveAuthClient auth = new LiveAuthClient(authorizeUri.ToString());
LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
if (loginResult != null)
{
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
this.txtStatus.Text = "Signed in";
}
}
}
catch (LiveAuthException exception)
{
this.txtStatus.Text = exception.Message+ " Error";
}
}
With this I am always getting the below exception:
"The app is not configured correctly to use Live Connect services. ..."
I tried to get Package identity for my Windows Store app. Since, it is taking me to paid registration page, I have not done that. [ https://appdev.microsoft.com/StorePortals/en-us/account/signup/start ]
I am not sure if that is the cause for the problem.
I have also tried this link to register my app. This too is not working.
https://manage.dev.live.com/build?wa=wsignin1.0
I appreciate if someone could help me in resolving this issue.
For a Windows Store app to use Live Connect APIs, it needs to have a Package Identity which you can only get my registering as a Windows Store Developer.
Windows Phone, iOS and Android apps need only the Client ID. All other apps need Client ID, Client Secret and Redirect Domain.
That is why it's not working. For more information, see: http://msdn.microsoft.com/en-us/library/live/hh826541.aspx
Hope that helps.