I am trying to add header authorization while loading by url img. I tested in postman it works fine , but on mobile device it doesnt work.
Here is the code:
private Picasso getPicasso() { OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request newRequest = chain.request().newBuilder() .addHeader("Authorization", "Bearer " + userPrefs.accessToken().get()) .build(); return chain.proceed(newRequest); } }); return new Picasso.Builder(getActivity()).downloader(new OkHttpDownloader(okHttpClient)).build(); } And how i use it :
getPicasso().load(ServiceGateway.API_BASE_URL + "me/avatar") .networkPolicy(NetworkPolicy.OFFLINE) .into(ivUserImage); Gradle:
compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.okhttp:okhttp:2.5.0' What i am doing wrong here ?
newRequestwas not called at all.