Search code examples
androidfileexpansion

IDownloaderClient.STATE_FAILED_UNLICENSED while downloading obb file android


I've followed many tutorials for publishing obb file, I've imported the lvl library and apkx after that I created the following classes:

import com.google.android.vending.expansion.downloader.impl.DownloaderService;

public class SampleDownloadService extends DownloaderService {
private static final String BASE64_PUBLIC_KEY = "KEY_FROM_PLAY_CONSOLE";
private static final byte[] SALT = new byte[]{
        1, 43, 16, 1, 54, 48,
        30, 1, 43, 2, 101, -4, 9, 54, -100, -108, -33, 45, -1, 84
};

/**
 * This public key comes from your Android Market publisher account, and it
 * used by the LVL to validate responses from Market on your behalf.
 */
@Override
public String getPublicKey() {
    return BASE64_PUBLIC_KEY;
}

/**
 * This is used by the preference obfuscater to make sure that your
 * obfuscated preferences are different than the ones used by other
 * applications.
 */
@Override
public byte[] getSALT() {
    return SALT;
}

/**
 * Fill this in with the class name for your alarm receiver. We do this
 * because receivers must be unique across all of Android (it's a good idea
 * to make sure that your receiver is in your unique package)
 */
@Override
public String getAlarmReceiverClassName() {
    return SampleAlarmReceiver.class.getName();
 }
}

And the other class:

import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller;

 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager.NameNotFoundException;


public class SampleAlarmReceiver extends BroadcastReceiver {

   @Override
public void onReceive(Context context, Intent intent) {
    try {
        DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent, SampleDownloadService.class);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

}

after that I declared in my manifest file in application tag:

    <service android:name=".services.SampleDownloadService"/>
    <receiver android:name=".services.SampleAlarmReceiver"/>

then in my activity:

    private val FILENAME =
    "main." + BuildConfig.VERSION_CODE.toString() + "." + BuildConfig.APPLICATION_ID.toString() + ".obb"

and in OnCreate:

try {
        // Check if expansion files are available before going any further
        if (!expansionFilesDelivered()) {
            // Build an Intent to start this activity from the Notification
            val notifierIntent = Intent(this, MainActivity::class.java.javaClass)
            notifierIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or
                    Intent.FLAG_ACTIVITY_CLEAR_TOP
            val pendingIntent = PendingIntent.getActivity(
                this, 0,
                notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT
            )

            // Start the download service (if required)
            val startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(
                this,
                pendingIntent, SampleDownloadService::class.java
            )
            // If download has started, initialize this activity to show
            // download progress
            if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
                // This is where you do set up to display the download
                // progress (next step)
                downloaderClientStub = DownloaderClientMarshaller.CreateStub(
                    this,
                    SampleDownloadService::class.java
                )
                return
            } // If the download wasn't necessary, fall through to start the app
        }else{
            tvModelDownload.visibility = View.GONE
            progressBar2.visibility = View.GONE
            val obbDir = obbDir
            val obbFile = File(obbDir, FILENAME)
            checkForModel(obbFile)
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }

Then I published my app in internal test section and added the obb file while uploading in the play console.

the error is that I'm always getting failed unlicensed error: IDownloaderClient.STATE_FAILED_UNLICENSED.


Solution

  • It looked that I should add my email to google play developer console and change it to licensed