Example usage for android.content Intent getType

List of usage examples for android.content Intent getType

Introduction

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

Prototype

public @Nullable String getType() 

Source Link

Document

Retrieve any explicit MIME type included in the intent.

Usage

From source file:com.krayzk9s.imgurholo.activities.MainActivity.java

private void processIntent(Intent intent) {
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();// w w  w . j  a va2s .c om
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("imgur-holo")) {
        Uri uri = intent.getData();
        Log.d("URI", "" + action + "/" + type);
        String uripath = "";
        if (uri != null)
            uripath = uri.toString();
        Log.d("URI", uripath);
        Log.d("URI", "HERE");

        if (uri != null && uripath.startsWith(ApiCall.OAUTH_CALLBACK_URL)) {
            apiCall.verifier = new Verifier(uri.getQueryParameter("code"));
            CallbackAsync callbackAsync = new CallbackAsync(apiCall, this);
            callbackAsync.execute();
        }
    } else if (getSupportFragmentManager().getFragments() == null) {
        loadDefaultPage();
    }
}

From source file:net.sourceforge.servestream.activity.MainActivity.java

private String getUri() {
    String intentUri = null;/*  w w  w.  j a  va 2  s  .  c om*/
    String contentType = null;

    Intent intent = getIntent();

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

    // check to see if we were called from a home screen shortcut
    if ((contentType = intent.getType()) != null) {
        if (contentType.contains("net.sourceforge.servestream/")) {
            intentUri = intent.getType().toString().replace("net.sourceforge.servestream/", "");
            setIntent(null);
            return intentUri;
        }
    }

    // check to see if we were called by clicking on a URL
    if (intent.getData() != null) {
        intentUri = intent.getData().toString();
    }

    // check to see if the application was opened from a share intent
    if (intent.getExtras() != null && intent.getExtras().getCharSequence(Intent.EXTRA_TEXT) != null) {
        intentUri = intent.getExtras().getCharSequence(Intent.EXTRA_TEXT).toString();
    }

    setIntent(null);

    return intentUri;
}

From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java

@Override
public void onStart() {
    super.onStart();

    Intent intent = getActivity().getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    if (files != null) {
        files.clear();//from  ww w.j  a  v a 2 s  .c  o  m
    }

    try {
        if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            if (AndroidVersion.isJBOrAbove()) {
                ClipData clipdata = intent.getClipData();
                if (clipdata != null && clipdata.getItemCount() > 1) {
                    Item item = null;
                    for (int i = 0; i < clipdata.getItemCount(); i++) {
                        item = clipdata.getItemAt(i);
                        Uri uri = item.getUri();
                        if (uri != null) {
                            retrieveIntentInfo(uri);
                        } else {
                            String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date());
                            File localParentFolder = StorageManager.getCacheDir(getActivity(),
                                    "AlfrescoMobile/import");
                            File f = createFile(localParentFolder, timeStamp + ".txt",
                                    item.getText().toString());
                            if (f.exists()) {
                                retrieveIntentInfo(Uri.fromFile(f));
                            }
                        }
                        if (!files.contains(file)) {
                            files.add(file);
                        }
                    }
                }
            } else {
                if (intent.getExtras() != null
                        && intent.getExtras().get(Intent.EXTRA_STREAM) instanceof ArrayList) {
                    @SuppressWarnings("unchecked")
                    List<Object> attachments = (ArrayList<Object>) intent.getExtras().get(Intent.EXTRA_STREAM);
                    for (Object object : attachments) {
                        if (object instanceof Uri) {
                            Uri uri = (Uri) object;
                            if (uri != null) {
                                retrieveIntentInfo(uri);
                            }
                            if (!files.contains(file)) {
                                files.add(file);
                            }
                        }
                    }
                } else if (file == null || fileName == null) {
                    MessengerManager.showLongToast(getActivity(),
                            getString(R.string.import_unsupported_intent));
                    getActivity().finish();
                    return;
                }
            }
        } else {
            // Manage only one clip data. If multiple we ignore.
            if (AndroidVersion.isJBOrAbove() && (!Intent.ACTION_SEND.equals(action) || type == null)) {
                ClipData clipdata = intent.getClipData();
                if (clipdata != null && clipdata.getItemCount() == 1 && clipdata.getItemAt(0) != null
                        && (clipdata.getItemAt(0).getText() != null
                                || clipdata.getItemAt(0).getUri() != null)) {
                    Item item = clipdata.getItemAt(0);
                    Uri uri = item.getUri();
                    if (uri != null) {
                        retrieveIntentInfo(uri);
                    } else {
                        String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date());
                        File localParentFolder = StorageManager.getCacheDir(getActivity(),
                                "AlfrescoMobile/import");
                        File f = createFile(localParentFolder, timeStamp + ".txt", item.getText().toString());
                        if (f.exists()) {
                            retrieveIntentInfo(Uri.fromFile(f));
                        }
                    }
                }
            }

            if (file == null && Intent.ACTION_SEND.equals(action) && type != null) {
                Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
                retrieveIntentInfo(uri);
            } else if (action == null && intent.getData() != null) {
                retrieveIntentInfo(intent.getData());
            } else if (file == null || fileName == null) {
                MessengerManager.showLongToast(getActivity(), getString(R.string.import_unsupported_intent));
                getActivity().finish();
                return;
            }
            if (!files.contains(file)) {
                files.add(file);
            }
        }
    } catch (AlfrescoAppException e) {
        org.alfresco.mobile.android.application.manager.ActionManager.actionDisplayError(this, e);
        getActivity().finish();
        return;
    }

    if (adapter == null && files != null) {
        adapter = new FileExplorerAdapter(this, R.layout.app_list_progress_row, files);
        if (lv != null) {
            lv.setAdapter(adapter);
        } else if (spinnerDoc != null) {
            spinnerDoc.setAdapter(adapter);
        }
    }

    Button b = UIUtils.initCancel(rootView, R.string.cancel);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().finish();
        }
    });

    b = UIUtils.initValidation(rootView, R.string.next);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            next();
        }
    });

    refreshImportFolder();
}

