问题
I am trying to working on download and open pdf file in windows phone 8. Where the code is successfully working when any pdf viewer (Adobe, MS PDF Reader etc.) presents on phone.
protected async void openPDFFile(string path)
{
try
{
// Access isolated storage.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Access the bug query file.
StorageFile pdfFile = await local.GetFileAsync(path);
if (pdfFile != null)
{
// Launch the pdf file.
IAsyncOperation<bool> success = Windows.System.Launcher.LaunchFileAsync(pdfFile);
if (await success)
{
// File launched
System.Diagnostics.Debug.WriteLine("Successfully Open.");
}
else
{
// File launch failed
System.Diagnostics.Debug.WriteLine("Failed to open.");
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("exception: " + ex.Message);
}
}
But when there is no pdf viewer present on the phone, it is executing the same success code block i.e.
if (await success)
{
// File launched
System.Diagnostics.Debug.WriteLine("Successfully Open.");
}
and open windows phone system message box, Can is it possible to detect it before system identify so that I will show my own/custom created message box here? Because on no click of windows phone system message box I want user to redirect on some other page.
Is there any way to detect pdf viewer application present or not before LaunchFileAsync(filepath)
method?
Can anyone please suggest me way how I will get solution.
Can anyone please guide me how to use below methode of LaunchFileAsync
? In MSDN its stated that this method Minimum supported phone :: Windows Phone 8.1. Is there any similar for Windows phone 8?
LaunchFileAsync(IStorageFile, LauncherOptions)
回答1:
Unfortunately the 'true' return value from LaunchFileAsync simply means that the attempt to launch this file was performed successfully. If you debug through your code you'll actually see that the asynchronous task completes before the user selects 'Yes' or 'No' from the message box that displays when there is no app available to open a pdf file.
There is also no way to determine if a PDF viewing app is available on the phone, this capability does not exist for the Windows Phone 8 SDK, although 1st party and OEM apps seem to have this feature available.
来源:https://stackoverflow.com/questions/25039818/how-to-detect-default-pdfviewer-and-open-pdf-in-windows-phone