Example usage for android.content Intent setDataAndType

List of usage examples for android.content Intent setDataAndType

Introduction

In this page you can find the example usage for android.content Intent setDataAndType.

Prototype

public @NonNull Intent setDataAndType(@Nullable Uri data, @Nullable String type) 

Source Link

Document

(Usually optional) Set the data for the intent along with an explicit MIME data type.

Usage

From source file:com.zsxj.pda.ui.client.LoginActivity.java

private void download(String url) {
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    Uri downloadUri = Uri.parse(url);/*w  w w.  j a  v a 2  s.  com*/
    DownloadManager.Request request = new DownloadManager.Request(downloadUri);
    String fileName = url.substring(url.lastIndexOf("/") + 1);
    File downloadDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
    Log.d("debug", downloadDir.toString());
    File updateFile = new File(downloadDir, fileName);
    Log.d("debug", updateFile.toString());
    if (updateFile.exists()) {
        Intent promtInstall = new Intent(Intent.ACTION_VIEW);
        promtInstall.setDataAndType(Uri.fromFile(updateFile), "application/vnd.android.package-archive");
        startActivity(promtInstall);
        finish();
    } else {
        request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, fileName);
        long downloadId = dm.enqueue(request);
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
        editor.putLong(PrefKeys.DOWNLOAD_ID, downloadId);
        editor.commit();
    }
}

From source file:org.openintents.updatechecker.UpdateChecker.java

public void parseVeeCheck(String uri) {
    VeecheckResult result = null;/*from  w  w  w . ja  v  a 2s. com*/
    try {
        VeecheckVersion version = new VeecheckVersion(mPackageName, String.valueOf(mCurrentVersion),
                mCurrentVersionName);
        try {
            result = performRequest(version, uri);
        } catch (Exception e) {
            Log.v(LOG_TAG, "Failed to process versions.", e);
            return;
        } finally {
        }

        if (result.matched) {
            Log.d(LOG_TAG, "Matching intent found.");
            if (result.latestVersion.getVersionCode() != null) {
                try {
                    mLatestVersion = Integer.parseInt(result.latestVersion.getVersionCode());
                } catch (NumberFormatException e) {
                    mLatestVersion = 0;
                }
            } else {
                mLatestVersion = 0;
            }
            mLatestVersionName = result.latestVersion.getVersionName();
            mComment = null;

            // create intent
            Intent intent = new Intent();
            if (Intent.ACTION_VIEW.equals(result.action)) {
                intent.setAction(result.action);
                if (result.data != null) {
                    Uri intentUri = Uri.parse(result.data);
                    if (result.type != null) {
                        intent.setDataAndType(intentUri, result.type);
                    } else {
                        intent.setData(intentUri);
                    }
                } else {
                    if (result.type != null) {
                        intent.setType(result.type);
                    }
                }

                if (result.extras != null) {
                    for (Entry<String, String> e : result.extras.entrySet()) {
                        intent.putExtra(e.getKey(), e.getValue());
                    }
                }
                ResolveInfo info = mContext.getPackageManager().resolveActivity(intent, 0);
                if (info != null) {
                    mUpdateIntent = intent;
                }
            } else {
                Log.v(TAG, "no view action but " + result.action);
            }

        } else {
            result = null;
            Log.d(LOG_TAG, "No matching intent found.");
        }

    } finally {

    }
}

From source file:com.openerp.base.ir.Attachment.java

@SuppressWarnings("deprecation")
private Notification setFileIntent(Uri uri) {
    Log.v(TAG, "setFileIntent()");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    FileNameMap mime = URLConnection.getFileNameMap();
    String mimeType = mime.getContentTypeFor(uri.getPath());
    intent.setDataAndType(uri, mimeType);
    mNotificationResultIntent = PendingIntent.getActivity(mContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mNotificationBuilder.addAction(R.drawable.ic_oe_notification, "Download attachment",
            mNotificationResultIntent);//  w  ww  . j  av a2  s .  c  o m
    mNotificationBuilder.setOngoing(false);
    mNotificationBuilder.setAutoCancel(true);
    mNotificationBuilder.setContentTitle("Attachment downloaded");
    mNotificationBuilder.setContentText("Download Complete");
    mNotificationBuilder.setProgress(0, 0, false);
    mNotification = mNotificationBuilder.build();
    mNotification.setLatestEventInfo(mContext, "Attachment downloaded", "Download complete",
            mNotificationResultIntent);
    return mNotification;

}

From source file:com.autoupdateapk.AutoUpdateApk.java

protected void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    // nm.cancel( NOTIFICATION_ID ); // tried this, but it just doesn't do
    // the trick =(
    nm.cancelAll();/*www  .  j  av a  2  s . c  om*/

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        setChanged();
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= NOTIFICATION_FLAGS;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}

