Android如何使用ContentProvider向其他应用发送ContentURI?
创始人
2024-10-09 22:34:46
0
  1. 在发送端的应用中,创建自定义的ContentProvider,并在AndroidManifest.xml文件中进行声明,同时定义好Content URI对应的MIME类型。
public class MyContentProvider extends ContentProvider {
    public static final String AUTHORITY = "com.example.mycontentprovider";
    public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);
 
    // ... 省略其他操作 ...
 
    @Override
    public String getType(Uri uri) {
        // 返回Content URI对应的MIME类型
        return "vnd.android.cursor.item/mytable";
    }
}
  1. 在发送端的应用中,使用下面的代码来创建带有Content URI的Intent,并发送给接收端应用。
Uri contentUri = ContentUris.withAppendedId(MyContentProvider.CONTENT_URI, id);
 
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(getContentResolver().getType(contentUri));
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
startActivity(Intent.createChooser(intent, "Share File"));
  1. 在接收端的应用中,使用getParcelableExtra方法获取Content URI,并对其进行处理。
Uri receivedUri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
if (receivedUri != null) {
    // 处理Content URI
}

相关内容

热门资讯

值得注意的是!wepoker辅... 值得注意的是!wepoker辅助软件视频(透视)竟然真的有辅助插件(有挂方针)-哔哩哔哩wepoke...
无独有偶!wepoker私人局... 无独有偶!wepoker私人局辅助挂(透视)总是是有辅助工具(发现有挂)-哔哩哔哩1.wepoker...
透视好友房!pokernow辅... 透视好友房!pokernow辅助工具(透视)原来真的是有辅助app(有挂技术)-哔哩哔哩1、poke...
据通报!wepoker数据分析... 据通报!wepoker数据分析(透视)确实有辅助插件(有挂技术)-哔哩哔哩1、起透看视 wepoke...
今天上午!wepoker免费辅... 今天上午!wepoker免费辅助器(透视)一直真的有辅助下载(有挂规律)-哔哩哔哩1、下载好wepo...
透视ai代打!wepoker游... 透视ai代打!wepoker游戏下载(透视)一直是真的辅助安装(有挂秘诀)-哔哩哔哩透视ai代打!w...
今天下午!wepoker有没有... 今天下午!wepoker有没有机器人(透视)本来是真的辅助平台(有挂分析)-哔哩哔哩1、wepoke...
有了最新消息!aapoker公... 有了最新消息!aapoker公共底牌(透视)一直存在有辅助插件(有挂方针)-哔哩哔哩1、进入游戏-大...
透视实锤!德州局透视脚本免费版... 透视实锤!德州局透视脚本免费版下载手机版(透视)竟然真的有辅助插件(有挂方法)-哔哩哔哩一、德州局透...
透视私人局!uupoker透视... 透视私人局!uupoker透视(透视)一直真的有辅助工具(真是有挂)-哔哩哔哩1、首先打开uupok...