From source file:com.italankin.dictionary.ui.main.MainActivity.java

private boolean handleIntent(Intent intent) {
    if (intent.getType() != null) {
        String type = intent.getType();
        String text = intent.getStringExtra(Intent.EXTRA_TEXT);
        text = text.substring(0, Math.min(text.length(), 80));
        if (type != null && !TextUtils.isEmpty(text) && "text/plain".equals(type)) {
            intent.setType(null);//from w  w w  .  j a  v  a2  s. co  m
            mInput.setText(text);
            mInput.selectAll();
            startLookup(text);
        }
        return true;
    }
    return false;
}

From source file:com.microntek.music.MusicActivity.java

/**
 * Checks whether the passed intent contains a playback request,
 * and starts playback if that's the case
 * @return true if the intent was consumed
 *///from  ww  w. j av a  2 s. c o  m
private boolean handlePlaybackIntent(Intent intent) {

    if (intent == null) {
        return false;
    } else if (!MusicUtils.isPlaybackServiceConnected()) {
        mHasPendingPlaybackRequest = true;
        return false;
    }

    String mimeType = intent.getType();
    boolean handled = false;

    if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "playlistId", "playlist", -1);
        if (id >= 0) {
            MusicUtils.playPlaylist(this, id, false);
            handled = true;
        }
    } else if (MediaStore.Audio.Albums.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "albumId", "album", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playAlbum(this, id, position, false);
            handled = true;
        }
    } else if (MediaStore.Audio.Artists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "artistId", "artist", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playArtist(this, id, position, false);
            handled = true;
        }
    } else {
        //added to start playing when we start the app and we have something in queue
        if (!MusicUtils.isPlaying() && MusicUtils.getQueueSize() > 0) {
            MusicUtils.playOrPause();
        }

        handled = true;
    }

    // reset intent as it was handled as a playback request
    if (handled) {
        setIntent(new Intent());
    }

    return handled;

}

From source file:com.cyanogenmod.eleven.ui.activities.HomeActivity.java

/**
 * Checks whether the passed intent contains a playback request,
 * and starts playback if that's the case
 * @return true if the intent was consumed
 *//*  w  w w. j  a  v  a2  s.c o m*/
private boolean handlePlaybackIntent(Intent intent) {

    if (intent == null) {
        return false;
    } else if (!MusicUtils.isPlaybackServiceConnected()) {
        mHasPendingPlaybackRequest = true;
        return false;
    }

    Uri uri = intent.getData();
    String mimeType = intent.getType();
    boolean handled = false;

    if (uri != null && uri.toString().length() > 0) {
        MusicUtils.playFile(this, uri);
        handled = true;
    } else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "playlistId", "playlist", -1);
        if (id >= 0) {
            MusicUtils.playPlaylist(this, id, false);
            handled = true;
        }
    } else if (MediaStore.Audio.Albums.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "albumId", "album", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playAlbum(this, id, position, false);
            handled = true;
        }
    } else if (MediaStore.Audio.Artists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "artistId", "artist", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playArtist(this, id, position, false);
            handled = true;
        }
    }

    // reset intent as it was handled as a playback request
    if (handled) {
        setIntent(new Intent());
    }

    return handled;

}

