Sharing from Windows Phone 8 - c#

I am working on a Windows Phone 8 app and am trying to share content through the DataTransferManager. The Windows API documentation says it is supported in Windows Phone but when the DataTransferManager.GetForCurrentView() function is called I get an exception
System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=Specified method is not supported.
Source=Windows
InnerException:
I have been searching for an answer and can't find anyone else with the same issue, any help would be appreciated. All samples on this topic seem to be Windows 8 specific, but Phone 8 does include these functions. Here's sample code from my app.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(dataTransferManager_DataRequested);
}
private void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Share Text Example";
requestData.Properties.Description = "An example of how to share text.";
requestData.SetText("Hello World!");
}
private void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
DataTransferManager.ShowShareUI();
}
Again, the exception is shown when the page loads on the DataTransferManager.GetForCurrentView(); function so it doesn't get to the other lines, but included them anyway. I've tried adding/removing permissions and assemblies but must be missing something. I've also tried putting the function in different events (such as the onTap function) with the same results.
If anyone is interested in trying this on their own here is some documentation:
DataTransferManager
DataRequested
DataPackage
GetForCurrentView()
UPDATE
Although it may not be the best solution given the context of this question, I am implementing the Email/Sms/Link Tasks as described below rather than using the DataTransferManager. It seems that DataTransferManager may not be accessible in WP8 and although the tasks will take a number of different functions they seem to be the best way to perform the intended functionality.

I think I have found most of what I was looking for with Launchers... Rather than just using the Windows 8 general sharing functionality I can be specific with Tasks/Launchers.
Unfortunately it doesn't have as many sharing options as the charm does, I will be implementing several functions for email/sms/social but so far this is the best solution.
Here are the functions that I will be implementing
private void ShareLink(object sender, System.Windows.Input.GestureEventArgs e)
{
ShareLinkTask shareLinkTask = new ShareLinkTask()
{
Title = "Code Samples",
LinkUri = new Uri("http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff431744(v=vs.92).aspx", UriKind.Absolute),
Message = "Here are some great code samples for Windows Phone."
};
shareLinkTask.Show();
}
private void ShareEmail(object sender, System.Windows.Input.GestureEventArgs e)
{
EmailComposeTask emailComposeTask = new EmailComposeTask()
{
Subject = "message subject",
Body = "message body",
To = "recipient#example.com",
Cc = "cc#example.com",
Bcc = "bcc#example.com"
};
emailComposeTask.Show();
}
private void ShareSMS(object sender, System.Windows.Input.GestureEventArgs e)
{
SmsComposeTask smsComposeTask = new SmsComposeTask()
{
Body = "Try this new application. It's great!"
};
smsComposeTask.Show();
}
Ref:
Launchers for Windows Phone
Share Link Task

According to my API reference, DataTransferManager is reserved for native apps only. Windows Phone API Quickstart.

Have you tried using the fully qualified method? It would be something like this:
DataTransferManager dataTransferManager = indows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
Also, make sure your target is Windows Phone 8.

The Windows 8 Share Contract isn't supported on WP8. There isn't even a Share charm on WP8. Why are you trying to use the DataTransferManager?
Instead of using the Share Contract, most usecases can work just fine with WP8 app2app custom protocols and file extensions. Using WP8 app you can transfer files and data across apps. Althrough the standardized contract of the Share Contract is gone, apps can create their own contracts using custom protocols and file extensions.
Here for example you can learn more about a real-world 3rd party implementation of Nokia Music custom protocols.

Related

Accessing AnswerWizard of Outlook from C# WinFormsApp

Is there any possibility to access the automatic answering function of Outlook out of my humble WinFormsApp (C#)? To activate it directly out of my App for the time of vacations e.g.
Really appreciate any ideas!
That's what i have but C# doesn't accept the last line:
private void Btn_Click(object sender, EventArgs e)
{
var OLApp = new Outlook.Application();
object OLAssistent = OLApp.AnswerWizard();
}
First of all, the AnswerWizard property is deprecated. Here is what MSDN documentation states:
This object, member, or enumeration is deprecated and is not intended to be used in your code.
Instead, you may consider using EWS if you deal with Exchange accounts or Graph API in case of Office365 accounts configured in Outlook.

What is the proper way of using the Windows.Media.Miracast namespace?

I am looking into screen casting through Miracast in an application but am unsure of how to use the Windows.Media.Miracast namespace. Limited information exists on the internet due to the short age of the Windows 10 1903 update that the namespace comes as a part of.
The only thing I've found so far is this documentation.
My question is does anybody know what the proper way of using this namespace is? Any examples or resources found online would be a great help.
Cheers.
These three sample projects demonstrate various MiraCast source apis that can be used from UWP applications. Not sure about outside UWP.
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BasicMediaCasting
https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/AdvancedCasting
https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/Projection
I'm personally using code like the following, on Windows IoT Core, to cast my whole screen
Scan for devices:
miraDeviceWatcher = DeviceInformation.CreateWatcher(CastingDevice.GetDeviceSelector(CastingPlaybackTypes.Video));
miraHandlerAdded = new TypedEventHandler<DeviceWatcher, DeviceInformation>(async (watcher, deviceInfo) =>
{
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
//Add each discovered device to our listbox
CastingDevice addedDevice = await CastingDevice.FromIdAsync(deviceInfo.Id);
var disp = new CastingDisplay(addedDevice); //my viewmodel
MiraDevices.Add(disp); //ObservableCollection
});
});
miraDeviceWatcher.Added += miraHandlerAdded;
Connect to selected device:
public async Task StartCasting(CastingDisplay castee)
{
//When a device is selected, first thing we do is stop the watcher so it's search doesn't conflict with streaming
if (miraDeviceWatcher.Status != DeviceWatcherStatus.Stopped)
{
miraDeviceWatcher.Stop();
}
//Create a new casting connection to the device that's been selected
connection = castee.Device.CreateCastingConnection();
//Register for events
connection.ErrorOccurred += Connection_ErrorOccurred;
connection.StateChanged += Connection_StateChangedAsync;
var image = new Windows.UI.Xaml.Controls.Image();
await connection.RequestStartCastingAsync(image.GetAsCastingSource());
}
This Image is just used as a casting source. Once the connection is made, my whole screen is broadcast. The behavior is not documented. Hopefully it won't get 'fixed' in a future update.

