调用Android系统分享功能(可分享纯文本信息)
2017-09-10 17:32
621 查看
前面有一篇博客说了使用QQ登录并获取用户QQ信息,也实现了分享消息到QQ功能,前面一篇博客使用的是腾讯QQ的开放接口,而且使用腾讯开放接口分享消息到QQ,不能分享纯文本信息,这个看了官方的API就知道了!
下面介绍另一种方法,不用使用什么开放接口,直接使用系统的就可以,并且可以分享纯文本信息!
main.xml也就一个按钮,设置了android:onClick="shareToQQ"属性!!!
到此实现了分享纯文本消息到QQ!
按钮监听直接调用这个方法就可以了!
效果:
下面介绍另一种方法,不用使用什么开放接口,直接使用系统的就可以,并且可以分享纯文本信息!
一、直接将消息分享到QQ:
package com.example.demo3; import java.util.List; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.view.View; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void shareToQQ(View view){ shareQQ(MainActivity.this); } public void shareQQ(Context mContext) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "这是要分享的消息"); sendIntent.setType("text/plain"); try { sendIntent.setClassName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity"); Intent chooserIntent = Intent.createChooser(sendIntent, "选择分享途径"); if (chooserIntent == null) { return; } mContext.startActivity(chooserIntent); } catch (Exception e) { mContext.startActivity(sendIntent); } } }
main.xml也就一个按钮,设置了android:onClick="shareToQQ"属性!!!
到此实现了分享纯文本消息到QQ!
二、实现多应用选择分享
public void shareMsg(String activityTitle, String msgTitle, String msgText, String imgPath) { Intent intent = new Intent(Intent.ACTION_SEND); if (imgPath == null || imgPath.equals("")) { intent.setType("text/plain"); // 纯文本 } else { File f = new File(imgPath); if (f != null && f.exists() && f.isFile()) { intent.setType("image/jpg"); Uri u = Uri.fromFile(f); intent.putExtra(Intent.EXTRA_STREAM, u); } } intent.putExtra(Intent.EXTRA_SUBJECT, msgTitle); intent.putExtra(Intent.EXTRA_TEXT, msgText); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent, activityTitle)); }
按钮监听直接调用这个方法就可以了!
效果:
相关文章推荐
- Android调用系统分享功能以及createChooser的使用
- Android实现调用系统分享功能示例的总结
- android 调用系统中分享功能
- Android:调用系统分享功能
- Android 调用系统分享功能
- Android:调用系统分享功能
- 探索Android调用系统的分享功能
- android调用系统的分享功能实现分享到短信,邮件和其他
- 探索Android调用系统的分享功能
- Android调用系统分享功能以及createChooser的使用
- Android调用系统分享功能总结
- Android调用系统分享功能以及createChooser的使用
- Android:调用系统分享功能
- Android-调用系统粘贴板copy复制文本功能及复制文本到粘贴板
- Android分享---调用系统自带的分享功能
- Android调用系统本身的分享功能
- Android调用系统分享功能以及createChooser的使用
- Android调用系统自带的分享功能实例代码
- Android调用系统分享功能以及createChooser的使用
- Android 调用系统的分享功能