mySimpleDraweeView.setImageURI(Uri.parse("http://cdn.cnn.com:80/cnn/.e1mo/img/4.0/logos/menu_politics.png"));
This is a url from link preview for cnn. It is an http url and not an https url. It has a port :80 in the path.
If I throw that url into a webbrowser, it gets resolved as "http://cdn.cnn.com/cnn/.e1mo/img/4.0/logos/menu_politics.png" and an image is there.
If I try to call setImageURI with "http://cdn.cnn.com/cnn/.e1mo/img/4.0/logos/menu_politics.png" from the web browser, it still doesn't work.
If I try to call setImageURI with "https://cdn.cnn.com/cnn/.e1mo/img/4.0/logos/menu_politics.png" it works.
I'm using a custom OKHttp3 OkHttpClient for Fresco. I tried using the getUnsafeOkHttpClient described here https://stackoverflow.com/a/25992879/1578222, but did not see a change in behavior with it.
I also tried setting the OkHttpClient.followRedirects but it did not fix it either:
httpClient.followSslRedirects(true);
httpClient.followRedirects(true);
I found a log message from the OKHttp3 client and that helped me figure out the problem:
<-- HTTP FAILED: java.net.UnknownServiceException: CLEARTEXT communication to cdn.cnn.com not permitted by network security policy
Solved my changing the Android Manifest file's Application object to include:
android:usesCleartextTraffic="true"
you can use any external library like Picasso and then show the image by using it
Related
Im trying to make a url encoder app. I tried to use java.net.urlencoder but I cant find its buildr, direct importing doest work for me also same problem from httpclient.
Can you give some working gradle/maven about java.net or http client
I'm writing a Java app. When I try to make a request to an API using OkHttp, nothing is returned. When I went to the request URL in a browser, I got the response {"Message":"The requested resource does not support http method 'GET'."}
I can only find help online if you're the one hosting the server. Is there anything I, as the one making the request, can do? Or do I have to wait until the API people can fix it?
You fool, you just assumed that the problem with your request was caused by the message in the browser! In actuality, it was a bug in your Android emulator. You simply needed to cold boot the emulated device, and it was fixed!
Following this post: http://android-developers.blogspot.com/2016/01/play-games-permissions-are-changing-in.html I have obtained a single use authorization code for use on my backend server as follows:
import com.google.android.gms.games.Games;
//later
Games.GetServerAuthCodeResult result = Games.getGamesServerAuthCode(gameHelper.getApiClient(), server_client_id).await();
if (result.getStatus().isSuccess()) {
String authCode = result.getCode();
// Send code to server...
This seems to works fine, but it presents a question:
1) getGamesServerAuthCode and GetServerAuthCodeResult are marked as deprecated. Why? Should I be using something else instead?
2) How would I do something equivalent in an non-Android installed Java application? I am able to obtain a token on the client application, but I also need to obtain a single use code to pass to my backend server like above. I can't find an equivalent function to get a Server Auth Code. (using com.google.api.client.extensions.java6.auth.oauth2)
I am basically trying to follow this flow: https://developers.google.com/games/services/web/serverlogin but in Java, NOT Javascript. I am attempting to do this in an Android app and a desktop Java app.
1) Yes, in Android use GetServerAuthCodeResult although it is still marked as deprecated. It is the recommended way from Google and it seems they have only forgot to remove the deprecation annotation when releasing to general public.
2) For desktop applications you can follow the instructions here: https://developers.google.com/identity/protocols/OAuth2InstalledApp
Basically from your app you open the system browser (embedded webviews are discouraged) and make a https request to the https://accounts.google.com/o/oauth2/v2/auth endpoint. In the request you supply a local redirect URI parameter i.e. http://127.0.0.1:9004 (you should query your platform for the relevant loopback IP, and start a HTTP listener on a random available port). The authorization code will be sent to your local HTTP listener when the user has given consent or an error such as error=access_denied if the user declined the request. Your application must be listening on this local web server to retrieve the response with the authcode. You also have the option to redirect to a server URI directly claimed by your app, see docs on link above. When your app receives the authorization response, for best usability, it should respond with an HTML page, instructing the user to close the browser tab and return to your app. Also, if you want the Games-scope make sure you are using the https://www.googleapis.com/auth/games as scope in the request, example below, with line breaks and spaces for readability.
https://accounts.google.com/o/oauth2/v2/auth?
scope=https://www.googleapis.com/auth/games&
redirect_uri=http://127.0.0.1:9004&
response_type=code&
client_id=812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amrf.apps.googleusercontent.com
Please note that I think you'll have to create and link an app of type other, in the Google Play Developer Console linked-app, for the localhost redirection to work. Use type Web if you plan to redirect to server URI directly, add your server URI to Authorized redirect URIs in the API Manager under section Credentials.
Browser screenshot:
There is finally a proper answer to part 1) of this question!
In the release notes of gms 10.2.0
https://developers.google.com/android/guides/releases#february_2017_-_v102
the new method of obtaining a server code is described. A good example of how to do this is provided here:
https://github.com/playgameservices/clientserverskeleton
I ended up updating Google's baseGameUtils to follow the example above.
Still not sure the proper way to do this for part 2) of the question, at the moment I am sending the token to the server which works but is probably unsafe.
Checking the extension of the file works in most cases, but not for all. Consider the following link:
http://t0.gstatic.com/images?q=tbn:ANd9GcTqqcX4SsdwgithvRcjQl_W3Hj-eIc_12FvdeGS2sO31uZ0F1HHqcdRKNo
Can I check from the URL if it is a link to an image? If not, is there a way to check after the page has loaded in the webview?
I know that I could download every page using HttpURLConnection, but I'm trying to avoid that approach.
Check Response HTTP Header Content-Type. It will be one of the image types. For Example, if I open the URL you have provided in Browser, will see Content-Type as show below
Content-Type:image/jpeg
You can use HttpHead method to fetch just the headers
I want to download a file from a Sharepoint server that protected with NTLM authentication from my Android application. I found some tutorials and couldn't successful.
I tried using The Java CIFS Client Library and did not successful again.
I investigated this post: Manipulating SharePoint list items with Android (JAVA) and NTLM Authentication but i do not want to consume a webservice, i just want to download a file.
Any suggestions?
Did you use standard Java java.net.Authenticator http://developer.android.com/reference/java/net/Authenticator.html? If it doesn't support NTLM check http://developer.android.com/reference/org/apache/http/auth/NTCredentials.html and related org.apache.http package. Also look at blog http://mrrask.wordpress.com/2009/08/21/android-authenticating-via-ntlm/ where it is shown how to use it. In par
Why complicate things
You should be able to send the authentication in the Uri.
URL url = new URL ("http://user:pass#sub.domain.com/FolderName/FileName.docx");
This technique should work with both Windows Authentication and Basic Authentication
Try using Chilkat, although it's not free. but you can easily implement it in your code.
Chilkat Link