Android:每次从一开始就打开PDF文件
我的应用程序中有一个按钮,当你按下它时,它会打开一个pdf文件。但是,当我退出pdf文件,然后再次按下按钮时,它会在我上次访问的页面上打开pdf文件。是否可以让我的按钮每次都从一开始就打开它?如何做到这一点?下面是我的代码:Android:每次从一开始就打开PDF文件,android,android-intent,android-button,Android,Android Intent,Android Button,我的应用程序中有一个按钮,当你按下它时,它会打开一个pdf文件。但是,当我退出pdf文件,然后再次按下按钮时,它会在我上次访问的页面上打开pdf文件。是否可以让我的按钮每次都从一开始就打开它?如何做到这一点?下面是我的代码: ImageButton userGuide = (ImageButton) findViewById(R.id.main_menu_user_guide_button); userGuide.setOnClickListener(new View.OnCli
ImageButton userGuide = (ImageButton) findViewById(R.id.main_menu_user_guide_button);
userGuide.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
SimpleAudioEngine.sharedEngine(context).playEffect(
"sfx/Button_Pop.wav");
File pdfFile = new File(Environment
.getExternalStorageDirectory().getAbsolutePath()
+ "/MathBarsPDFDocument/userg.pdf");
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "application/pdf");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// No application to view, ask to download one
AlertDialog.Builder builder = new AlertDialog.Builder(
HelpMenu.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://details?id=com.adobe.reader"));
startActivity(marketIntent);
}
});
builder.setNegativeButton("No, Thanks", null);
builder.create().show();
}
}
});
}
是否可以让我的按钮每次从一开始就打开它
否,因为PDF查看器的行为取决于该PDF查看器的作者。Android上有许多PDF viewer应用程序,每个应用程序都可以按照作者的意愿处理此问题。在您的代码中,您发送了一个隐含的意图。这使得android操作系统可以决定哪个应用程序应该处理这个问题。您已经失去了对系统行为的控制。现在取决于pdf查看器应用程序的行为,它可以正常工作。你不能对它做任何改变。若你们发现了任何动作属性,那个么它也不会对所有的应用程序通用。可以做的一件事是在应用程序中创建一个简单的PDF查看器活动