package com.tecsun.tsb.jinzhou.activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.widget.Toast;
import java.util.List;
public class DouYinUtil {
public boolean checkAppInstalled(Context context, String pName) {
if (pName == null || pName.isEmpty()) {
return false;
}
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> info = packageManager.getInstalledPackages(0);
if (info == null || info.isEmpty()) {
return false;
}
for (int i = 0; i < info.size(); i++) {
if (pName.equals(info.get(i).packageName)) {
return true;
}
}
return false;
}
/***
* 进入抖音视频页面
* @param context
* @param url 视频作品ID
*/
public void jumpDouyinVedioPage(Context context, String url) {
Intent intent = new Intent();
if (checkAppInstalled(context, "com.ss.android.ugc.aweme")) //抖音
{
intent.setData(Uri.parse(url));
intent.setData(Uri.parse("snssdk1128://aweme/detail/" + url));
} else if (checkAppInstalled(context, "com.ss.android.article.video")) { //抖音极速版
intent.setData(Uri.parse("snssdk1112://aweme/detail/" + url));
} else if (checkAppInstalled(context, "com.ss.android.ugc.live")) { //抖音火山版
intent.setData(Uri.parse("snssdk1112://aweme/detail/" + url));
} else {
Toast.makeText(context, "请先安装此应用", Toast.LENGTH_SHORT).show();
return;
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
/***
* 进入抖音主页
* @param context
*/
public void jumpDouyinIndex(Context context) {
// 打开抖音主页
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName componentName = new ComponentName("com.ss.android.ugc.aweme","com.ss.android.ugc.aweme.splash.SplashActivity");
intent.setComponent(componentName);
context.startActivity(intent);
}
/***
* 进入抖音用户主页
* @param context
* @param url
*/
public void jumpDouyinUserIndex(Context context, String url) {
Intent intent = new Intent();
if (checkAppInstalled(context, "com.ss.android.ugc.aweme")) {//抖音
intent.setData(Uri.parse(url));
intent.setData(Uri.parse("snssdk1128://user/profile/" + url));
} else if (checkAppInstalled(context, "com.ss.android.article.video")) { //抖音极速版
intent.setData(Uri.parse("snssdk1112://user/profile/" + url));
} else if (checkAppInstalled(context, "com.ss.android.ugc.live")) { //抖音火山版
intent.setData(Uri.parse("snssdk1112://user/profile/" + url));
} else {
Toast.makeText(context, "请先安装此应用", Toast.LENGTH_SHORT).show();
return;
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
使用
DouYinUtil douYinUtil = new DouYinUtil();
douYinUtil.jumpDouyinVedioPage(this,"0000000000000000000");
// 照片id可以通过分享的链接获取,抖音分享之后浏览器打开的那个链接
douYinUtil.jumpDouyinUserIndex(this,"00000000000");
douYinUtil.jumpDouyinIndex(this);