How can I handle file uploading to other apps and sites? Android

269 views Asked by At

I am working on a simple android file manager. The problem I am facing is getting my app to upload files to another app or site when someone wants to send files and such. I tried reading through the developer docs, but they were a bit confusing. How can I set up my MainActivity(If that is a good place to put this) to handle this and allow the uploading of files? Here is what I have in my manifest...

<activity android:name="com.myapp.MainActivity" android:label="@string/app_name"
                  android:configChanges="keyboardHidden|screenSize|orientation">
            <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.GET_CONTENT"/>
                <category android:name="android.intent.category.OPENABLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="*/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PICK"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="file"/>
                <data android:scheme="folder"/>
                <data android:scheme="directory"/>
            </intent-filter>
            <meta-data android:name="android.app.searchable"
                       android:resource="@xml/searchable"/>
        </activity>
1

There are 1 answers

1
Sam Edwards On

You don't need anything in your manifest file. Use Android's share intent to share content with other applications on the device. Here is the documentation: http://developer.android.com/training/sharing/send.html

The Example:

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));