android 把自己app作为一个分享渠道

  • 在需要被分享后打开的Activity的Manifest文件中加入如下标签
    <intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="text/plain" />
    </intent-filter>
  • 通过分享会引起一个Intent来传递给你的Activity 之后启动
        Intent intent = getActivity().getIntent();
        String action = intent.getAction();  //分享的action都是Intent.ACTION_SEND
        String type = intent.getType();//获取分享来的数据类型,和上面<data android:mimeType="text/plain" />中的一致
        //具体还有其他的类型,请上网参考
        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) { 
                //do sth.
            }
        }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容