android - 多个 Intent 过滤器

标签 android android-intent uri android-manifest

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

或者也许我最好问一下如何为预览或 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));
            }

        }

我的截断 list 文件

<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>

最佳答案

您需要在 list 中有两个 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>

关于android - 多个 Intent 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31800656/

相关文章:

Android:进度条作为占位符

android - 我的第一个应用程序。错误 : Invalid start tag LinearLayout. 为什么?

android - 无法将 var 传递给其他 Activity

android - 找不到处理 Intent { act=android.intent.action.DELETE } 的 Activity

Android 相机视频 Intent 返回空 URI

node.js - S3 正在将带有空格和符号的 url 编码为未知格式

android - 如何将矢量放在渐变上?

android - 在 onStart() 之后直接调用 fragment onStop() - 为什么?

java - 有没有办法通过 Intent 或其他方式共享 *.json 文件?

javascript - url 中的这个字符串意味着什么#!?