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.bf.zxd.zhuangxudai.my.fragment.CompanyApplyFragment.java

private void startPhoneZoom(Uri uri) {
    Log.e("Daniel", "---uri---" + uri);
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, "image/*");
    Log.e("Daniel", "--- intent.getDataString()---" + intent.getDataString());
    Log.e("Daniel", "---  intent.getData()---" + intent.getData());

    //???/*  ww w .  jav a  2 s .  c  om*/
    intent.putExtra("corp", "true");
    //?
    intent.putExtra("aspectY", 1);
    intent.putExtra("aspectX", 1);
    //?
    intent.putExtra("outputX", 150);
    intent.putExtra("outputY", 150);
    //?
    intent.putExtra("return-data", true);
    startActivityForResult(intent, RESULT_PHOTO);
}

From source file:org.mythdroid.util.UpdateService.java

private void updateMythDroid(String ver, String url) {

    LogUtil.debug("Fetching APK from " + url); //$NON-NLS-1$

    HttpFetcher fetcher = null;//  www .  java2 s .co  m
    try {
        fetcher = new HttpFetcher(url, false);
    } catch (ClientProtocolException e) {
        ErrUtil.logErr(e);
        notify("MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
                e.getMessage());
        return;
    } catch (IOException e) {
        ErrUtil.logErr(e);
        notify("MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
                e.getMessage());
        return;
    }

    final File storage = Environment.getExternalStorageDirectory();
    final File outputFile = new File(storage.getAbsolutePath() + '/' + "Download", //$NON-NLS-1$
            "MythDroid-" + ver + ".apk" //$NON-NLS-1$ //$NON-NLS-2$
    );

    LogUtil.debug("Saving to " + outputFile.getAbsolutePath()); //$NON-NLS-1$

    FileOutputStream outputStream;
    try {
        outputStream = new FileOutputStream(outputFile);
    } catch (FileNotFoundException e) {
        ErrUtil.logErr("SDCard is unavailable"); //$NON-NLS-1$
        notify("MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
                Messages.getString("UpdateService.4") //$NON-NLS-1$
        );
        return;
    }

    try {
        fetcher.writeTo(outputStream);
    } catch (IOException e) {
        ErrUtil.logErr(e);
        notify("MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
                e.getMessage());
        return;
    }

    LogUtil.debug("Download successful, installing..."); //$NON-NLS-1$

    final Intent installIntent = new Intent(Intent.ACTION_VIEW);
    installIntent.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive" //$NON-NLS-1$
    );
    installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(installIntent);

}

From source file:RhodesService.java

public static void installApplication(final String url) {
    Thread bgThread = new Thread(new Runnable() {
        public void run() {
            try {
                final RhodesService r = RhodesService.getInstance();
                final File tmpFile = r.downloadPackage(url);
                if (tmpFile != null) {
                    PerformOnUiThread.exec(new Runnable() {
                        public void run() {
                            try {
                                Logger.D(TAG, "Install package " + tmpFile.getAbsolutePath());
                                Uri uri = Uri.fromFile(tmpFile);
                                Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setDataAndType(uri, "application/vnd.android.package-archive");
                                r.startActivity(intent);
                            } catch (Exception e) {
                                Log.e(TAG, "Can't install file from " + tmpFile.getAbsolutePath(), e);
                                Logger.E(TAG, "Can't install file from " + tmpFile.getAbsolutePath() + ": "
                                        + e.getMessage());
                            }//from   www .  jav a2  s  .com
                        }
                    });
                }
            } catch (IOException e) {
                Log.e(TAG, "Can't download package from " + url, e);
                Logger.E(TAG, "Can't download package from " + url + ": " + e.getMessage());
            }
        }
    });
    bgThread.setPriority(Thread.MIN_PRIORITY);
    bgThread.start();
}

From source file:com.android.messaging.ui.UIIntentsImpl.java

@Override
public void launchSaveVCardToContactsActivity(final Context context, final Uri vcardUri) {
    Assert.isTrue(MediaScratchFileProvider.isMediaScratchSpaceUri(vcardUri));
    final Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(vcardUri, ContentType.TEXT_VCARD.toLowerCase());
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startExternalActivity(context, intent);
}

From source file:com.dafeng.upgradeapp.util.AutoUpdateApk.java

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

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        setChanged();/* w w w.ja v  a  2s.  c  o m*/
        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:org.dvbviewer.controller.ui.fragments.StreamConfig.java

/**
 * Gets the video intent.//from   w w w .  j a  v a2  s  . c  o  m
 *
 * @return the video intent
 * @author RayBa
 * @date 07.04.2013
 */
private Intent getVideoIntent() {
    String videoUrl = null;
    String videoType = null;
    switch (mStreamType) {
    case STREAM_TYPE_DIRECT:
        switch (mFileType) {
        case FILE_TYPE_LIVE:
            videoUrl = liveUrl + mFileId + ".ts";
            break;
        case FILE_TYPE_RECORDING:
            videoUrl = mediaUrl + mFileId + ".ts";
            break;

        default:
            break;
        }
        videoType = "video/*";

        break;
    case STREAM_TYPE_TRANSCODE:
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Preset", String.valueOf(qualitySpinner.getSelectedItemPosition())));
        params.add(new BasicNameValuePair("aspect", aspectSpinner.getSelectedItem().toString()));
        params.add(new BasicNameValuePair("ffPreset", ffmpegSpinner.getSelectedItem().toString()));

        /**
         * Check if height is set from user, otherwise the the default values are used
         */
        if (widthSpinner.getSelectedItemPosition() > 0) {
            params.add(new BasicNameValuePair("maxwidth", widthSpinner.getSelectedItem().toString()));
        }
        if (heightSpinner.getSelectedItemPosition() > 0) {
            params.add(new BasicNameValuePair("maxheight", heightSpinner.getSelectedItem().toString()));
        }

        /**
         * Calculate startposition in seconds
         */
        int hours = TextUtils.isEmpty(startHours.getText()) ? 0
                : Integer.valueOf(startHours.getText().toString());
        int minutes = TextUtils.isEmpty(startMinutes.getText()) ? 0
                : Integer.valueOf(startMinutes.getText().toString());
        int seconds = TextUtils.isEmpty(startSeconds.getText()) ? 0
                : Integer.valueOf(startSeconds.getText().toString());
        int start = 3600 * hours + 60 * minutes + seconds;
        params.add(new BasicNameValuePair("start", String.valueOf(start)));

        switch (mFileType) {
        case FILE_TYPE_LIVE:
            params.add(new BasicNameValuePair("chid", String.valueOf(mFileId)));
            break;
        case FILE_TYPE_RECORDING:
            params.add(new BasicNameValuePair("recid", String.valueOf(mFileId)));
            break;

        default:
            break;
        }
        String query = URLEncodedUtils.format(params, "utf-8");
        videoUrl = flashUrl + query;
        break;

    default:
        break;
    }
    Log.i(StreamConfig.class.getSimpleName(), "url: " + videoUrl);

    DVBViewerPreferences prefs = new DVBViewerPreferences(getActivity());
    boolean external = prefs.getPrefs().getBoolean(DVBViewerPreferences.KEY_STREAM_EXTERNAL_PLAYER, true);
    Intent videoIntent;
    if (external) {
        videoType = "video/mpeg";
        videoIntent = new Intent(Intent.ACTION_VIEW);
        videoIntent.setDataAndType(Uri.parse(videoUrl), videoType);
    } else {
        videoIntent = new Intent(getActivity(), VideoPlayerActivity.class);
        videoIntent.setData(Uri.parse(videoUrl));
    }
    return videoIntent;
}

From source file:com.bitants.wally.fragments.ImageZoomFragment.java

private void setImageAsWallpaperPicker(Uri fileUri) {
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setType("image/*");

    MimeTypeMap map = MimeTypeMap.getSingleton();
    String mimeType = map.getMimeTypeFromExtension("png");
    intent.setDataAndType(fileUri, mimeType);
    intent.putExtra("mimeType", mimeType);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    startActivity(Intent.createChooser(intent, getString(R.string.action_set_as)));
}

