获取隐含意图的操作和类别

时间:2015-03-23 12:52:38

标签: android android-intent

我需要从第三方库中捕获隐含的意图。它不起作用,所以我想验证我是否使用了正确的操作和类别。我认为LogCat可能会显示这一点,但似乎并非如此。

那么,如何显示隐式意图的动作和类别?

1 个答案:

答案 0 :(得分:0)

要捕获活动类中的隐含意图,请使用

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
}

如果您想进一步了解,请参阅此链接:

http://developer.android.com/training/sharing/receive.html