增加tiktok分享功能
This commit is contained in:
parent
a1ee38a70e
commit
6283a0a66b
@ -108,10 +108,12 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".tiktokapi.TikTokEntryActivity"
|
||||
android:exported="true"></activity>
|
||||
android:launchMode="singleTask"
|
||||
android:taskAffinity="com.cege.games.release"
|
||||
android:exported="true" />
|
||||
<activity
|
||||
android:name=".apple.AppleLoginActivity"
|
||||
android:theme="@style/WebViewTheme"></activity>
|
||||
android:theme="@style/WebViewTheme" />
|
||||
<activity
|
||||
android:name=".apple.AppleLoginCbActivity"
|
||||
android:exported="true">
|
||||
|
@ -18,6 +18,9 @@ import android.widget.Toast;
|
||||
import com.bytedance.sdk.open.tiktok.TikTokOpenApiFactory;
|
||||
import com.bytedance.sdk.open.tiktok.api.TikTokOpenApi;
|
||||
import com.bytedance.sdk.open.tiktok.authorize.model.Authorization;
|
||||
import com.bytedance.sdk.open.tiktok.base.MediaContent;
|
||||
import com.bytedance.sdk.open.tiktok.base.VideoObject;
|
||||
import com.bytedance.sdk.open.tiktok.share.Share;
|
||||
import com.cege.games.release.activity.CustomCaptureActivity;
|
||||
import com.cege.games.release.activity.WebPageActivity;
|
||||
import com.cege.games.release.apple.AppleLoginActivity;
|
||||
@ -74,6 +77,7 @@ import org.cocos2dx.lib.Cocos2dxHelper;
|
||||
import org.cocos2dx.lib.CocosJSHelper;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -117,6 +121,8 @@ public class MainActivity extends UnityPlayerActivity
|
||||
public static final int RC_READ_PHOTO = 0X012;
|
||||
|
||||
public static final int RC_LOAD_KEY = 0X013;
|
||||
|
||||
public static final int FILE_SELECTOR_CODE = 0X014;
|
||||
private String title;
|
||||
private String funId;
|
||||
private String oid;
|
||||
@ -134,6 +140,8 @@ public class MainActivity extends UnityPlayerActivity
|
||||
private CountDownLatch mAuthIntentLatch = new CountDownLatch(1);
|
||||
private static final String EXTRA_FAILED = "failed";
|
||||
|
||||
private TikTokOpenApi tiktokOpenApi;
|
||||
|
||||
public String getFunId() {
|
||||
return funId;
|
||||
}
|
||||
@ -191,6 +199,8 @@ public class MainActivity extends UnityPlayerActivity
|
||||
Intent appLinkIntent = getIntent();
|
||||
String appLinkAction = appLinkIntent.getAction();
|
||||
Uri appLinkData = appLinkIntent.getData();
|
||||
|
||||
tiktokOpenApi = TikTokOpenApiFactory.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -229,6 +239,10 @@ public class MainActivity extends UnityPlayerActivity
|
||||
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
|
||||
handleSignInResult(task);
|
||||
break;
|
||||
case FILE_SELECTOR_CODE:
|
||||
Uri uri = data.getData();
|
||||
shareToTikTok(uri);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
boolean next = false;
|
||||
@ -771,7 +785,6 @@ public class MainActivity extends UnityPlayerActivity
|
||||
this.funId = funId;
|
||||
Log.i(TAG, "login with tiktok: " + funId);
|
||||
// STEP 1: Create an instance of TiktokOpenApi
|
||||
TikTokOpenApi tiktokOpenApi = TikTokOpenApiFactory.create(this);
|
||||
|
||||
// STEP 2: Create an instance of Authorization.Request and set parameters
|
||||
Authorization.Request request = new Authorization.Request();
|
||||
@ -893,10 +906,50 @@ public class MainActivity extends UnityPlayerActivity
|
||||
public void showPage(String fid, final String url) {
|
||||
runOnUiThread(() -> {
|
||||
Log.i(TAG, "show page: " + url);
|
||||
Intent intent = new Intent(this, WebPageActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
startActivity(intent);
|
||||
// Intent intent = new Intent(this, WebPageActivity.class);
|
||||
// intent.putExtra("url", url);
|
||||
// startActivity(intent);
|
||||
openFileSelector();
|
||||
});
|
||||
}
|
||||
public void shareToTikTok(Uri uriToImage) {
|
||||
grantUriPermission("com.zhiliaoapp.musically",
|
||||
uriToImage, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
grantUriPermission("com.ss.android.ugc.trill",
|
||||
uriToImage, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
Log.i(TAG, "share to tiktok: " + uriToImage.toString());
|
||||
if (tiktokOpenApi.isShareSupportFileProvider()) {
|
||||
Share.Request request = new Share.Request();
|
||||
ArrayList<String> mUri = new ArrayList<>();
|
||||
mUri.add(uriToImage.toString());
|
||||
VideoObject videoObject = new VideoObject();
|
||||
videoObject.mVideoPaths = mUri;
|
||||
MediaContent content = new MediaContent();
|
||||
content.mMediaObject = videoObject;
|
||||
|
||||
// 3.set required parameters
|
||||
request.mMediaContent = content;
|
||||
request.mShareFormat = Share.Format.DEFAULT;
|
||||
tiktokOpenApi.share(request);
|
||||
}
|
||||
// runOnUiThread(() -> {
|
||||
// Log.i(TAG, "share to tiktok: " + uriToImage);
|
||||
// Intent shareIntent = new Intent();
|
||||
// shareIntent.setAction(Intent.ACTION_SEND);
|
||||
// shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
|
||||
// shareIntent.setType("video/*");
|
||||
// startActivity(Intent.createChooser(shareIntent, "share"));
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开本地文件器
|
||||
*/
|
||||
private void openFileSelector() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("video/*");
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
startActivityForResult(intent, FILE_SELECTOR_CODE);
|
||||
}
|
||||
|
||||
}
|
@ -3,13 +3,16 @@ package com.cege.games.release.tiktokapi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bytedance.sdk.open.tiktok.CommonConstants;
|
||||
import com.bytedance.sdk.open.tiktok.TikTokOpenApiFactory;
|
||||
import com.bytedance.sdk.open.tiktok.api.TikTokOpenApi;
|
||||
import com.bytedance.sdk.open.tiktok.authorize.model.Authorization;
|
||||
import com.bytedance.sdk.open.tiktok.common.handler.IApiEventHandler;
|
||||
import com.bytedance.sdk.open.tiktok.common.model.BaseReq;
|
||||
import com.bytedance.sdk.open.tiktok.common.model.BaseResp;
|
||||
import com.bytedance.sdk.open.tiktok.share.Share;
|
||||
import com.jc.jcfw.JcSDK;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
@ -41,6 +44,9 @@ public class TikTokEntryActivity extends Activity implements IApiEventHandler {
|
||||
JcSDK.nativeCb(response.state, response.errorMsg, null);
|
||||
}
|
||||
finish();
|
||||
} else if (resp.getType() == CommonConstants.ModeType.SHARE_CONTENT_TO_TT_RESP) {
|
||||
Share.Response response = (Share.Response) resp;
|
||||
Log.i(TAG, "share result code:" + response.errorCode + " errorMessage:" + response.errorMsg);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
|
@ -9,7 +9,7 @@
|
||||
name="root_path"
|
||||
path="." />
|
||||
</path>
|
||||
|
||||
<external-files-path name="sharedata" path="shareData/"/>
|
||||
<external-path
|
||||
name="camera_photos"
|
||||
path="" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user