问题描述
我遵循了许多发布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_FROM_PLAY_CONSOLE";
private static final byte[] SALT = new byte[]{
1,43,16,1,54,48,30,2,101,-4,9,-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"/>
然后参加我的活动:
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,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开发者控制台并将其更改为许可