aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-17 21:14:29 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-17 21:14:29 +0200
commitd51f3fab943c31ae653d30dcdd0908b60164956c (patch)
treea6a50aaacd6b6124a9595b491621ffdb4af72774 /src/main
parente946eb76c7eb51cb27903dc725415eec26036e18 (diff)
Extend QR scanner to support VCard with IMPP field
Currently QR scanner supports only URIs. VCard specification allows embedding instant messaging protocols in the `IMPP` field [0]. This change will extract the first XMPP URI from `IMPP` field if a VCard has been scanned and process it just like if the XMPP URI was scanned directly. In case the contact is not already present in the roster this will pop up "Add contact" window. Example VCard with this URI: BEGIN:VCARD FN:Test Contact EMAIL:test@example.com IMPP:xmpp:test@example.com END:VCARD [0]: https://tools.ietf.org/html/rfc6350#section-6.4.3
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
index 776973c09..66355f49c 100644
--- a/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/UriHandlerActivity.java
@@ -12,6 +12,8 @@ import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
@@ -153,12 +155,20 @@ public class UriHandlerActivity extends AppCompatActivity {
finish();
}
+ private static final Pattern VCARD_XMPP_PATTERN = Pattern.compile("\nIMPP([^:]*):(xmpp:.+)\n");
+
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, requestCode, intent);
if (requestCode == REQUEST_SCAN_QR_CODE && resultCode == RESULT_OK) {
String result = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
if (result != null) {
+ if (result.startsWith("BEGIN:VCARD\n")) {
+ Matcher matcher = VCARD_XMPP_PATTERN.matcher(result);
+ if (matcher.find()) {
+ result = matcher.group(2);
+ }
+ }
Uri uri = Uri.parse(result);
handleUri(uri, true);
}