Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
In doing today to share a file into the micro-channel function, micro-channel has been experiencing the return of "access to resources failure" by Intent.
code show as below:
Intent intent = new Intent();
//设置intent的Action属性
intent.setAction(Intent.ACTION_SEND);
// 授权读权限
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//设置intent的data和Type属性。
intent.setDataAndType(uri, type);
activity.startActivity(intent);
There are several reasons
1. You need to get permissions are stored
2. You need intent.addFlags (Intent.FLAG_GRANT_READ_URI_PERMISSION); authorize temporary external application permissions
3. You need to add this one
intent.putExtra(Intent.EXTRA_STREAM, uri); // 必须添加这一句,否则找不到资源
Such a sentence was later found in the notes, presumably meant for compatibility with old applications you need to use ACTION_SEND must add EXTRA_TEXT or EXTRA_STREAM both FLAG
* As of {@link android.os.Build.VERSION_CODES#JELLY_BEAN}, the data
* being sent can be supplied through {@link #setClipData(ClipData)}. This
* allows you to use {@link #FLAG_GRANT_READ_URI_PERMISSION} when sharing
* content: URIs and other advanced features of {@link ClipData}. If
* using this approach, you still must supply the same data through the
* {@link #EXTRA_TEXT} or {@link #EXTRA_STREAM} fields described below
* for compatibility with old applications. If you don't set a ClipData,
* it will be copied there for you when calling {@link Context#startActivity(Intent)}.
In this card for a long time, records about it