Example usage for android.net Uri parse

List of usage examples for android.net Uri parse

Introduction

In this page you can find the example usage for android.net Uri parse.

Prototype

public static Uri parse(String uriString) 

Source Link

Document

Creates a Uri which parses the given encoded URI string.

Usage

From source file:Main.java

public static InputStream getISFromURI(Context context, Uri contentURI) {
    ContentResolver res = context.getContentResolver();
    Uri uri = Uri.parse(contentURI.toString());
    InputStream is = null;/*ww w.  j av  a 2 s  . c o  m*/
    try {
        is = res.openInputStream(uri);
    } catch (FileNotFoundException e) {
        jlog(e);
    }

    return is;
}

From source file:Main.java

public static void openBrowser(Context context, String url) {
    if (!TextUtils.isEmpty(url)) {
        if (!url.startsWith("http://") && !url.startsWith("https://")) {
            url = "http://" + url;
        }/*  www  . jav  a  2  s.c o m*/
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    } else {
        Log.e("Helpers#openBrowser", "Something isn't right about the URL passed");
    }
}

From source file:Main.java

public static boolean installNormal(Context context, String filePath) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);
    if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    } else {//from  w w  w  .j  ava  2  s  . c  o m
        intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    }
}

From source file:Main.java

public static void showOperaBrowser(Context context, String visitUrl) {
    Intent intent = new Intent();
    intent.setClassName("com.opera.mini.android", "com.opera.mini.android.Browser");
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse(visitUrl));
    context.startActivity(intent);//from w  ww  .ja va2 s . co m
}

From source file:Main.java

public static ResolveInfo getDefaultBrowser(Context context) {
    PackageManager pm = context.getPackageManager();

    Intent query = new Intent();
    query.setAction(Intent.ACTION_VIEW);
    query.setData(Uri.parse("http://localhost"));

    ResolveInfo info = pm.resolveActivity(query, 0);

    if (info == null) {
        return info;
    }/* w w  w .  ja  v  a  2s  .c o  m*/

    // Could be a Chooser
    if (info.activityInfo.packageName.equals("android")) {
        return null;
    }

    return info;
}

From source file:Main.java

public static List<ResolveInfo> getBrowsers(Context context) {
    PackageManager pm = context.getPackageManager();

    Intent query = new Intent();
    query.setAction(Intent.ACTION_VIEW);
    query.setData(Uri.parse("http://localhost"));

    return pm.queryIntentActivities(query, 0);
}

From source file:Main.java

public static void installApk(Context context, String fileName) {
    if (fileName != null && fileName.contains(".apk")) {
        //         File f = new File(fileName);
        //         if(f.exists()){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setDataAndType(Uri.parse("file://" + fileName), "application/vnd.android.package-archive");
        context.startActivity(intent);//from  w ww .jav a  2s  . c o m
        //         }
    }
}

From source file:Main.java

/**
 * Forces the Android gallery to  refresh its thumbnail images.
 * @param context//from   w  ww. j  a v  a2s .co  m
 * @param fdelete
 */
private static void refreshGalleryImages(Context context, File fdelete) {
    try {
        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    } catch (Exception e1) {
        try {
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri contentUri = Uri.fromFile(fdelete);
            mediaScanIntent.setData(contentUri);
            context.sendBroadcast(mediaScanIntent);
        } catch (Exception e2) {
        }
    }
}

From source file:Main.java

public static final Uri getImageUri(Context inContext, Bitmap inImage) {
    //      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    //      inImage.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

From source file:Main.java

/**
 * Method to get more apps/*from ww w . j  av a  2s.  c  om*/
 * 
 * @param context
 * @param publisherName
 */
public static void getMoreApps(Context context, String publisherName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:" + publisherName));
    if (isIntentAvailable(context, intent)) {
        context.startActivity(intent);
    } else {
        Toast.makeText(context, "Network Error", Toast.LENGTH_LONG).show();
    }
}