How to open kindle eBook from Android?

匆匆过客 提交于 2019-12-03 09:03:38
Lucian

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

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);

    }

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!