Show Viber, Whatsup in Windows Phone 8.1 share contract

Hi I am developing an app that shares a picture in via Share contract in Windows Phone 8.1. My code is
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
and
private async void DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequest request = args.Request;
request.Data.Properties.Title = "Unscramble this";
request.Data.Properties.Description = "";
request.Data.SetText(string.Format("Scrambled word is {0} and clue is {1}. Help me to unscramble this \r\n(via Unscramble Plus for Windows Phone)",scrambledString.ToUpper(),selectedMeanings.ToUpper()));
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
//StorageFile logoFile = await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png");
StorageFile imagefile = await KnownFolders.PicturesLibrary.GetFileAsync("pic.png");
List<IStorageItem> storageItems = new List<IStorageItem>();
storageItems.Add(imagefile);
request.Data.SetStorageItems(storageItems);
}
finally
{
deferral.Complete();
}
}
where this show the share contract as below (including only Facebook, Mail apps)
But if you see in Sendtiment app for Windows Phone (http://www.windowsphone.com/en-us/store/app/sendtiment-cards/9c389cc5-5c00-4f8e-8bd4-e6fbb5040c24) it shows many apps like Viber, Whatsapp, Twitter.
How to get these Viber, Whatsapp like apps in my app's share contract?
Edit: (Addition) When I remove
request.Data.SetText(string.Format("Scrambled word is {0} and clue is {1}. \r\n(via Unscramble Plus for Windows Phone)",scrambledString.ToUpper(),selectedMeanings.ToUpper())); line, this shows OneDrive.
http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-1/10
this might help, also make sure what kind of data you are sharing, as the app will show only if the Content type matches,
for example whatsapp will show only if you are sharing Video,Images but NOT phone contact.
if you use a Universal-App, Whatsapp will not shown. WhatsApp is a WP8.1 Silverlight-App.
This is the Problem!

How to get current URL of webview in windows 8 Apps | C#, XMAL

How can I get the URL of currently opened page in webview?
Actually I want to create a login scenario. so that I can integrate my university site for real-time notifications of assignments and quiz's.
Thanks in advance
Another idea would be to use InvokeScript and get the info from the document using javascript. Something like:
var url = await myWebView.InvokeScriptAsync("eval", new String[] { "document.location.href;" });
Hope it helps someone.
There's no direct property. You have to use LoadCompleted event.
private void WebView_LoadCompleted(object sender, NavigationEventArgs e)
{
System.Diagnostics.Debug.WriteLine(e.Uri.ToString());
}
It should be noted that the WebView_LoadCompleted event has been deprecated & is/will be obsolete. It may not be available after Windows 8.1 so you should use the NavigationCompleted event instead.
private void myWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
string myUrl = sender.Source.ToString();
}

Distinguishing between phone and tablet browsers

I know this question as been beaten to death, but I don't want anything super complicated here.
We have a companion app with our site that is only compatible with 7 and 10-inch tablets. We need to only alert users on those devices about our app. Problem is, I can't go by resolution. My Galaxy S3 has a 1280 x 720 screen, but is obviously not a tablet. I also can't for the life of me find out a way to get the physical size of the screen. The only solution I have come up with is detecting whether the device can make calls with MobileCapabilities.CanInitiateVoiceCall. Unfortuantely, by boss isn't happy with that solution.
So... How can I distinguish between a phone and a tablet in my web app (Server or client side)?
UPDATE: So far it seems that the best approach for Android is something from a blog post by the Android team: All Android phones use "Mobile" in the UserAgent string, so checking for "Mobile" *and "Android" will tell you if it's a phone, while just "Android" should be a tablet. iOS devices should be just as simple--checking for "iPhone" vs "iPad" seems to have worked so far.
I know this is a little late, but I was looking for the same thing.
Wurfl has wat you want. You can implement it easily and and even have an api you can query.
For ASP.NET application first you must place the one-off initialization.
public class Global : HttpApplication
{
public const String WurflDataFilePath = "~/App_Data/wurfl.zip";
private void Application_Start(Object sender, EventArgs e)
{
var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
var configurer = new InMemoryConfigurer().MainFile(wurflDataFile);
var manager = WURFLManagerBuilder.Build(configurer);
HttpContext.Current.Cache[WurflManagerCacheKey] = manager;
}
}
And then use it like this.
var device = WURFLManagerBuilder.Instance.GetDeviceForRequest(userAgent);
var isTablet = device.GetCapability("is_tablet");
var isSmartphone = device.GetCapability("is_smartphone");
For more info check ASP.NET implementation
Hope this helps anyone else looking for this.
You can try to do a user agent detection and search for the keywrords, for example, all Non tablet devices have a "Mobile Safari" key words on their user agent.

Categories