源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

android app跳转到微信的示例

  • 时间:2020-02-01 01:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:android app跳转到微信的示例
今天写这片文章主要是记录下 app跳转到微信的实现方法,我的项目需求是跳转到微信公众号,由于微信官方关闭了这个直接可以跳到公众号的接口,只能 从app打开微信,让用户自己去搜索。 我的项目需求: [img]http://files.jb51.net/file_images/article/201712/2017121315512331.png[/img] [img]http://files.jb51.net/file_images/article/201712/2017121315512332.png[/img] 点击跳转微信的时候,我实现了点击复制的方法,这样客户也省去了输入公众号的繁琐。 点击复制文本的代码:
ClipboardManager tvCopy = (ClipboardManager) getBaseActivity().getSystemService(Context.CLIPBOARD_SERVICE);
tvCopy.setText("XXX");
XXX即为你的公众号。 如图所示:点击去关注跳转到微信,就打开微信了。
/**
 * 跳转到微信
 */
private void getWechatApi(){
  try {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    ComponentName cmp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.LauncherUI");
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(cmp);
    startActivity(intent);
  } catch (ActivityNotFoundException e) {
    // TODO: handle exception
    getBaseActivity().showToastLong("检查到您手机没有安装微信,请安装后使用该功能");
  }
}
里面的 showToastLong方法即为自定义的Toast提示。 OK,用户自己打开微信公众号直接粘贴上搜索就可以了。 [b]题外话:[/b] 点击复制,传参
ClipboardManager tvCopy = (ClipboardManager) getBaseActivity().getSystemService(Context.CLIPBOARD_SERVICE);
tvCopy.setText("XXX");
XXX可以直接使用下面的方法替代:
tv.getText().toString().trim();
获取复制的内容:
ClipboardManager tvPaste = (ClipboardManager) getBaseActivity().getSystemService(Context.CLIPBOARD_SERVICE);
String content = tvPaste.getText().toString().trim();
content就是你想要的内容。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部