美文网首页
Android 使用ACTION_SEND的intent.get

Android 使用ACTION_SEND的intent.get

作者: 费麭 | 来源:发表于2017-12-20 00:01 被阅读0次

因为有适配问题

Uri fileUri;
if (TextUtils.equals(action, Intent.ACTION_SEND)) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // 16上使用intent.getClipData()获取uri
        if (getIntent().getClipData() != null) {
            if (getIntent().getClipData().getItemCount() > 0) {
                fileUri = getIntent().getClipData().getItemAt(0).getUri();
            }
        }
    } else {
        fileUri = getIntent().getData();
    }
} else {
    fileUri = getIntent().getData();
}
if (fileUri != null) { 
  // do sth...
}

注意在jelly_bean16上有适配问题,必须使用ClipData(剪切板)获取intent数据。

相关文章

网友评论

      本文标题:Android 使用ACTION_SEND的intent.get

      本文链接:https://www.haomeiwen.com/subject/rkdwwxtx.html