Show Viber, Whatsup in Windows Phone 8.1 share contract - c#

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!

Related

I'm try to share text on Whatsapp in wp8

I'm try to share text on whtsapp where below method not show the whtsapp messanger.
ShareStatusTask shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = jokeId;
shareStatusTask.Show();
But How can i share the text on whtsapp or other messanger
This is how I called whatsapp from my app but I haven't tried anything with sending some data to it. You will have to check it somewhere in their documentation.
private async void SendWhatsAppMessage()
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("whatsapp:"));
}
You can try the Share Link Task as follows-
ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "Code Samples";
shareLinkTask.LinkUri = new Uri("http://code.msdn.com/wpapps", UriKind.Absolute);
shareLinkTask.Message = "Here are some great code samples for Windows Phone.";
shareLinkTask.Show();
Share Link Task is a little different from Share Status Task.
In both cases your app is sending some data to share, but the other application (whatsapp in this case) must also accept the data your app is sending.
But Whatsapp currently does not support ShareLinkTask or ShareStatusTask.
You should implement these in your application code. when whatsapp starts supporting them, it will appear in the list and it will be possible to share data directly with whatsapp.

Call Navigation/Maps/Drive with an Address in WP8.1 Application

I was wondering if it's possible to call the default navigation application within my Windows Phone 8.1 application. I have an address and I would like for the user to press a button and be able to navigate to that address through the default navigation app. If this is possible, how do I do it?
Thanks for your time,
Johan
You can launch turn-by-turn directions apps using the ms-drive-to and ms-walk-to schemes (depending on the type of directions you want) but you first need to get a geocoordinate for the address that you have. Since you're targeting Windows Phone 8.1, you can use the MapLocationFinder class in the Windows.Services.Maps namespace.
string locationName = "Empire State Building";
string address = "350 5th Avenue, New York City, New York 10018";
var locFinderResult = await MapLocationFinder.FindLocationsAsync(
address, new Geopoint(new BasicGeoposition()));
// add error checking here
var geoPos = locFinderResult.Locations[0].Point.Position;
var driveToUri = new Uri(String.Format(
"ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}",
geoPos.Latitude,
geoPos.Longitude,
locationName));
Launcher.LaunchUriAsync(driveToUri);
the official solution is:
Uri uri = new Uri("ms-drive-to:?destination.latitude=" + latitude.ToString(CultureInfo.InvariantCulture) +
"&destination.longitude=" + longitude.ToString(CultureInfo.InvariantCulture))
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// Uri launched.
}
else
{
MessageBox.Show("error");
}
But, there is a problem with this solution.
If you use the nokia programs (HERE), it works fine.
if you want to use waze, you have to add origin.latitude and origin.longitude.
in the MSDN page, They said that it is not necessary, but in fact, you have to write it.
I am already not enable to load moovit but if someone has an issue, it'll help me a lot.

How to convert speech to text? Windows 8 RT

Is it possible to convert speech to text without using a web service? I have tried the following solution but the libraries aren't recognised in eclipse,http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207021(v=vs.105).aspx
I'm thinking there has to be a speech recognition API in Windows 8 RT? Does anyone have an implementation of speech recognition in this platform or point me in the right direction?
I'm guessing that these methods are not available on the Windows 8 RT platform,If so are there any alternatives?
I tried the following in an app bar button click event but none of the methods/namespaces are recognized.
// Create an instance of SpeechRecognizerUI.
this.recoWithUI = new SpeechRecognizerUI();
// Start recognition (load the dictation grammar by default).
SpeechRecognitionUIResult recoResult = await recoWithUI.RecognizeWithUIAsync();
// Do something with the recognition result.
MessageBox.Show(string.Format("You said {0}.", recoResult.RecognitionResult.Text));
It looks like the SpeechRecognitionUI class is for Windows Phone 8.
For Windows 8 RT, Microsoft has the The Bing Speech Recognition Control and the class is called SpeechRecognizerUx.
The Bing Speech Recognition Control enables a Windows 8, Windows 8.1,
or Windows RT machine to convert audio speech input to written text.
It does this by receiving audio data from a microphone, sending the
audio data to a web service for analysis, and then returning its best
interpretations of user speech as text.
The one 'caveat' (if you don't wanna pay) is that this requires a subscription to Windows Azure Data Marketplace, although the free stuff is pretty generous IMO.
The Bing Speech Recognition Control is only available from the Visual
Studio Gallery. To develop with the Bing Speech Recognition Control,
you must first subscribe on the Windows Azure Data Marketplace, and
then register your application. There is no cost to subscribe for the
first 500,000 service calls per month.
Here's a code sample.
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
SpeechRecognizer SR;
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
// Apply credentials from the Windows Azure Data Marketplace.
var credentials = new SpeechAuthorizationParameters();
credentials.ClientId = "<YOUR CLIENT ID>";
credentials.ClientSecret = "<YOUR CLIENT SECRET>";
// Initialize the speech recognizer and attach to control.
SR = new SpeechRecognizer("en-US", credentials);
SpeechControl.SpeechRecognizer = SR;
}
private async void SpeakButton_Click(object sender, RoutedEventArgs e)
{
try
{
// Start speech recognition.
var result = await SR.RecognizeSpeechToTextAsync();
ResultText.Text = result.Text;
}
catch (System.Exception ex)
{
ResultText.Text = ex.Message;
}
}
Source: http://msdn.microsoft.com/en-us/library/dn434633.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-4

Using PowerStatus class in windows phone 7 app

I am new to windows phone app development.
I am trying to use the powerStatus class in a windows phone 7 app. I have searched quite a bit regarding that and learnt that it is necessary to add reference of System.Windows.Forms
But in the add reference of the project 'System.Windows.Forms' is not present.
How can I use the powerStatus class?
Please help.
Thank you.
Please Refer this msdn link that will clearly shows that how can you get the status of the Battery. i.e. The remaining Percentage of charge in phone;s battery.
Know the battery status in windows phone
In this link, use the RemainingChargePercent() Method this will return the value that indicates the percentage of the charge remaining on the phone's battery.
This things will used in windows phone 8 only.
But, you are with windows phone 7. so, currently there is no API available for windows phone 7 to know the remaining charge in phone's battery.
You will get the information like the if your phone is connected to power source or running in battery.
I will show here some important msdn question links that shows that there is no method or the class is available to get the charge level in windows phone 7.
The MSDN Question link: how to get the battery status in windows phone 7.
if you have the need to show the battery charge percentage, then i suggest you to proceed with windows phone 8.
It work for wp8. but I am not sure about wp7.
_battery = Battery.GetDefault();
var remainingCharge = string.Format("{0} %", _battery.RemainingChargePercent);
var remainingTime = _battery.RemainingDischargeTime.TotalMinutes;
_battery.RemainingChargePercentChanged += OnRemainingChargePercentChanged;
private void OnRemainingChargePercentChanged(object sender, object e)
{
var remainingCharge = string.Format("{0} %", _battery.RemainingChargePercent);
var remainingTime = _battery.RemainingDischargeTime.TotalMinutes;
if(Microsoft.Phone.Info.DeviceStatus.PowerSource == Microsoft.Phone.Info.PowerSource.External)
var text = "Charger Connected";
else
var text = "Charger Not Connected";
}

Sharing from Windows Phone 8

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.

Categories