一个在点击时打开PDF文件的应用程序?

时间:2014-11-30 18:02:37

标签: java android pdf android-intent onclick

是否可以通过单击按钮打开PDF文件。 我在下面使用的代码从网上下载PDF文件,如果PDF文件在从Play商店下载时已经在应用程序上,那么用户不必下载任何其他内容就会容易得多。 我已经看过这个问题和答案,但我无法理解它https://stackoverflow.com/review/suggested-edits/6350919。 如果有可能你可以发布一个例子,因为我是编程的新手并且发现很难理解人们有时会说些什么。 非常感谢你!

这是我的代码:

public class GreekHl extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_greek_hl);

    Button ge1 = (Button) findViewById(R.id.ge1);
    ge1.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View arg0) {
            String url1 = "http://www.examinations.ie/archive/exampapers/2014/JC007ALP000EV.pdf";
            Intent ge1 = new Intent(Intent.ACTION_VIEW);
            ge1.setData(Uri.parse(url1));
            startActivity(ge1);

        }
    });
    Button gm1 = (Button) findViewById(R.id.gm1);
    gm1.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View arg0) {
            String url1 =  "http://examinations.ie/archive/markingschem/2014/JC007ALP000EV.pdf";
            Intent ge1 = new Intent(Intent.ACTION_VIEW);
            ge1.setData(Uri.parse(url1));
            startActivity(ge1);

        }
    });

ps我对整个编码事情都很陌生,所以我可能会有点慢!

1 个答案:

答案 0 :(得分:1)

我想你也想去:

ge1.setType("application/pdf");

因此,当您开始活动时,它会重定向到PDF查看器。

相关问题