Android 使用ACTION_SEND的intent.get

2017-12-20  本文已影响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数据。

上一篇 下一篇

猜你喜欢

热点阅读