【问题标题】:How can I handle file uploading to other apps and sites? Android如何处理文件上传到其他应用程序和网站?安卓
【发布时间】:2013-08-20 14:31:56
【问题描述】:

我正在开发一个简单的 android 文件管理器。我面临的问题是当有人想要发送文件等时,让我的应用程序将文件上传到另一个应用程序或网站。我尝试阅读开发人员文档,但它们有点令人困惑。如何设置我的 MainActivity(如果这是放置这个的好地方)来处理这个并允许上传文件?这是我的清单中的内容...

<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>

【问题讨论】:

    标签: java android manifest file-uri


    【解决方案1】:

    清单文件中不需要任何内容​​。使用 Android 的共享意图与设备上的其他应用程序共享内容。这是文档:http://developer.android.com/training/sharing/send.html

    例子:

    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)));
    

    【讨论】:

    • 那是不同的。我想要完成的是,例如,当您打开 gmail 应用程序并编写电子邮件时,您可以选择附加文件,并且当您选择它打开应用程序选择器时。我能够将我的应用程序放在那里,但我不知道应该如何处理意图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    相关资源
    最近更新 更多