我最近问了一个关于如何在android开发中用按钮打开pdf文件的问题。很抱歉这个含糊的问题,但我会尽量让它更具体一点。所以我已经有了这段代码:
try {
var f = Ti.Filesystem.getFile('your.pdf');
Ti.Android.currentActivity.startActivity(Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: 'application/pdf',
data: f.getNativePath()
}));
catch (err) {
var alertDialog = Titanium.UI.createAlertDialog({
title: //your text,
message: // your text if not found,
buttonNames: ['Yes','No'],
cancel: 1
});
alertDialog.show();
alertDialog.addEventListener('click', function(evt) {
if (evt.index == 0) {
Ti.Platform.openURL('http://search?q=pdf');
}
});
但是,我不知道将“Your.pdf 文件”放在哪里。我尝试了 assets 文件夹并输入了
var f = Ti.Filesystem.getFile('assets/your.pdf');
但是,我收到一条错误消息,提示“无效字符常量”
帮助?我希望这个问题更精确一些。
最佳答案
我们通常将所有可加载资源放在资源下,并使用资源文件夹中的相对路径。
关于android - ti中pdf文件放在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17682490/