如何从Android打开Kindle电子书? [英] How to open kindle eBook from Android?

查看:272
本文介绍了如何从Android打开Kindle电子书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从我的android应用程序启动Amazon Kindle应用程序,但要基于用户点击的特定书籍.

I'm trying to launch the Amazon Kindle app from my android application but based on a specific book that the user clicks.

我能够确定可用的书以及用户选择的书,但是我只能启动kindle应用程序(使用程序包名称com.amazon.kindle)来启动kindle应用程序.

I'm able to determine the books available and which book the user has selected but I have only been able to launch the kindle application (using the package name com.amazon.kindle) to launch the kindle app.

有人知道我可以发送任何其他命令来指定要打开的书吗?我知道这是可能的,因为Google Play商店中有一个小部件,用户可以在其中选择一个boo,然后在主屏幕上创建一个按钮,以启动kindle应用并打开书.

Does anyone know of any additional commands I can send to specify a book to open? I know this is possible as there is a widget on the google play store where the user selects a boo and it creates a button on the homescreen that launches the kindle app and opens the book.

提前谢谢!

推荐答案

首先,我们需要将意图设置为ACTION_VIEW意图.

First we need to set the intent to an ACTION_VIEW intent.

然后,我们需要为数据定义一个Uri,实际上它是一个类似于以下内容的链接: kindle://book/?action = open& book_id = AMZNID0/B000FC1GHO/0/,在这种情况下,B000FC1GHO部分对应于图书的ID.

Then we need to define an Uri for the data which is actually a link that looks something like: kindle://book/?action=open&book_id=AMZNID0/B000FC1GHO/0/, where in this case the section B000FC1GHO corresponds to the ID of the book.

最后,我们可以开始活动了.就我而言,我必须在意图上发起新的活动设置一些标志.

Finally we can then start the activity. In my case I had to set some flags on the intent to launch a new activity.

我正在使用的代码如下:

The code I'm using is as follows:

if(intent.getAction().contains("BOOK_ACTION_"))
    {
        Log.w("LOG", "We have a book selected");

        bookID = intent.getAction().substring(12);
        Log.w("LOG", bookID);

        Intent readbook = new Intent(Intent.ACTION_VIEW);
        readbook.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        Uri file = Uri.parse("kindle://book/?action=open&book_id=AMZNID0/" + bookID + "/0/");
        readbook.setData(file);
        context.startActivity(readbook);

    }

在这种情况下,我将覆盖onReceive方法,以便我可以对每本书执行一些附加步骤.大概是因为我只是设置一个ACTION_VIEW意图,所以这本来可以在另一个类中处理的,该类为保存我想要的书的imageviewonClickListener.

I'm overriding the onReceive method in this case so that I can perform some additional steps on each book. Presumably because I'm just setting an ACTION_VIEW intent this could have been handles in the other class that does the onClickListener for the imageview that holds the book I want.

这篇关于如何从Android打开Kindle电子书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