我正在开发一个带有书籍按钮的Xamarin.Forms应用程序 . 我想要它打开iBooks,如果操作系统是iOS,谷歌玩书,如果它是Android
我有iBooks部分下来,但如何从应用程序的Android版本中的按钮单击打开谷歌播放书籍?
继承我的xaml代码:
<StackLayout Orientation="Horizontal" MinimumHeightRequest="30" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Button Image="books.png" HorizontalOptions="CenterAndExpand" BackgroundColor="Transparent" Clicked="OpenBooks" />
<Button Image="settings.png" HorizontalOptions="EndAndExpand" BorderColor="Transparent" BackgroundColor="Transparent" Clicked="gotosettings" />
</StackLayout>
继承人我的C#代码:
public void OpenBooks(object sender, EventArgs e)
{
switch (Device.OS)
{
case TargetPlatform.iOS:
Device.OpenUri(new Uri("itms-books"));
break;
case TargetPlatform.Android:
//open google play books code here
break;
}
}
任何帮助都会很棒!
预先感谢!
1 回答
在Android平台上,你应该知道google play books的包名,并检查它是否已经安装 .
在PCL部分,你无法通过
Device.OpenUri("packagename");
实现它您应该使用依赖服务打开Google Play图书应用,并且Google Play图书应用包名称为
com.google.android.apps.books
:In the PCL side define the interface:
In the andorid side implements the interface:
And then call the openBooks method in the PCL side:
在我的Android设备中,我安装了Google Play书籍: