Example usage for android.content Intent getDataString

List of usage examples for android.content Intent getDataString

Introduction

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

Prototype

public @Nullable String getDataString() 

Source Link

Document

The same as #getData() , but returns the URI as an encoded String.

Usage

From source file:de.vanita5.twittnuker.fragment.support.DirectMessagesConversationFragment.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    switch (requestCode) {
    case REQUEST_SELECT_USER: {
        if (resultCode != Activity.RESULT_OK || !data.hasExtra(EXTRA_USER)) {
            break;
        }//from  www  .  j  a v  a 2s  .c om
        final ParcelableUser user = data.getParcelableExtra(EXTRA_USER);
        if (user != null && mAccountId > 0) {
            mRecipientId = user.id;
            showConversation(mAccountId, mRecipientId);
        }
        break;
    }
    case REQUEST_PICK_IMAGE: {
        if (resultCode != Activity.RESULT_OK || data.getDataString() == null) {
            break;
        }
        mImageUri = data.getDataString();
        updateAddImageButton();
        break;
    }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:id.nci.stm_9.ImportKeysActivity.java

protected void handleActions(Bundle savedInstanceState, Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();/*from ww w.  j a  va2 s.  c o m*/

    if (extras == null) {
        extras = new Bundle();
    }

    /**
     * Android Standard Actions
     */
    if (Intent.ACTION_VIEW.equals(action)) {
        // Android's Action when opening file associated to Keychain (see AndroidManifest.xml)
        // override action to delegate it to Keychain's ACTION_IMPORT_KEY
        action = ACTION_IMPORT_KEY;
    }

    /**
     * Keychain's own Actions
     */
    if (ACTION_IMPORT_KEY.equals(action)) {
        if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
            String importFilename = intent.getData().getPath();

            // display selected filename
            getSupportActionBar().setSelectedNavigationItem(0);
            Bundle args = new Bundle();
            args.putString(ImportKeysFileFragment.ARG_PATH, importFilename);
            loadFragment(ImportKeysFileFragment.class, args, mNavigationStrings[0]);

            // directly load data
            startListFragment(savedInstanceState, null, importFilename);
        } else if (extras.containsKey(EXTRA_KEY_BYTES)) {
            byte[] importData = intent.getByteArrayExtra(EXTRA_KEY_BYTES);

            // directly load data
            startListFragment(savedInstanceState, importData, null);
        }
    } else {
        // Internal actions
        startListFragment(savedInstanceState, null, null);

        if (ACTION_IMPORT_KEY_FROM_FILE.equals(action)) {
            getSupportActionBar().setSelectedNavigationItem(0);
            loadFragment(ImportKeysFileFragment.class, null, mNavigationStrings[0]);
        }
        //            } else if (ACTION_IMPORT_KEY_FROM_QR_CODE.equals(action)) {
        //                getSupportActionBar().setSelectedNavigationItem(2);
        //                loadFragment(ImportKeysQrCodeFragment.class, null, mNavigationStrings[2]);
        //            } else if (ACTION_IMPORT_KEY_FROM_NFC.equals(action)) {
        //                getSupportActionBar().setSelectedNavigationItem(3);
        //                loadFragment(ImportKeysNFCFragment.class, null, mNavigationStrings[3]);
        //            }
    }
}

From source file:com.yeldi.yeldibazaar.AppDetails.java

public void tryOpenUri(String s) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
    if (intent.resolveActivity(getPackageManager()) != null)
        startActivity(intent);//from w  w  w  . j a  v  a  2s.c o  m
    else
        Toast.makeText(this, getString(R.string.no_handler_app, intent.getDataString()), Toast.LENGTH_LONG)
                .show();
}

From source file:com.github.michalbednarski.intentslab.providerlab.AdvancedQueryActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.advanced_query);

    Intent intent = getIntent();
    Bundle instanceStateOrExtras = savedInstanceState != null ? savedInstanceState : intent.getExtras();
    if (instanceStateOrExtras == null) {
        instanceStateOrExtras = Bundle.EMPTY;
    }/*from   ww  w .java  2 s  . co m*/

    // Uri
    mUriTextView = (AutoCompleteTextView) findViewById(R.id.uri);
    if (intent.getData() != null) {
        mUriTextView.setText(intent.getDataString());
    }
    mUriTextView.setAdapter(new UriAutocompleteAdapter(this));

    // Projection
    {
        mSpecifyProjectionCheckBox = (CheckBox) findViewById(R.id.specify_projection);
        mProjectionLayout = (LinearLayout) findViewById(R.id.projection_columns);

        // Bind events for master CheckBox and add new button
        findViewById(R.id.new_projection_column).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new UserProjectionColumn("");
            }
        });
        mSpecifyProjectionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mProjectionLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });

        // Get values to fill
        String[] availableProjectionColumns = intent.getStringArrayExtra(EXTRA_PROJECTION_AVAILABLE_COLUMNS);
        String[] specifiedProjectionColumns = instanceStateOrExtras.getStringArray(EXTRA_PROJECTION);

        if (specifiedProjectionColumns == null) {
            mSpecifyProjectionCheckBox.setChecked(false);
        }

        if (availableProjectionColumns != null && availableProjectionColumns.length == 0) {
            availableProjectionColumns = null;
        }
        if (availableProjectionColumns != null && specifiedProjectionColumns == null) {
            specifiedProjectionColumns = availableProjectionColumns;
        }

        // Create available column checkboxes
        int i = 0;
        if (availableProjectionColumns != null) {
            for (String availableProjectionColumn : availableProjectionColumns) {
                boolean isChecked = i < specifiedProjectionColumns.length
                        && availableProjectionColumn.equals(specifiedProjectionColumns[i]);
                new DefaultProjectionColumn(availableProjectionColumn, isChecked);
                if (isChecked) {
                    i++;
                }
            }
        }

        // Create user column text fields
        if (specifiedProjectionColumns != null && i < specifiedProjectionColumns.length) {
            for (int il = specifiedProjectionColumns.length; i < il; i++) {
                new UserProjectionColumn(specifiedProjectionColumns[i]);
            }
        }

    }

    // Selection
    {
        // Find views
        mSelectionCheckBox = (CheckBox) findViewById(R.id.selection_header);
        mSelectionText = (TextView) findViewById(R.id.selection);
        mSelectionLayout = findViewById(R.id.selection_layout);
        mSelectionArgsTable = (TableLayout) findViewById(R.id.selection_args);

        // Bind events for add button and master CheckBox
        findViewById(R.id.selection_add_arg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new SelectionArg("", true);
            }
        });
        mSelectionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mSelectionLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });

        // Fill selection text view and CheckBox
        String selection = intent.getStringExtra(EXTRA_SELECTION);
        String[] selectionArgs = instanceStateOrExtras.getStringArray(EXTRA_SELECTION_ARGS);

        mSelectionCheckBox.setChecked(selection != null);
        if (selection != null) {
            mSelectionText.setText(selection);
        }

        // Fill selection arguments
        if ((selection != null || savedInstanceState != null) && selectionArgs != null
                && selectionArgs.length != 0) {
            for (String selectionArg : selectionArgs) {
                new SelectionArg(selectionArg);
            }
        }
    }

    // Content values
    {
        // Find views
        mContentValuesHeader = (TextView) findViewById(R.id.content_values_header);
        mContentValuesTable = (TableLayout) findViewById(R.id.content_values);
        mContentValuesTableHeader = (TableRow) findViewById(R.id.content_values_table_header);

        // Bind add new button event
        findViewById(R.id.new_content_value).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new ContentValue("", "", true);
            }
        });

        // Create table
        ContentValues contentValues = instanceStateOrExtras.getParcelable(EXTRA_CONTENT_VALUES);
        if (contentValues != null) {
            contentValues.valueSet();
            for (String key : Utils.getKeySet(contentValues)) {
                new ContentValue(key, contentValues.getAsString(key));
            }
        }
    }

    // Order
    {
        // Find views
        mSpecifyOrderCheckBox = (CheckBox) findViewById(R.id.specify_order);
        mOrderTextView = (TextView) findViewById(R.id.order);

        // Bind events
        mSpecifyOrderCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mOrderTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });

        // Fill fields
        String order = intent.getStringExtra(EXTRA_SORT_ORDER);
        if (order == null) {
            mSpecifyOrderCheckBox.setChecked(false);
        } else {
            mOrderTextView.setText(order);
        }
    }

    // Method (affects previous views so they must be initialized first)
    mMethodSpinner = (Spinner) findViewById(R.id.method);
    mMethodSpinner
            .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, METHOD_NAMES));
    mMethodSpinner.setOnItemSelectedListener(onMethodSpinnerItemSelectedListener);
    mMethodSpinner.setSelection(intent.getIntExtra(EXTRA_METHOD, METHOD_QUERY));
}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysActivity.java

protected void handleActions(Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();/*from   ww w  .  ja v a2 s. c  o m*/

    if (extras == null) {
        extras = new Bundle();
    }

    /**
     * Android Standard Actions
     */
    if (Intent.ACTION_VIEW.equals(action)) {
        // Android's Action when opening file associated to APG (see AndroidManifest.xml)
        // override action to delegate it to APGs ACTION_IMPORT
        action = ACTION_IMPORT;
    }

    /**
     * APG's own Actions
     */
    if (ACTION_IMPORT.equals(action)) {
        if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
            mImportFilename = intent.getData().getPath();
            mImportData = null;
        } else if (extras.containsKey(EXTRA_TEXT)) {
            mImportData = intent.getStringExtra(EXTRA_TEXT).getBytes();
            mImportFilename = null;
        } else if (extras.containsKey(EXTRA_KEYRING_BYTES)) {
            mImportData = intent.getByteArrayExtra(EXTRA_KEYRING_BYTES);
            mImportFilename = null;
        }
        loadKeyListFragment();
    } else if (ACTION_IMPORT_FROM_FILE.equals(action)) {
        if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
            mImportFilename = intent.getData().getPath();
            mImportData = null;
        }
        showImportFromFileDialog();
    } else if (ACTION_IMPORT_FROM_QR_CODE.equals(action)) {
        importFromQrCode();
    } else if (ACTION_IMPORT_FROM_NFC.equals(action)) {
        importFromNfc();
    }
}

From source file:de.earthlingz.oerszebra.DroidZebra.java

@Override
protected void onNewIntent(Intent intent) {

    String action = intent.getAction();
    String type = intent.getType();

    Log.i("Intent", type + " " + action);

    if (Intent.ACTION_SEND.equals(action) && type != null) {
        switch (type) {
        case "text/plain":
            setUpBoard(intent.getDataString()); // Handle text being sent

            break;
        case "message/rfc822":
            Log.i("Intent", intent.getStringExtra(Intent.EXTRA_TEXT));
            setUpBoard(intent.getStringExtra(Intent.EXTRA_TEXT)); // Handle text being sent

            break;
        default://w w  w  .j a va2 s .c o  m
            Log.e("intent", "unknown intent");
            break;
        }
    } else {
        Log.e("intent", "unknown intent");
    }
}

From source file:it.rignanese.leo.slimfacebook.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    //used to upload files
    //thanks to gauntface
    //https://github.com/GoogleChrome/chromium-webview-samples
    if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
        super.onActivityResult(requestCode, resultCode, data);
        return;//from  w  w  w .ja  va 2  s  . com
    }

    Uri[] results = null;

    // Check that the response is a good one
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            // If there is not data, then we may have taken a photo
            if (mCameraPhotoPath != null) {
                results = new Uri[] { Uri.parse(mCameraPhotoPath) };
            }
        } else {
            String dataString = data.getDataString();
            if (dataString != null) {
                results = new Uri[] { Uri.parse(dataString) };
            }
        }
    }

    mFilePathCallback.onReceiveValue(results);
    mFilePathCallback = null;
    return;
}

From source file:com.android.providers.downloads.DownloadThread.java

/**
 * Transfer the downloaded destination file to the DRM store.
 *///from   ww w . j a va2 s. co  m
private void transferToDrm(State state) throws StopRequest {
    File file = new File(state.mFilename);
    Intent item = DrmStore.addDrmFile(mContext.getContentResolver(), file, null);
    file.delete();

    if (item == null) {
        throw new StopRequest(Downloads.Impl.STATUS_UNKNOWN_ERROR, "unable to add file to DrmProvider");
    } else {
        state.mFilename = item.getDataString();
        state.mMimeType = item.getType();
    }
}

From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_details);

    setToolbar((Toolbar) findViewById(R.id.toolbar));

    if (getToolbar() != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.TRANSPARENT);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }/*from   w  w w  .j  a  v a 2s.  c  om*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getToolbar().setPadding(0, getStatusBarHeight(), 0, 0);
        }
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    final Intent intent = getIntent();
    String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        pageUri = Uri.parse(intent.getDataString());
        if ("wally".equalsIgnoreCase(pageUri.getScheme())) {
            pageUri = pageUri.buildUpon().scheme("http").build();
        }
    }

    setupViews();
    setupHandlers();

    Size size = new Size(16, 9);

    if (intent.hasExtra(INTENT_EXTRA_IMAGE)) {
        final Image image = intent.getParcelableExtra(INTENT_EXTRA_IMAGE);
        final Bitmap thumbBitmap = WallyApplication.getBitmapThumb();

        if (thumbBitmap != null) {

            size = fitToWidthAndKeepRatio(image.getWidth(), image.getHeight());

            photoView.getLayoutParams().width = size.getWidth();
            photoView.getLayoutParams().height = size.getHeight();

            Bitmap blurBitMap;
            try {
                blurBitMap = Blur.apply(imageHolder.getContext(), thumbBitmap);
            } catch (ArrayIndexOutOfBoundsException e) {
                //Blur couldn't be applied. Show regular thumbnail instead.
                blurBitMap = thumbBitmap;
            }
            photoView.setImageBitmap(blurBitMap);
        }
    }
    setupPaddings(size, false);

    if (savedInstanceState == null) {
        getPage(pageUri.toString());
    } else if (savedInstanceState.containsKey(STATE_IMAGE_PAGE)) {
        imagePage = savedInstanceState.getParcelable(STATE_IMAGE_PAGE);
    }

    if (imagePage != null) {
        Message msgObj = uiHandler.obtainMessage();
        msgObj.what = MSG_PAGE_FETCHED;
        msgObj.obj = imagePage;
        uiHandler.sendMessage(msgObj);
    } else {
        getPage(pageUri.toString());
    }

}

From source file:com.owncloud.android.files.InstantUploadBroadcastReceiver.java

private void handleNewVideoAction(Context context, Intent intent) {
    Cursor c = null;//  w w  w  .j  a  v a2 s .  c o  m
    String file_path = null;
    String file_name = null;
    String mime_type = null;
    long date_taken = 0;

    Log_OC.i(TAG, "New video received");

    if (!PreferenceManager.instantVideoUploadEnabled(context)) {
        Log_OC.d(TAG, "Instant video upload disabled, ignoring new video");
        return;
    }

    Account account = AccountUtils.getCurrentOwnCloudAccount(context);
    if (account == null) {
        Log_OC.w(TAG, "No account found for instant upload, aborting");
        return;
    }

    String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE,
            Video.Media.SIZE };
    c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
    if (!c.moveToFirst()) {
        Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
        return;
    }
    file_path = c.getString(c.getColumnIndex(Video.Media.DATA));
    file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
    mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
    c.close();
    date_taken = System.currentTimeMillis();
    Log_OC.d(TAG, file_path + "");

    int behaviour = getUploadBehaviour(context);
    FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
    requester.uploadNewFile(context, account, file_path,
            FileStorageUtils.getInstantVideoUploadFilePath(context, file_name, date_taken), behaviour,
            mime_type, true, // create parent folder if not existent
            UploadFileOperation.CREATED_AS_INSTANT_VIDEO);
}