You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android直播应用使用Vidyo库生成Token的技术求助

Fixing Vidyo Token Generation in Your Android Live Stream App

Hey there! Let's work through this Token generation issue you're having with your Vidyo-based Android app. First off, I spot a couple of critical problems with your current approach—let's break them down and get you on the right track.

Why Your Current Method Isn't Working (And Why It's Risky)

  • Incorrect command line syntax: Your exec command has an extra space between -- and key (like -- key=), which will break argument parsing for the jar file. It should be --key= without the space, same for --appID= and other flags.
  • Android doesn’t support running arbitrary JARs this way: The Runtime.getRuntime().exec() approach assumes a full JVM is available to execute the jar, which isn’t guaranteed across all Android devices. Even if it works on your test device, it’ll fail on many others.
  • Huge security risk: Hardcoding your Developer_Key in the Android app and generating tokens client-side is a major red flag. Anyone can decompile your APK to steal the key, then generate unlimited tokens to abuse your Vidyo service.

The Correct Approach: Server-Side Token Generation

Vidyo explicitly recommends generating tokens on a backend server, not on the client. Here's how to set this up:

1. Create a Simple Backend Endpoint

Build a lightweight backend (e.g., Java Spring Boot, Node.js, etc.) that accepts a username and returns a valid Vidyo token. This way, your Developer_Key stays safe on the server, never exposed to the client.

Example Java backend code (using Vidyo's official Token generation logic):

import com.vidyo.token.TokenGenerator;

public class VidyoTokenService {
    private static final String DEVELOPER_KEY = "your-secure-developer-key";
    private static final String APP_ID = "your-vidyo-app-id";

    public String generateToken(String username, int expiresInSecs) {
        TokenGenerator tokenGenerator = new TokenGenerator(DEVELOPER_KEY);
        return tokenGenerator.generateToken(APP_ID, username, expiresInSecs);
    }
}

(Make sure to include Vidyo's token generation library in your backend dependencies.)

2. Call the Backend from Your Android App

Instead of trying to run a jar locally, use a network request (like Retrofit or OkHttp) to fetch the token from your backend.

Example OkHttp call in Android:

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
        .url("https://your-backend-domain.com/generate-token?username=G.Salah&expiresInSecs=75000")
        .build();

client.newCall(request).enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {
        // Handle error
        e.printStackTrace();
    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
        if (response.isSuccessful()) {
            String token = response.body().string();
            // Use this token to connect to Vidyo
        } else {
            // Handle server error
        }
    }
});

If You Must Test Locally (For Development Only!)

If you need to generate tokens locally during testing (never do this in production), use Vidyo's token generation library directly in your Android project instead of calling an external jar. Add the library to your build.gradle and use the same TokenGenerator logic as the backend example above.

If you really want to troubleshoot the exec command (again, don’t ship this), fix the syntax and ensure the jar is properly bundled with your app (note this will only work on devices with a compatible JVM):

// Fixed command syntax (removed spaces after --)
Process su = Runtime.getRuntime().exec(
    "java -jar /path/to/generateToken.jar --key=" + Developer_Key + 
    " --appID=" + APP_ID + 
    " --userName=G.Salah --expiresInSecs=75000"
);

You’ll also need to fully handle the process’s input/output (your code snippet cuts off) — make sure to read from both the InputStream and ErrorStream to debug why it’s failing.

内容的提问来源于stack exchange,提问作者Salah Hadaydeh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:29:02