QQ分享纯文本(兼容TIM)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* @param content 要分享QQ纯文本
*/
public void shareQQText(String content) {
if (AppUtils.isAppInstalled("com.tencent.mobileqq")||AppUtils.isAppInstalled("com.tencent.tim")) {
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, content);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(AppUtils.isAppInstalled("com.tencent.mobileqq")?"com.tencent.mobileqq":"com.tencent.tim", "com.tencent.mobileqq.activity.JumpActivity"));
Utils.getApp().startActivity(intent);
} else {
CustomToast.showShort("您需要安装QQ客户端");
}
}


/**
* 判读App是否安装
*/
public boolean isAppInstalled(Context context, String packageName){
if (TextUtils.isEmpty(packageName))
return false;
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES);
return true;
} catch (PackageManager.NameNotFoundException e) {

return false;
}
}
坚持原创技术分享,您的支持将鼓励我继续创作!