IDownloaderClient.STATE_FAILED_UNLICENSED 正在下载 obb 文件 android
IDownloaderClient.STATE_FAILED_UNLICENSED while downloading obb file android
我遵循了很多发布 obb 文件的教程,我导入了 lvl 库和 apkx 之后我创建了以下 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();
}
}
另一个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();
}
}
}
之后我在应用程序标签中的清单文件中声明:
<service android:name=".services.SampleDownloadService"/>
<receiver android:name=".services.SampleAlarmReceiver"/>
然后在我的 activity:
private val FILENAME =
"main." + BuildConfig.VERSION_CODE.toString() + "." + BuildConfig.APPLICATION_ID.toString() + ".obb"
并在 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()
}
然后我在内部测试部分发布了我的应用程序,并在播放控制台上传时添加了 obb 文件。
错误是我总是遇到未经许可的错误:IDownloaderClient.STATE_FAILED_UNLICENSED。
看来我应该将我的电子邮件添加到 google play developer console 并将其更改为 licensed
我遵循了很多发布 obb 文件的教程,我导入了 lvl 库和 apkx 之后我创建了以下 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();
}
}
另一个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();
}
}
}
之后我在应用程序标签中的清单文件中声明:
<service android:name=".services.SampleDownloadService"/>
<receiver android:name=".services.SampleAlarmReceiver"/>
然后在我的 activity:
private val FILENAME =
"main." + BuildConfig.VERSION_CODE.toString() + "." + BuildConfig.APPLICATION_ID.toString() + ".obb"
并在 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()
}
然后我在内部测试部分发布了我的应用程序,并在播放控制台上传时添加了 obb 文件。
错误是我总是遇到未经许可的错误:IDownloaderClient.STATE_FAILED_UNLICENSED。
看来我应该将我的电子邮件添加到 google play developer console 并将其更改为 licensed