2013-04-20 131 views
0

我在我的应用程序中有一个按钮,当您按下它时会打开一个pdf文件。但是,当我退出PDF文件,然后再次按下按钮时,它会在我上次打开的页面上打开PDF文件。是否可以让我的按钮每次都从头开始打开它? ?如何才能做到这一点下面是我的代码:Android:每次开始打开PDF文件

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(); 
       } 
      } 
     }); 

    } 

回答

2

是否有可能使我的按钮从一开始就打开它每一次?

不,因为PDF查看器的行为取决于该PDF查看器的作者。 Android上有很多PDF查看器应用程序,但每个作者都可以处理这些应用程序。

0

在你的代码中你发送一个隐含的意图。这给了android操作系统来决定哪个应用程序应该处理这个。你失去了对系统行为的控制。现在取决于PDF查看器应用程序的行为。你不能做任何改变。如果您发现任何操作属性,那么它也不适用于所有应用程序的通用。可以做的一件事就是在应用程序中创建一个简单的PDF查看器活动。