Skip to content

Commit cf8eef4

Browse files
committed
Add support to send intent
1 parent 9a53c80 commit cf8eef4

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

lib/src/main/AndroidManifest.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
android:exported="true"
1212
android:label="@string/document_activity"
1313
>
14-
<intent-filter>
14+
<intent-filter android:label="@string/document_activity">
1515
<action android:name="android.intent.action.VIEW" />
1616
<category android:name="android.intent.category.BROWSABLE" />
1717
<category android:name="android.intent.category.DEFAULT" />
@@ -30,6 +30,20 @@
3030
<data android:mimeType="application/octet-stream"
3131
android:scheme="file" />
3232
</intent-filter>
33+
34+
<intent-filter android:label="@string/document_activity">
35+
<action android:name="android.intent.action.SEND" />
36+
<category android:name="android.intent.category.DEFAULT" />
37+
<!-- list the mime-types we know about -->
38+
<data android:mimeType="application/pdf" />
39+
<data android:mimeType="application/vnd.ms-xpsdocument" />
40+
<data android:mimeType="application/oxps" />
41+
<data android:mimeType="application/vnd.comicbook+zip" />
42+
<data android:mimeType="application/x-cbz" />
43+
<data android:mimeType="application/epub+zip" />
44+
<data android:mimeType="application/x-fictionbook" />
45+
<data android:mimeType="application/x-mobipocket-ebook" />
46+
</intent-filter>
3347
</activity>
3448
<activity
3549
android:name=".OutlineActivity"

lib/src/main/java/com/artifex/mupdf/viewer/DocumentActivity.java

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import android.app.AlertDialog;
55
import android.content.ContentResolver;
66
import android.content.Context;
7-
import android.content.DialogInterface;
8-
import android.content.DialogInterface.OnCancelListener;
97
import android.content.Intent;
108
import android.content.SharedPreferences;
119
import android.content.res.Resources;
@@ -179,12 +177,7 @@ private void showCannotOpenDialog(String reason) {
179177
Resources res = getResources();
180178
AlertDialog alert = mAlertBuilder.create();
181179
setTitle(String.format(Locale.ROOT, res.getString(R.string.cannot_open_document_Reason), reason));
182-
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss),
183-
new DialogInterface.OnClickListener() {
184-
public void onClick(DialogInterface dialog, int which) {
185-
finish();
186-
}
187-
});
180+
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss), (dialog, which) -> finish());
188181
alert.show();
189182
}
190183

@@ -214,10 +207,13 @@ public void onCreate(final Bundle savedInstanceState)
214207

215208
mReturnToLibraryActivity = intent.getIntExtra(getComponentName().getPackageName() + ".ReturnToLibraryActivity", 0) != 0;
216209

217-
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
210+
if (Intent.ACTION_VIEW.equals(intent.getAction())
211+
|| Intent.ACTION_SEND.equals(intent.getAction())) {
218212
Uri uri = intent.getData();
219213
String mimetype = getIntent().getType();
220-
214+
if (uri == null) {
215+
uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
216+
}
221217
if (uri == null) {
222218
showCannotOpenDialog("No document uri to open");
223219
return;
@@ -289,18 +285,8 @@ public void onCreate(final Bundle savedInstanceState)
289285
{
290286
AlertDialog alert = mAlertBuilder.create();
291287
alert.setTitle(R.string.cannot_open_document);
292-
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss),
293-
new DialogInterface.OnClickListener() {
294-
public void onClick(DialogInterface dialog, int which) {
295-
finish();
296-
}
297-
});
298-
alert.setOnCancelListener(new OnCancelListener() {
299-
@Override
300-
public void onCancel(DialogInterface dialog) {
301-
finish();
302-
}
303-
});
288+
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dismiss), (dialog, which) -> finish());
289+
alert.setOnCancelListener(dialog -> finish());
304290
alert.show();
305291
return;
306292
}
@@ -317,22 +303,14 @@ public void requestPassword(final Bundle savedInstanceState) {
317303
alert.setTitle(R.string.enter_password);
318304
alert.setView(mPasswordView);
319305
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.okay),
320-
new DialogInterface.OnClickListener() {
321-
public void onClick(DialogInterface dialog, int which) {
322-
if (core.authenticatePassword(mPasswordView.getText().toString())) {
323-
createUI(savedInstanceState);
324-
} else {
325-
requestPassword(savedInstanceState);
326-
}
306+
(dialog, which) -> {
307+
if (core.authenticatePassword(mPasswordView.getText().toString())) {
308+
createUI(savedInstanceState);
309+
} else {
310+
requestPassword(savedInstanceState);
327311
}
328312
});
329-
alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel),
330-
new DialogInterface.OnClickListener() {
331-
332-
public void onClick(DialogInterface dialog, int which) {
333-
finish();
334-
}
335-
});
313+
alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), (dialog, which) -> finish());
336314
alert.show();
337315
}
338316

0 commit comments

Comments
 (0)