Share / Copy To from "e-mail" to Xamarin App

Ika777Ika777 Member ✭✭

Is there a way to "Copy To" / "Share" attachment to/with Xamarin App from e-mail. Basically make my application to show up in list of applications where file can be copied to or shared with? Could you please provide an examples how it can be done, both for iOS and Android? Thanks.

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    in iOS ,add the following code in info.plist.

    <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Unknown File</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.calendar-event</string>
                    <string>public.database</string>
                    <string>public.executable</string>
                    <string>public.data</string>
                    <string>public.content </string>
                    <string>public.item</string>
                </array>
            </dict>     
            <dict>
                <key>CFBundleTypeName</key>
                <string>Image</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.image</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Web Archive</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>com.apple.webarchive</string>
                </array>
            </dict>
    
            <dict>
                <key>CFBundleTypeName</key>
                <string>OpenDocument Spreadsheet</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>org.oasis.opendocument.spreadsheet</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>OpenDocument Presentation</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>org.oasis.opendocument.presentation</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>OpenDocument Text</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>org.oasis.opendocument.text</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Folder</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.folder</string>
                </array>
            </dict>
    
    
    
            <dict>
                <key>CFBundleTypeName</key>
                <string>GIF image</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>com.compuserve.gif</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>PNG image</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.png</string>
                </array>
            </dict>
    
            <dict>
                <key>CFBundleTypeName</key>
                <string>JPEG image</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.jpeg</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>XML</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.xml</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>HTML</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.html</string>
                    <string>public.xhtml</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Rich Text</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.rtf</string>
                    <string>com.apple.rtfd</string>
                    <string>com.apple.flat-rtfd</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Text</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.text</string>
                    <string>public.plain-text</string>
                    <string>public.utf8-plain-text</string>
                    <string>public.utf16-external-plain-​text</string>
                    <string>public.utf16-plain-text</string>
                    <string>com.apple.traditional-mac-​plain-text</string>
                    <string>public.source-code</string>
                    <string>public.c-source</string>
                    <string>public.objective-c-source</string>
                    <string>public.c-plus-plus-source</string>
                    <string>public.objective-c-plus-​plus-source</string>
                    <string>public.c-header</string>
                    <string>public.c-plus-plus-header</string>
                    <string>com.sun.java-source</string>
                    <string>public.script</string>
                    <string>public.shell-script</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeExtensions</key>
                <array>
                    <string>zip</string>
                    <string>zipx</string>
                </array>
                <key>CFBundleTypeName</key>
                <string>Zip archive</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>public.zip-archive</string>
                    <string>public.archive</string>
                    <string>com.pkware.zip-archive</string>
                    <string>com.pkware.zipx-archive</string>
                </array>
            </dict>
    
            <dict>
                <key>CFBundleTypeName</key>
                <string>Microsoft PowerPoint</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>com.microsoft.powerpoint.​ppt</string>
                    <string>org.openxmlformats.presentationml.presentation</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Microsoft Excel</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>org.openxmlformats.spreadsheetml.sheet</string>
                    <string>com.microsoft.excel.xls</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>Microsoft Word</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>com.microsoft.word.doc</string>
                    <string>com.microsoft.word.wordml</string>
                    <string>org.openxmlformats.wordprocessingml.document</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeName</key>
                <string>PDF</string>
                <key>LSHandlerRank</key>
                <string>Alternate</string>
                <key>LSItemContentTypes</key>
                <array>
                    <string>com.adobe.pdf</string>
                </array>
            </dict>
        </array>
    

    And you can handle the file in Appdelegate.cs

    public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
    {
         string path = url.AbsoluteString;
    
         // do something you want      
    
          return true;           
    }
    

    in Android ,add the following code in Manifest.xml

    <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.share.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    
                <intent-filter>
                        <action android:name="android.intent.action.SEND"/>
                            <category android:name="android.intent.category.DEFAULT"/>
    
                            <data android:mimeType="image/*" />
                                    <data android:mimeType="video/*" />                               
                                    <data android:mimeType="text/x-vcard" />
                                    <data android:mimeType="text/plain" />
                                    <data android:mimeType="text/html" />
                                    <data android:mimeType="application/zip" />
                                    <data android:mimeType="application/vnd.ms-excel" />
                                    <data android:mimeType="application/msword" />
                                    <data android:mimeType="application/vnd.ms-powerpoint" />
                                    <data android:mimeType="application/pdf" />
                                    //...other type
                </intent-filter>  
            </activity>
        </application>
    
    

    You can refer https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types to add the mimeType which you want to share :)

  • Ika777Ika777 Member ✭✭

    @LucasZhang Thanks a lot, will try it out and let you know :).

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    Hi ,does it work?

Sign In or Register to comment.