Hello,
My app size is more than 150 MB because it contains 3 pdfs and play store dont let me upload my aap bundle.
I saw android
Integrate Asset Delivery and followed the step the way below, now I dont know whether I followed the steps correctly or if I made any error coping and pasting the code. Please help.
I created a directory named assetspacks, then created subdirectories src/main/assets in it and then copied the code to my app.
Please help me, it also gives me an error:
Attempt to invoke interface method 'com.google.android.gms.tasks.Task com.google.android.play.core.assetpacks.AssetPackManager.getPackStates(java.util.List)' on a null object reference
Please help.
What I have tried:
AssetPackManager assetPackManager;
AssetPackStateUpdateListener assetPackStateUpdateListener;
ConnectivityManager connManager;
NetworkInfo mWifi;
boolean waitForWifiConfirmationShown;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String assetPackName = "assetspacks";
connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if(mWifi.isConnected()){
waitForWifiConfirmationShown = false;
}
else
{
waitForWifiConfirmationShown = true;
}
assetPackManager.getPackStates(Collections.singletonList(assetPackName))
.addOnCompleteListener(new OnCompleteListener<AssetPackStates>() {
@Override
public void onComplete(Task<AssetPackStates> task) {
AssetPackStates assetPackStates;
try {
assetPackStates = task.getResult();
AssetPackState assetPackState =
assetPackStates.packStates().get(assetPackName);
} catch (RuntimeExecutionException e) {
Log.d("MainActivity", e.getMessage());
return;
}
}
});
assetPackStateUpdateListener = new AssetPackStateUpdateListener() {
@Override
public void onStateUpdate(AssetPackState assetPackState) {
switch (assetPackState.status()) {
case AssetPackStatus.PENDING:
Log.i(TAG, "Pending");
break;
case AssetPackStatus.DOWNLOADING:
long downloaded = assetPackState.bytesDownloaded();
long totalSize = assetPackState.totalBytesToDownload();
double percent = 100.0 * downloaded / totalSize;
Log.i(TAG, "PercentDone=" + String.format("%.2f", percent));
break;
case AssetPackStatus.TRANSFERRING:
break;
case AssetPackStatus.COMPLETED:
break;
case AssetPackStatus.FAILED:
Log.e(TAG, String.valueOf(assetPackState.errorCode()));
break;
case AssetPackStatus.CANCELED:
break;
case AssetPackStatus.WAITING_FOR_WIFI:
if (!waitForWifiConfirmationShown) {
assetPackManager.showCellularDataConfirmation(MainActivity.this)
.addOnSuccessListener(new OnSuccessListener<Integer>() {
@Override
public void onSuccess(Integer resultCode) {
if (resultCode == RESULT_OK) {
Log.d(TAG, "Confirmation dialog has been accepted.");
} else if (resultCode == RESULT_CANCELED) {
Log.d(TAG, "Confirmation dialog has been denied by the user.");
}
}
});
waitForWifiConfirmationShown = true;
}
break;
case AssetPackStatus.NOT_INSTALLED:
break;
case AssetPackStatus.UNKNOWN:
Log.wtf(TAG, "Asset pack status unknown");
break;
}
}
};
setContentView(R.layout.activity_main);