Android IDownloaderClient.STATE_下载obb文件时未经许可而失败
我已经学习了很多关于发布obb文件的教程,在创建了以下类之后,我导入了lvl库和apkx:Android IDownloaderClient.STATE_下载obb文件时未经许可而失败,android,file,expansion,Android,File,Expansion,我已经学习了很多关于发布obb文件的教程,在创建了以下类之后,我导入了lvl库和apkx: import com.google.android.vending.expansion.downloader.impl.DownloaderService; public class SampleDownloadService extends DownloaderService { private static final String BASE64_PUBLIC_KEY = "KEY_FRO
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();
}
}
另一类:
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"/>
在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\u failed\u unlicensed。看起来我应该将我的电子邮件添加到google play开发者控制台并将其更改为licensed
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()
}