美文网首页Android知识
android 把自己app作为一个分享渠道

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

作者: MrRock | 来源:发表于2014-12-17 14:51 被阅读415次
  • 在需要被分享后打开的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.
            }
        }

相关文章

网友评论

    本文标题:android 把自己app作为一个分享渠道

    本文链接:https://www.haomeiwen.com/subject/xwuotttx.html