首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何从intent filter调用启动完整的应用程序?

如何从intent filter调用启动完整的应用程序?
EN

Stack Overflow用户
提问于 2018-08-16 03:37:23
回答 1查看 0关注 0票数 0

我已在我的清单中声明:

代码语言:javascript
复制
        <intent-filter>
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>

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

        <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="audio/*" />
        </intent-filter>

从其他应用程序获取可共享内容,如手机的gallary。一切都运行正常,但有一个问题,我想从意图过滤器打开整个应用程序,因为我的应用程序是覆盖gallary应用程序,而不是我自己的应用程序。

EN

回答 1

Stack Overflow用户

发布于 2018-08-16 13:16:32

从其他应用接收简单数据:

代码语言:javascript
复制
<activity android:name=".ui.MyActivity" >
<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.SEND_MULTIPLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
</intent-filter>
</activity>

你的活动中的getData:

代码语言:javascript
复制
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();

if (Intent.ACTION_SEND.equals(action) && type != null) {
    if ("text/plain".equals(type)) {
        handleSendText(intent); // Handle text being sent
    } else if (type.startsWith("image/")) {
        handleSendImage(intent); // Handle single image being sent
    }
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
    if (type.startsWith("image/")) {
        handleSendMultipleImages(intent); // Handle multiple images being sent
    }
} else {
    // Handle other intents, such as being started from the home screen
}
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档