打开从Android应用程序ePub文件 [英] open an epub file from android app
本文介绍了打开从Android应用程序ePub文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的使用月球阅读器Android应用程序中打开EPUB文件。 code如下。我在日志中收到一个错误如下:
11-26 16:57:01.237:E / Web控制台(12254):未捕获的错误:错误NPObject.:5914调用方法
请你能指教一下可以是问题?
公共无效openEpub(字符串URL)
{
意向意图= NULL;
URI URI = NULL;
尝试{
意图=新意图(Intent.ACTION_VIEW);
URI = Uri.parse(URL);
intent.setDataAndType(URI,应用程序/ EPUB +压缩);
}赶上(例外五){
e.printStackTrace();
}
尝试{
// startActivity(意向);
软件包管理系统下午= getPackageManager();
尝试
{
字符串的packageName =com.flyersoft.moonreader;
意向launchIntent = pm.getLaunchIntentForPackage(的packageName);
launchIntent.setAction(Intent.ACTION_VIEW);
launchIntent.setData(URI);
startActivity(launchIntent);
}
赶上(例外E1)
{
e1.printStackTrace();
}
赶上(误差E2){
e2.printStackTrace();
}
}赶上(ActivityNotFoundException E){
//没有应用程序来查看,请下载一个
AlertDialog.Builder建设者=新AlertDialog.Builder(本);
builder.setTitle(未找到应用);
builder.setMessage(从Android Market下载一个?);
builder.setPositiveButton(是,请
新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
意图marketIntent =新意图(Intent.ACTION_VIEW);
marketIntent.setData(Uri.parse(市场://搜Q = EPUB和C =应用程序));
startActivity(marketIntent);
}
});
builder.setNegativeButton(不,谢谢,NULL);
builder.create()显示()。
}
赶上(错误E3){
e3.printStackTrace();
}
}
解决方案
同样code工作对我来说没有任何变化。误差在code的一些不同的部分。
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();
}
}
解决方案
The same code worked for me without any change. Error was in some different part of code.
这篇关于打开从Android应用程序ePub文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文