-1

I am newbie in android, i have this url now i need to encode this url: the url that has to be encoded. With Reference of downloading apk in Mobile using Java how can i pass this url to this Line :

updateAppInstance.execute("http://demo.ingresssolutions.com/proposalmanagement/services/user/getApkFile");

Previous post Regarding Apk Download

http://demo.ingresssolutions.com/proposalmanagement/services/user/uploadFile

Community
  • 1
  • 1
Erum
  • 790
  • 3
  • 14
  • 36

2 Answers2

0

Contrary to many answers you will read, java.net.URLEncoder isn't for encoding URLs. It is for encoding URL and POST arguments.

The correct way to encode a URL in Java is as given in this answer, or, if you only need to encode the path component:

String encodedPath = new URI(null, path, null).toASCIIString();
Community
  • 1
  • 1
user207421
  • 305,947
  • 44
  • 307
  • 483
-1
import java.net.URL; 
import java.net.URLEncoder;
import java.net.MalformedURLException; 
import java.io.UnsupportedEncodingException;

public class Encoder{
 public static void main(String[] args){
  URL url = null; 
  try{
   url = new URL("http://www.stackoverflow.com");       
  }catch(MalformedURLException mue){
   System.err.println(mue); 
  }
  System.out.println(url + "
"); 
  try{
   String encodedurl = URLEncoder.encode(url.toString(),"UTF-8"); 
   System.out.println(encodedurl);
  }catch(UnsupportedEncodingException uee){
   System.err.println(uee);
  }
 }
}

Hope this helps you

Raj
  • 600
  • 1
  • 5
  • 18