• 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I would like my application to be able to receive vCards. Typically from an email attachment, but also files,etc. Unfortunately it does not show in the "Open with" / "Share with" menu.

This is the activity definition in the manifest:

     <activity
        android:name=".MyMainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW"/>
            <action android:name="android.intent.action.SEND" />
            <action android:name="android.intent.action.BROWSABLE"/>
            <action android:name="android.intent.action.EDIT" />
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
            <data android:scheme="http" android:host="*" android:pathPattern=".*\\.vcf"/>
            <data android:scheme="https" android:host="*" android:pathPattern=".*\\.vcf"/>
            <data android:scheme="content" android:host="*" android:pathPattern=".*\\.vcf"/>
            <data android:scheme="file" android:host="*" android:pathPattern=".*\\.vcf"/>
        </intent-filter>
    </activity>

My test vCard email attachment has a .vcf file extension, and the email marks the mimetype as text/vcard. I've used a *.* mimetype for testing - clearly this would not be appropriate for production code.

The above code is cribbed from other stackoverflow questions, blog posts, etc. I initially started with the following (both with a mimetype of text/vcard and then */*:

        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
      • 2
    • @sansa i think i'm doing everything in those answers? If it makes a difference, I'm testing with a tethered device - this a vcf test file and suitable emails.
    • Using file extensions isn't likely to work for email attachments or many other on-device uses. Go with your latter code snippet, replacing SEND with VIEW. If that works, refine the MIME type to text/vcard.
    • Thanks @CommonsWare - that appears to work. It appears, and selecting it does show my app's activity. It doesn't do anything with the vcard, but I think that is my internal mime-checking code. The compiler gives me the AppLinkUrl warning which I should at least double check.

For Web URLs and most on-device purposes, this should work with "Open With" sorts of options:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/vcard" />
    </intent-filter>

If you wanted to also support "Share With", you could try:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/vcard" />
    </intent-filter>

Note that how you get the content varies between those two actions:

  • For ACTION_VIEW, it is getData() on your Intent
  • For ACTION_SEND, look in the EXTRA_STREAM extra for a Uri or in the EXTRA_TEXT extra for the actual vCard text
  • 1
Reply Report
    • Yes that fixed it - thanks. I've implemented both VIEW and SEND. The ACTION_VIEW returns a Uri in getData(). Now I just need to parse the vCard :-)