add app version code to header
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package ch.pizzacucina.android.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -41,4 +43,15 @@ public class BaseActivity extends AppCompatActivity {
|
||||
BaseActivity.currentActivity = currentActivity;
|
||||
}
|
||||
|
||||
public int getAppVersionCode(){
|
||||
PackageInfo pInfo = null;
|
||||
try {
|
||||
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
return pInfo.versionCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -304,17 +304,6 @@ public class SplashActivity extends BaseActivity {
|
||||
return params;
|
||||
}
|
||||
|
||||
private int getAppVersionCode(){
|
||||
PackageInfo pInfo = null;
|
||||
try {
|
||||
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
return pInfo.versionCode;
|
||||
}
|
||||
|
||||
private void getCategoryList(){
|
||||
Call<ResponseArray<CategoryModel>> call = ApiService.apiInterface.getAllCategories(SessionHelper.getSelectedStore().getStoreName());
|
||||
call.enqueue(new Callback<ResponseArray<CategoryModel>>() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import ch.pizzacucina.android.BuildConfig;
|
||||
import ch.pizzacucina.android.activity.BaseActivity;
|
||||
import ch.pizzacucina.android.helper.SessionHelper;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -44,6 +45,8 @@ public class ApiService {
|
||||
|
||||
Request.Builder builder = chain.request().newBuilder();
|
||||
builder.addHeader("Content-Type", "application/json");
|
||||
builder.addHeader("application", ApiConstants.APP_TYPE_ID_ANDROID);
|
||||
builder.addHeader("version", getAppVersionCode());
|
||||
|
||||
String url = chain.request().url().toString();
|
||||
if(!url.contains("getSessionId") && !SessionHelper.getSessionId().isEmpty()){
|
||||
@@ -75,4 +78,15 @@ public class ApiService {
|
||||
|
||||
apiInterface = retrofit.create(ApiInterface.class);
|
||||
}
|
||||
|
||||
private String getAppVersionCode(){
|
||||
try{
|
||||
int versionCode = BaseActivity.currentActivity.getAppVersionCode();
|
||||
return String.valueOf(versionCode);
|
||||
}
|
||||
catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user