From source file:com.cloudexplorers.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 * /*from w w  w  . j  av  a 2s .c  om*/
 * @param url
 *          The url to load.
 * @param usePhoneGap
 *          Load url in PhoneGap webview
 * @return "" if ok, or error message.
 */
public String openExternal(String urlToOpen, String encodedCredentials) {
    try {
        // set the download URL, a url that points to a file on the internet
        // this is the file to be downloaded
        URL url = new URL(urlToOpen);

        // create the new connection
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

        // set up some things on the connection
        urlConnection.setRequestMethod("GET");
        urlConnection.setDoOutput(true);

        urlConnection.setRequestProperty("Authorization", encodedCredentials);

        // and connect!
        urlConnection.connect();

        // set the path where we want to save the file
        // in this case, going to save it on the root directory of the
        // sd card.
        File SDCardRoot = Environment.getExternalStorageDirectory();
        // create a new file, specifying the path, and the filename
        // which we want to save the file as.
        File file = new File(SDCardRoot, "temp.pdf");

        // this will be used to write the downloaded data into the file we created
        FileOutputStream fileOutput = new FileOutputStream(file);

        // this will be used in reading the data from the internet
        InputStream inputStream = urlConnection.getInputStream();

        // this is the total size of the file
        int totalSize = urlConnection.getContentLength();
        // variable to store total downloaded bytes
        int downloadedSize = 0;

        // create a buffer...
        byte[] buffer = new byte[1024];
        int bufferLength = 0; // used to store a temporary size of the buffer

        // now, read through the input buffer and write the contents to the file
        while ((bufferLength = inputStream.read(buffer)) > 0) {
            // add the data in the buffer to the file in the file output stream (the
            // file on the sd card
            fileOutput.write(buffer, 0, bufferLength);
            // add up the size so we know how much is downloaded
            downloadedSize += bufferLength;

        }
        // close the output stream when done
        fileOutput.close();

        Uri path = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        this.cordova.getActivity().startActivity(intent);

        // catch some possible errors...
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return "";

}

From source file:com.esri.arcgisruntime.sample.editfeatureattachments.EditAttachmentActivity.java

private void fetchAttachmentAsync(final int position, final View view) {

    progressDialog.setTitle(getApplication().getString(R.string.downloading_attachments));
    progressDialog.setMessage(getApplication().getString(R.string.wait));
    progressDialog.show();//www.java  2s  .c om

    // create a listenableFuture to fetch the attachment asynchronously
    final ListenableFuture<InputStream> listenableFuture = attachments.get(position).fetchDataAsync();
    listenableFuture.addDoneListener(new Runnable() {
        @Override
        public void run() {
            try {
                String fileName = attachmentList.get(position);
                // create a drawable from InputStream
                Drawable d = Drawable.createFromStream(listenableFuture.get(), fileName);
                // create a bitmap from drawable
                Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
                File root = Environment.getExternalStorageDirectory();
                File fileDir = new File(root.getAbsolutePath() + "/ArcGIS/Attachments");
                // create folder /ArcGIS/Attachments in external storage
                boolean isDirectoryCreated = fileDir.exists();
                if (!isDirectoryCreated) {
                    isDirectoryCreated = fileDir.mkdirs();
                }
                File file = null;
                if (isDirectoryCreated) {
                    file = new File(fileDir, fileName);
                    FileOutputStream fos = new FileOutputStream(file);
                    // compress the bitmap to PNG format
                    bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
                    fos.flush();
                    fos.close();
                }

                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                // open the file in gallery
                Intent i = new Intent();
                i.setAction(android.content.Intent.ACTION_VIEW);
                i.setDataAndType(Uri.fromFile(file), "image/png");
                startActivity(i);

            } catch (Exception e) {
                Log.d(TAG, e.toString());
            }

        }
    });
}

From source file:cm.aptoide.pt.Aptoide.java

private void doUpdateSelf() {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + TMP_UPDATE_FILE), "application/vnd.android.package-archive");

    startActivityForResult(intent, UPDATE_SELF);
}