From source file:com.mediatek.galleryfeature.stereo.segment.background.StereoBackgroundActivity.java

private void setupMenu() {
    if (mMenu == null || mMasterImage == null) {
        return;//from  w  w  w  .j av a 2s  .co  m
    }

    mMenuRefineOriginal = mMenu.findItem(R.id.refine_refine_foreground);
    mMenuRefineOriginal.setVisible(true);

    mMenuRefineOriginal.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Intent intent = new Intent("action_stereo_pick");
            intent.setDataAndType(getIntent().getData(), getIntent().getType())
                    .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            if (mMaskSimulator != null) {
                mMaskSimulator.release();
                mMaskSimulator = null;
            }

            startActivityForResult(intent, REQUEST_CODE_REFINE);

            return false;
        }
    });
}

From source file:com.polyvi.xface.extension.XAppExt.java

private void setIntentByUri(Intent intent, Uri uri) {
    if (!XConstant.FILE_SCHEME.contains(uri.getScheme())) {
        intent.setData(uri);/* www . j a va  2  s  .  c o m*/
    } else {
        String mimeType = XFileUtils.getMIMEType(uri.toString());
        intent.setDataAndType(uri, XStringUtils.isEmptyString(mimeType) ? "*/*" : mimeType);
    }
}

From source file:com.polyvi.xface.extension.XAppExt.java

/**
 * apk/*from w  w  w . j  a v a 2s .  c om*/
 *
 * @param path
 *            ?apk
 */
public void install(String path, XCallbackContext callbackCtx) {
    registerInstallerReceiver(callbackCtx);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    // ???, ?apk?
    XFileUtils.setPermission(XFileUtils.READABLE_BY_OTHER, path);
    intent.setDataAndType(Uri.fromFile(new File(path)), APK_TYPE);
    getContext().startActivity(intent);
}

From source file:com.mediatek.galleryfeature.stereo.fancycolor.FancyColorActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int action = item.getItemId();
    switch (action) {
    case R.id.action_refine:
        mEffectManager.setMaskBufferToSegment();
        Intent intent = new Intent(STEREO_PICK_ACTION);
        intent.setClass(FancyColorActivity.this, StereoRefineActivity.class);
        intent.setDataAndType(mSourceUri, mIntent.getType()).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivityForResult(intent, REQUEST_STEREO_PICK);
        break;/*from  w  ww.j av a  2s  .  c  om*/
    default:
        break;
    }
    return true;
}

From source file:com.android.music.AlbumBrowserActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
    intent.putExtra("album", Long.valueOf(id).toString());
    intent.putExtra("artist", mArtistId);
    startActivity(intent);//from  w w  w  . j av  a2 s  . co m
}

From source file:cn.com.caronwer.activity.CertificationActivity.java

/**
 * ?//from w  ww .  j ava  2s  .c o  m
 *
 * @param uri
 */

public void startPhotoZoom(Uri uri) {

    Intent intent = new Intent("com.android.camera.action.CROP");
    String filename = BitmapUtil.getPath(this, uri);
    assert filename != null;
    uri = Uri.fromFile(new File(filename));
    intent.setDataAndType(uri, "image/*");
    // crop=true?IntentVIEW??
    intent.putExtra("crop", true);
    intent.putExtra("scale", true);// ?
    intent.putExtra("scaleUpIfNeeded", true);// 
    // aspectX aspectY 
    intent.putExtra("aspectX", 1);
    intent.putExtra("aspectY", 1);
    // outputX outputY ?
    intent.putExtra("outputX", 200);
    intent.putExtra("outputY", 200);
    intent.putExtra("return-data", true);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    System.out.println("start intent");
    startActivityForResult(intent, REQUESTCODE_CUTTING);
}