mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Issue 786, from Lachezar, support encoding text/plain
git-svn-id: https://zxing.googlecode.com/svn/trunk@1740 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
c24fefe747
commit
dcbee05f25
|
@ -76,7 +76,7 @@ versionName is 2.31, 2.4, or 3.0. -->
|
|||
<activity android:name=".PreferencesActivity"
|
||||
android:label="@string/preferences_name">
|
||||
</activity>
|
||||
<activity android:name=".encode.EncodeActivity">
|
||||
<activity android:name=".encode.EncodeActivity" android:label="@string/share_name">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.zxing.client.android.ENCODE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
@ -87,6 +87,12 @@ versionName is 2.31, 2.4, or 3.0. -->
|
|||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="text/x-vcard"/>
|
||||
</intent-filter>
|
||||
<!-- This allows us to handle sharing any plain text . -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".book.SearchBookContentsActivity"
|
||||
android:label="@string/sbc_name"
|
||||
|
|
|
@ -123,8 +123,39 @@ final class QRCodeEncoder {
|
|||
return contents != null && contents.length() > 0;
|
||||
}
|
||||
|
||||
// Handles send intents from the Contacts app, retrieving a contact as a VCARD.
|
||||
// Handles send intents from multitude of Android applications
|
||||
private boolean encodeContentsFromShareIntent(Intent intent) {
|
||||
// Check if this is a plain text encoding, or contact
|
||||
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||
return encodeContentsFromShareIntentPlainText(intent);
|
||||
}
|
||||
// Attempt default sharing.
|
||||
return encodeContentsFromShareIntentDefault(intent);
|
||||
}
|
||||
|
||||
private boolean encodeContentsFromShareIntentPlainText(Intent intent) {
|
||||
// Notice: Google Maps shares both URL and details in one text, bummer!
|
||||
contents = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
// We only support non-empty and non-blank texts.
|
||||
// Trim text to avoid URL breaking.
|
||||
if (contents == null) {
|
||||
return false;
|
||||
}
|
||||
contents = contents.trim();
|
||||
if (contents.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
// We only do QR code.
|
||||
format = BarcodeFormat.QR_CODE;
|
||||
// TODO: Consider using the Intent.EXTRA_SUBJECT or Intent.EXTRA_TITLE
|
||||
displayContents = contents;
|
||||
title = activity.getString(R.string.contents_text);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handles send intents from the Contacts app, retrieving a contact as a VCARD.
|
||||
// Note: Does not work on HTC devices due to broken custom Contacts application.
|
||||
private boolean encodeContentsFromShareIntentDefault(Intent intent) {
|
||||
format = BarcodeFormat.QR_CODE;
|
||||
try {
|
||||
Uri uri = (Uri)intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
|
||||
|
|
Loading…
Reference in a new issue