今天写这片文章主要是记录下 app跳转到微信的实现方法,我的项目需求是跳转到微信公众号,由于微信官方关闭了这个直接可以跳到公众号的接口,只能 从app打开微信,让用户自己去搜索。
我的项目需求:


点击跳转微信的时候,我实现了点击复制的方法,这样客户也省去了输入公众号的繁琐。
点击复制文本的代码:
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,用户自己打开微信公众号直接粘贴上搜索就可以了。
题外话:
点击复制,传参
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就是你想要的内容。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持天达云。