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 Intent getLaunchIntent(Context context, String title, String url, String sel) {
    Intent intent = null;/* w w  w .j  av a 2  s.  c  o  m*/
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        } else if (isYouTubeURL(url)) {
            intent.setPackage(YT_PACKAGE_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }

    if (sel != null && sel.length() > 0) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(sel);
    }

    return intent;
}

From source file:Main.java

public static Uri getAllCallLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) {
    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm");
    String[] callLogArray = new String[3];
    String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
    Uri callUri = Uri.parse("content://call_log/calls");
    Cursor cur = cr.query(callUri, null, null, null, strOrder);

    FileOutputStream fOut = null;
    try {/*from   w  w w.  j a v  a 2 s  .co m*/
        fOut = context.openFileOutput("call_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    OutputStreamWriter osw = new OutputStreamWriter(fOut);

    while (cur.moveToNext()) {
        callLogArray[0] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
        callLogArray[1] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));

        int thirdIndex = cur.getColumnIndex(android.provider.CallLog.Calls.DATE);
        long seconds = cur.getLong(thirdIndex);
        String dateString = formatter.format(new Date(seconds));
        callLogArray[2] = dateString;

        writeToOutputStreamArray(callLogArray, osw);
    }

    try {
        osw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return internal;
}

From source file:Main.java

public static Uri getFileUri(String dir, String fileName) {
    return Uri.parse(BASE + dir + "/" + fileName);
}

From source file:Main.java

/**
 * Get contact photo bitmap.//from w  ww.jav  a2s  .  co  m
 *
 * @param context context.
 * @param photo photo uri.
 * @return bitmap.
 */
public static Bitmap getContactBitmapFromURI(Context context, String photo) {
    // Get photo uri.
    Uri uri = Uri.parse(photo);

    try {
        // Get input.
        InputStream input = context.getContentResolver().openInputStream(uri);

        if (input == null) {
            return null;
        }

        return getRoundedCornerBitmap(BitmapFactory.decodeStream(input));
    } catch (FileNotFoundException ignored) {
    }

    return null;
}

From source file:Main.java

/**
 * Get video's duration without {@link ContentProvider}. Because not know
 * {@link Uri} of video./* ww w. j av  a 2  s. c  om*/
 *
 * @param context
 * @param path    Path of video file.
 * @return Duration of video, in milliseconds. Return 0 if path is null.
 */
public static long getDuration(Context context, String path) {
    MediaPlayer mMediaPlayer = null;
    long duration = 0;
    try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(context, Uri.parse(path));
        mMediaPlayer.prepare();
        duration = mMediaPlayer.getDuration();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (mMediaPlayer != null) {
            mMediaPlayer.reset();
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }
    return duration;
}

From source file:Main.java

public static void openSupportPage(Context context) {
    Uri supportUri = Uri.parse("https://notisync.uservoice.com");
    Intent intent = new Intent(Intent.ACTION_VIEW, supportUri);
    context.startActivity(intent);/*w  w w . j  av a  2  s.c o m*/
}

From source file:Main.java

/**
 * Get a reference to a copied file//from  w w w .j a v  a2s . c om
 * @param context Application Context
 * @param imageUri Source URI of an image
 * @return Reference to a copied file
 */
public static File getCopiedFile(Context context, String imageUri) {
    String filename;

    try {
        filename = String.format("%s.png", md5(imageUri));

    } catch (Exception e) {
        filename = Uri.parse(imageUri).getLastPathSegment();
    }

    File workingDir = getWorkingDir(context);
    File f = null;

    if (workingDir != null && workingDir.exists()) {
        f = new File(workingDir, filename);
    }

    return f;
}

From source file:Main.java

public static Boolean sendSms(Context mContext, String smstext) {
    Uri smsToUri = Uri.parse("smsto:");
    Intent mIntent = new Intent(android.content.Intent.ACTION_SENDTO, smsToUri);
    mIntent.putExtra("sms_body", smstext);
    mContext.startActivity(mIntent);//www  .ja  va 2 s.c o  m
    return null;
}

From source file:Main.java

public static void uninstallApp(Context context, String packageName) {
    Uri uri = Uri.parse("package:" + packageName);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*from w  w  w .j a v a 2 s  .c  o m*/
}

From source file:Main.java

public static Intent sendSms(String to, String message) {
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + to));
    intent.putExtra("sms_body", message);
    return intent;
}