问题
I'm trying to launch the Amazon Kindle app from my android application but based on a specific book that the user clicks.
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.
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.
Thanks in advance!
回答1:
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.
来源:https://stackoverflow.com/questions/11779584/how-to-open-kindle-ebook-from-android