gpt4 book ai didi

android - 多个 Intent 过滤器

转载 作者:行者123 更新时间:2023-11-30 01:58:51 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com