Advertisement
jasperlow

intent filter read vcard content

Apr 18th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1.  
  2. /**
  3. * Validate Intent
  4. * @return true success, false failure
  5. */
  6. boolean receiveContact() {
  7. try {
  8. Intent receivedIntent = getIntent();
  9. String receivedAction = receivedIntent.getAction();
  10. String receivedType = receivedIntent.getType();
  11. if (receivedIntent != null) {
  12. if (!TextUtils.isEmpty(receivedAction) && !TextUtils.isEmpty(receivedType)) {
  13. if (receivedAction.equals(Intent.ACTION_SEND) && receivedType.equals("text/x-vcard")) {
  14. doSomething(getVCardContent(receivedIntent));
  15. return true;
  16. }
  17. }
  18. }
  19. } catch (Exception e) {
  20. e.printStackTrace();
  21. }
  22. return false;
  23. }
  24.  
  25. /**
  26. * Attempt to get data android:mimeType="text/x-vcard" content from Uri provided
  27. * @param pIntent
  28. * @return
  29. */
  30. String getVCardContent(Intent pIntent) {
  31. Uri vcard_uri = (Uri) pIntent.getExtras().get(Intent.EXTRA_STREAM);
  32. ContentResolver cr = getContentResolver();
  33. InputStream stream = null;
  34. try {
  35. stream = cr.openInputStream(vcard_uri);
  36. } catch (FileNotFoundException e) {
  37. e.printStackTrace();
  38. }
  39. StringBuffer fileContent = new StringBuffer("");
  40. int ch;
  41. try {
  42. while ((ch = stream.read()) != -1) {
  43. fileContent.append((char) ch);
  44. }
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48. return new String(fileContent);
  49. }
  50.  
  51. void doSomething(String data) {
  52. Log.i("TAG", "data: " + data);
  53. MwDialog.OK_Alert(data, new POS_ButtonHandler() {
  54. @Override
  55. public void onPositiveClick() {}
  56. });
  57. }
  58.  
  59. void parseVCard() {
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement