废话
首先附上系统分享内容到其他应用的方法:
https://my.oschina.net/u/1462828/blog/2086000
分享是调起系统分享接口,是拿不到分享成功与否的状态的,并且分享到其他APP了之后一般不会带有来源自xxxAPP的这种标识,因为对方应用不知道分享是来源自什么地方什么应用。
分享主要是根据文件的类型进行划分,有图片、视频、音频、文字等常见类型,也有所有的文件类型,即:(*/*)
常见的几种类型:(text/plain)、(image/*)、(audio/*)、(video/*)、(*/*)
接收分享
1、新建一个Activity,这里叫ShareReceiveActivity,并在AndroidManifest里面注册它,然后根据类型,加上相关的配置代码,具体如下:
<activity android:name=\".module.share.ShareReceiveActivity\">
<intent-filter>
<action android:name=\"android.intent.action.SEND\" />
<category android:name=\"android.intent.category.DEFAULT\" />
<data android:mimeType=\"*/*\" />
</intent-filter>
<intent-filter>
<action android:name=\"android.intent.action.SEND_MULTIPLE\" />
<category android:name=\"android.intent.category.DEFAULT\" />
<data android:mimeType=\"*/*\" />
</intent-filter>
<intent-filter>
<action android:name=\"android.intent.action.SEND\" />
<category android:name=\"android.intent.category.DEFAULT\" />
<data android:mimeType=\"audio/*\" />
</intent-filter>
<intent-filter>
<action android:name=\"android.intent.action.SEND_MULTIPLE\" />
<category android:name=\"android.intent.category.DEFAULT\" />
<data android:mimeType=\"audio/*\" />
</intent-filter>
<intent-filter>
<action android:name=\"android.intent.action.SEND\" />
<category android:name=\"android.intent.category.DEFAULT\" />
<data android:mimeType=\"video/*\" />
</intent-filter>
<intent-filter>
<action android:name=\"android.intent.action.SEND_MULTIPLE\" />
<category android:name=\"android.intent.category.DEFAULT\" />
<data android:mimeType=\"video/*\" />
</intent-filter>
</activity>
2、配置好了之后,往用于接收分享的Activity的onCreate方法里面加接收代码:
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (\"audio/\".equals(type)) {
// 处理发送来音频
ToastUtils.showToast(getContext(),\"\");
} else if (type.startsWith(\"video/\")) {
// 处理发送来的视频
} else if (type.startsWith(\"*/\")) {
//处理发送过来的其他文件
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
ArrayList<Uri> arrayList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (type.startsWith(\"audio/\")) {
// 处理发送来的多个音频
} else if (type.startsWith(\"video/\")) {
//处理发送过来的多个视频
} else if (type.startsWith(\"*/\")) {
//处理发送过来的多个文件
}
}
版权声明
本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。




