Action Intent没有收到额外的流

时间:2015-08-03 07:38:09

标签: java android android-intent itext android-manifest

使用android.intent.action.SEND时,我的应用程序运行良好。让用户通过adobe的分享获取我的PDF。但当我将我的清单文件更改为android.intent.action.VIEW时,我收到"尝试调用虚方法' java.lang.Object android.os.Bundle.get(java.lang.String)& #39;在null对象引用"

我需要它成为View的原因是因为用户需要打开他的电子邮件并单击文件附件上的预览然后选择我的应用程序。从那里我希望能够使用itext来编辑PDF。如果我没有添加android.intent.action.VIEW,那么我的程序就不在列表中。

require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

Log Cat:

 public void existingpdf(View view) {
        Intent intent = getIntent();

        String action = intent.getAction();
        String type = intent.getType();
        //intent.setAction(android.content.Intent.ACTION_VIEW);

        try {
            //Intent intent = Intent();
            //
            Uri pdfUri = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);
            PdfReader pdfReader = new PdfReader(pdfUri.getPath());

            //PdfReader pdfReader = new PdfReader(android.os.Environment.getExternalStorageDirectory().getPath()+ File.separatorChar + "testfile.pdf");

            PdfStamper pdfStamper = new PdfStamper(pdfReader,
                    new FileOutputStream(android.os.Environment.getExternalStorageDirectory().getPath()+ File.separatorChar + "testfilemodified.pdf"));

            Image image = Image.getInstance(android.os.Environment.getExternalStorageDirectory().getPath()+ File.separatorChar + "temp.jpg");

            for(int i=1; i<= pdfReader.getNumberOfPages(); i++){

                //put content under
                PdfContentByte content = pdfStamper.getUnderContent(i);
                image.setAbsolutePosition(100f, 150f);
                image.scaleToFit(100, 125);
                content.addImage(image);

                //put content over
                //content = pdfStamper.getOverContent(i);
                //image.setAbsolutePosition(100f, 150f);
                //image.scaleToFit(100,125);
                //content.addImage(image);



                mSubjectEditText = (TextView) findViewById(R.id.edit_text_subject);
                mSubjectEditText = (TextView) findViewById(R.id.edit_text_subject);







                //Text over the existing page
                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                        BaseFont.WINANSI, BaseFont.EMBEDDED);
                content.beginText();
                content.setFontAndSize(bf, 18);

                //content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Page No: " + i, 130, 15, 0);
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, mSubjectEditText.getText().toString(),150, 120, 0);
                content.endText();
                Toast.makeText(getApplicationContext(), "Completed", Toast.LENGTH_LONG).show();
            }

            pdfStamper.close();

        } catch (IOException e) {
            e.printStackTrace();
            //Toast.makeText(getApplicationContext(), (CharSequence) e, Toast.LENGTH_LONG).show();
            Log.e("error", String.valueOf(e));
        } catch (DocumentException e) {
            e.printStackTrace();
            //Toast.makeText(getApplicationContext(), (CharSequence) e, Toast.LENGTH_LONG).show();
            Log.e("error document", String.valueOf(e));
        }
    }

0 个答案:

没有答案