int leng=ulink.length();
for (int i = 0; i <= (leng - 7);i++) {
if (ulink.regionMatches(i, "http://", 0, 6)) {
youtubelink=ulink;}}
for (int i = 0; i <= (leng - 4);i++) {
if (ulink.regionMatches(i, "www.", 0, 3)) {
youtubelink=ulink.replace("www.", "http://");
youtubelink=youtubelink.trim();}}
try{
url = as("user name", "api key").call(shorten(youtubelink));
String s1=url.getShortUrl();
feed1.append(" "+s1);
}
catch(Exception e)
{
showAlertDialog("please check your url and its wrong");
}
// Do something with value!
}
public class BitActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Url url = as("username", "key").call(shorten("http://google.com"));
String s=url.getShortUrl();
Log.e("url",s);
URLConnection conn = null;
conn = connectURL(s);
String sss=conn.toString();
Log.e("expand",sss);
}
private URLConnection connectURL(String s) {
// TODO Auto-generated method stub
URLConnection conn =null;
try {
URL inputURL = new URL(s);
conn = inputURL.openConnection();
// int test = 0;
}catch(MalformedURLException e) {
System.out.println("Please input a valid URL");
}catch(IOException ioe) {
System.out.println("Can not connect to the URL");
}
return conn;
}
its very simple
No comments:
Post a Comment