Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Validate Intent
- * @return true success, false failure
- */
- boolean receiveContact() {
- try {
- Intent receivedIntent = getIntent();
- String receivedAction = receivedIntent.getAction();
- String receivedType = receivedIntent.getType();
- if (receivedIntent != null) {
- if (!TextUtils.isEmpty(receivedAction) && !TextUtils.isEmpty(receivedType)) {
- if (receivedAction.equals(Intent.ACTION_SEND) && receivedType.equals("text/x-vcard")) {
- doSomething(getVCardContent(receivedIntent));
- return true;
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- /**
- * Attempt to get data android:mimeType="text/x-vcard" content from Uri provided
- * @param pIntent
- * @return
- */
- String getVCardContent(Intent pIntent) {
- Uri vcard_uri = (Uri) pIntent.getExtras().get(Intent.EXTRA_STREAM);
- ContentResolver cr = getContentResolver();
- InputStream stream = null;
- try {
- stream = cr.openInputStream(vcard_uri);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- StringBuffer fileContent = new StringBuffer("");
- int ch;
- try {
- while ((ch = stream.read()) != -1) {
- fileContent.append((char) ch);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return new String(fileContent);
- }
- void doSomething(String data) {
- Log.i("TAG", "data: " + data);
- MwDialog.OK_Alert(data, new POS_ButtonHandler() {
- @Override
- public void onPositiveClick() {}
- });
- }
- void parseVCard() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement