多个意图过滤器
Multiple Intent Filters
我有一个 Intent 过滤器设置,它可以接收 Action.send(将其用于 adobe 共享按钮)和 Action.view(将其用于预览电子邮件附件)
我遇到的问题是当我尝试将 pdf 从 adobe 共享到我的应用程序时,它默认为操作视图。如果我从清单中删除 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));
}
}
我截断的清单文件
<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>
您需要在清单中有两个 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>
在我的代码中进一步证明是 intent.setAction(android.content.Intent.ACTION_VIEW);
这是强制意图类型
我有一个 Intent 过滤器设置,它可以接收 Action.send(将其用于 adobe 共享按钮)和 Action.view(将其用于预览电子邮件附件) 我遇到的问题是当我尝试将 pdf 从 adobe 共享到我的应用程序时,它默认为操作视图。如果我从清单中删除 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));
}
}
我截断的清单文件
<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>
您需要在清单中有两个 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>
在我的代码中进一步证明是 intent.setAction(android.content.Intent.ACTION_VIEW);
这是强制意图类型