我正在開發一個Windows Phone應用程序,並將其定位到7.1,因此它可以在wp7和wp8設備上運行。 如果應用一個WP8設備上運行時,我想運行此代碼:GetFileAsync然後通過反射調用Windows.System.Launcher.LaunchFileAsync
public async void DefaultLaunch2a()
{
// Path to the file in the app package to launch
var file1 = await ApplicationData
.Current
.LocalFolder
.GetFileAsync("webcam-file.jpg");
if (file1 != null)
{
// Launch the retrieved file
var success = await Windows.System.Launcher.LaunchFileAsync(file1);
if (success)
{
// File launched/y
}
else
{
// File launched/n
}
}
else
{
// Could not find file
}
}
啓動器的文件類型(打開的圖像)。我正在嘗試通過反思來實現,但我遇到了一些問題。
String name = "file1.jpg";
Type taskDataType2 = Type.GetType("Windows.Storage.StorageFolder, Windows, "
+ "Version=255.255.255.255, Culture=neutral, "
+ "PublicKeyToken=null, "
+ "ContentType=WindowsRuntime");
MethodInfo showmethod2 = taskDataType2.GetMethod("GetFileAsync",
new Type[]
{
typeof(System.String)
});
showmethod2.Invoke(taskDataType2,
new System.String[] { name });
此代碼拋出異常TargetException: Object does not match target type
- 當調用該方法。
出了什麼問題?有沒有人試圖用反射來編寫上面的代碼? 目標是從設備商店中讀取圖像文件,然後啓動Windows.System.Launcher.LaunchFileAsync
。 如果代碼在wp8設備上運行,我想要做一些類似mangopollo的操作。