file android closed,open an epub file from android app [closed]

问题

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 5 years ago.

I am trying to open an epub file from my android app using Moon Reader. Code given below. I am getting an error in the log as follows:

11-26 16:57:01.237: E/Web Console(12254): Uncaught Error: Error calling method on NPObject.:5914

Please can you advise what can be the issue?

public void openEpub(String url)

{

Intent intent = null;

Uri uri = null;

try {

intent = new Intent(Intent.ACTION_VIEW);

uri = Uri.parse(url);

intent.setDataAndType(uri, "application/epub+zip");

} catch (Exception e) {

e.printStackTrace();

}

try {

//startActivity(intent);

PackageManager pm = getPackageManager();

try

{

String packageName = "com.flyersoft.moonreader";

Intent launchIntent = pm.getLaunchIntentForPackage(packageName);

launchIntent.setAction(Intent.ACTION_VIEW);

launchIntent.setData(uri);

startActivity(launchIntent);

}

catch (Exception e1)

{

e1.printStackTrace();

}

catch (Error e2) {

e2.printStackTrace();

}

} catch (ActivityNotFoundException e) {

// No application to view, ask to download one

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("No Application Found");

builder.setMessage("Download one from Android Market?");

builder.setPositiveButton("Yes, Please",

new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

Intent marketIntent = new Intent(Intent.ACTION_VIEW);

marketIntent.setData(Uri.parse("market://search?q=epub&c=apps"));

startActivity(marketIntent);

}

});

builder.setNegativeButton("No, Thanks", null);

builder.create().show();

}

catch(Error e3) {

e3.printStackTrace();

}

}

回答1:

Try this

private void openReader(String data)

{

Intent i;

PackageManager manager = getPackageManager();

try {

i = manager.getLaunchIntentForPackage("com.flyersoft.moonreader");

if (i == null)

throw new PackageManager.NameNotFoundException();

i.setAction(Intent.ACTION_VIEW);

i.setData(Uri.parse(data));

startActivity(i);

} catch (PackageManager.NameNotFoundException e) {

//Do something

}

}

And as parameter send path to the file

回答2:

The same code worked for me without any change. Error was in some different part of code.

来源:https://stackoverflow.com/questions/20216203/open-an-epub-file-from-android-app

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值