From source file:com.commonsware.android.foredown.Downloader.java

private void raiseNotification(Intent inbound, File output, Exception e) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);

    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis());

    if (e == null) {
        b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun))
                .setSmallIcon(android.R.drawable.stat_sys_download_done)
                .setTicker(getString(R.string.download_complete));

        Intent outbound = new Intent(Intent.ACTION_VIEW);

        outbound.setDataAndType(Uri.fromFile(output), inbound.getType());

        b.setContentIntent(PendingIntent.getActivity(this, 0, outbound, 0));
    } else {//  w w w  .j av a2 s.  c o m
        b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage())
                .setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
    }

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mgr.notify(NOTIFY_ID, b.build());
}

From source file:cz.yetanotherview.webcamviewer.app.MainActivity.java

private void initReceivedIntent() {
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            //handleReceivedUrl(intent);
        }/*from   w w  w  . j  av  a 2s .c om*/
    }
}

From source file:com.nnm.smsviet.Message.java

/**
 * Get a {@link OnLongClickListener} to save the attachment.
 * //from  w  ww  . ja  v  a 2s  .c  om
 * @param context
 *            {@link Context}
 * @return {@link OnLongClickListener}
 */
public OnLongClickListener getSaveAttachmentListener(final Context context) {
    if (this.contentIntent == null) {
        return null;
    }

    return new OnLongClickListener() {
        @Override
        public boolean onLongClick(final View v) {
            try {
                Log.d(TAG, "save attachment: " + Message.this.id);
                String fn = ATTACHMENT_FILE;
                final Intent ci = Message.this.contentIntent;
                final String ct = ci.getType();
                Log.d(TAG, "content type: " + ct);
                if (ct.startsWith("image/")) {
                    if (ct.equals("image/jpeg")) {
                        fn += "jpg";
                    } else if (ct.equals("image/gif")) {
                        fn += "gif";
                    } else {
                        fn += "png";
                    }
                } else if (ct.startsWith("audio/")) {
                    if (ct.equals("audio/3gpp")) {
                        fn += "3gpp";
                    } else if (ct.equals("audio/mpeg")) {
                        fn += "mp3";
                    } else if (ct.equals("audio/mid")) {
                        fn += "mid";
                    } else {
                        fn += "wav";
                    }
                } else if (ct.startsWith("video/")) {
                    if (ct.equals("video/3gpp")) {
                        fn += "3gpp";
                    } else {
                        fn += "avi";
                    }
                } else {
                    fn += "ukn";
                }
                final File file = Message.this.createUniqueFile(Environment.getExternalStorageDirectory(), fn);
                InputStream in = context.getContentResolver().openInputStream(ci.getData());
                OutputStream out = new FileOutputStream(file);
                IOUtils.copy(in, out);
                out.flush();
                out.close();
                in.close();
                Log.i(TAG, "attachment saved: " + file.getPath());
                Toast.makeText(context, context.getString(R.string.attachment_saved) + " " + fn,
                        Toast.LENGTH_LONG).show();
                return true;
            } catch (IOException e) {
                Log.e(TAG, "IO ERROR", e);
                Toast.makeText(context, R.string.attachment_not_saved, Toast.LENGTH_LONG).show();
            }
            return true;
        }
    };
}

From source file:org.y20k.transistor.MainActivityFragment.java

private void handleNewStationIntent() {

    // get intent
    Intent intent = mActivity.getIntent();

    // check for intent of tyoe VIEW
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        // set new station URL
        String newStationURL;//  ww  w  .  j av  a  2s  .  c om
        // mime type check
        if (intent.getType() != null && intent.getType().startsWith("audio/")) {
            newStationURL = intent.getDataString();
        }
        // no mime type
        else {
            newStationURL = intent.getDataString();
        }

        // clear the intent
        intent.setAction("");

        // check for null
        if (newStationURL != null) {
            // download and add new station
            StationDownloader stationDownloader = new StationDownloader(newStationURL, mActivity);
            stationDownloader.execute();

            // send local broadcast
            Intent i = new Intent();
            i.setAction(ACTION_COLLECTION_CHANGED);
            LocalBroadcastManager.getInstance(mActivity).sendBroadcast(i);

        }
        // unsuccessful - log failure
        else {
            Log.v(LOG_TAG, "Received an empty intent");
        }

    }
}