多个意图过滤器

时间:2015-08-04 04:21:47

标签: android android-intent uri android-manifest

我有一个意图过滤器设置,它可以接收Action.send(使用此用于adobe共享按钮)和Action.view(使用此用于预览电子邮件附件) 我遇到的问题是当我尝试从adobe分享pdf到我的应用程序时,它默认为Action视图。如果我从清单中删除action.view,然后使用Action Send将PDF发送到我的应用程序。使用操作视图时代码失败.....它只适用于动作发送

或者也许我更好地问我如何处理预览或adobe 这项工作非常适合点击电子邮件上的预览按钮而不是adobe中的分享按钮

   Uri pdfUri = (Uri) getIntent().getData();
                PdfReader pdfReader = new PdfReader(pdfUri.getPath());

实际代码:

if (Intent.ACTION_VIEW.equals(action) && type != null) {

            Uri pdfUri = (Uri) getIntent().getData();
            PdfReader pdfReader = new PdfReader(pdfUri.getPath());
            //PdfReader pdfReader = new PdfReader(pdfUri.getPath());

            try {
                //Intent intent = Intent();
                //


                //PdfReader pdfReader = new PdfReader

(android.os.Environment.getExternalStorageDirectory().getPath()+ File.separatorChar + 

"Anthonyrules.pdf");

                PdfStamper pdfStamper = new PdfStamper(pdfReader,
                        new FileOutputStream

(android.os.Environment.getExternalStorageDirectory().getPath()+ File.separatorChar + 

"anthonyrulesmodified.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));
            }

        }

我的Trunicated Manifest文件

<intent-filter >
                <action android:name="android.intent.action.SEND" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="application/pdf" />
            </intent-filter>

2 个答案:

答案 0 :(得分:1)

你需要在manifest中有两个intent过滤器标签,作为两种不同的配置。

<intent-filter >
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter >
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="application/pdf" />
</intent-filter>

答案 1 :(得分:0)

我的代码中intent.setAction(android.content.Intent.ACTION_VIEW);

进一步说明了这一点

这是强制意图类型