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:com.company.millenium.iwannask.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
        super.onActivityResult(requestCode, resultCode, data);
        return;//  ww w .  ja va  2 s. c  o m
    }

    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;
}

From source file:com.coact.kochzap.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // historyManager must be initialized here to update the history preference
    historyManager = new HistoryManager(this);
    historyManager.trimHistory();//from  w  w  w  .j a v a2 s. c  om

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    resultView = findViewById(R.id.result_view);
    statusView = (TextView) findViewById(R.id.status_view);

    handler = null;
    lastResult = null;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

    resetStatusView();

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    Intent intent = getIntent();

    copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
            && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

    source = IntentSource.NONE;
    sourceUrl = null;
    scanFromWebPageManager = null;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();
        String dataString = intent.getDataString();

        if (Intents.Scan.ACTION.equals(action)) {
            // Scan the formats the intent requested, and return the result to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
            decodeHints = DecodeHintManager.parseDecodeHints(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }

            if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
                int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
                if (cameraId >= 0) {
                    cameraManager.setManualCameraId(cameraId);
                }
            }

            String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
            if (customPromptMessage != null) {
                statusView.setText(customPromptMessage);
            }
        } else if (dataString != null && dataString.contains("http://www.google")
                && dataString.contains("/m/products/scan")) {

            // Scan only products and send the result to mobile Product Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;
        } else if (isZXingURL(dataString)) {

            // Scan formats requested in query string (all formats if none specified).
            // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(dataString);
            scanFromWebPageManager = new ScanFromWebPageManager(inputUri);
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);
            // Allow a sub-set of the hints to be specified by the caller.
            decodeHints = DecodeHintManager.parseDecodeHints(inputUri);

        }
        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);
    }

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }
}

From source file:net.eledge.android.europeana.gui.activity.SearchActivity.java

private void handleIntent(Intent intent) {
    String query = null;//from  w  w  w. ja  v a 2 s .  c om
    String[] qf = null;
    if (intent != null) {

        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            query = intent.getStringExtra(SearchManager.QUERY);
            qf = splitFacets(intent.getStringExtra(SearchManager.USER_QUERY));
        } else if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
            Parcelable[] parcelables = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
            NdefMessage msg = (NdefMessage) parcelables[0];
            Uri uri = Uri.parse(new String(msg.getRecords()[0].getPayload()));
            query = uri.getQueryParameter("query");
            qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
        } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            query = intent.getDataString();
            if (!TextUtils.isEmpty(query)) {
                if (StringUtils.contains(query, "europeana.eu/")) {
                    Uri uri = Uri.parse(query);
                    query = uri.getQueryParameter("query");
                    qf = StringArrayUtils.toArray(uri.getQueryParameters("qf"));
                }
            }
        } else {
            // no search action recognized? end this activity...
            closeSearchActivity();
        }
        if (!TextUtils.isEmpty(query) && !TextUtils.equals(runningSearch, query)) {
            runningSearch = query;
            if (StringArrayUtils.isNotBlank(qf)) {
                searchController.newSearch(this, query, qf);
            } else {
                searchController.newSearch(this, query);
            }
            getSupportActionBar().setTitle(searchController.getSearchTitle(this));
        }
    }
}

From source file:com.frostwire.android.gui.activities.MainActivity.java

private void openTorrentUrl(Intent intent) {
    try {//w ww .j  a  v a 2s.co  m
        //Open a Torrent from a URL or from a local file :), say from Astro File Manager.
        //Show me the transfer tab
        Intent i = new Intent(this, MainActivity.class);
        i.setAction(Constants.ACTION_SHOW_TRANSFERS);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(i);
        //go!
        final String uri = intent.getDataString();
        intent.setAction(null);
        if (uri != null) {
            if (uri.startsWith("file") || uri.startsWith("http") || uri.startsWith("https")
                    || uri.startsWith("magnet")) {
                TransferManager.instance().downloadTorrent(uri,
                        new HandpickedTorrentDownloadDialogOnFetch(this));
            } else if (uri.startsWith("content")) {
                String newUri = saveViewContent(this, Uri.parse(uri), "content-intent.torrent");
                if (newUri != null) {
                    TransferManager.instance().downloadTorrent(newUri,
                            new HandpickedTorrentDownloadDialogOnFetch(this));
                }
            }
        } else {
            LOG.warn(
                    "MainActivity.onNewIntent(): Couldn't start torrent download from Intent's URI, intent.getDataString() -> null");
            LOG.warn("(maybe URI is coming in another property of the intent object - #fragmentation)");
        }
    } catch (Throwable e) {
        LOG.error("Error opening torrent from intent", e);
    }
}

From source file:com.keepassdroid.PasswordActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {

    case KeePass.EXIT_NORMAL:
        setEditText(R.id.password, "");
        App.getDB().clear();/* www. j a  v  a  2 s . c  o  m*/
        break;

    case KeePass.EXIT_LOCK:
        setResult(KeePass.EXIT_LOCK);
        setEditText(R.id.password, "");
        finish();
        App.getDB().clear();
        break;
    case FILE_BROWSE:
        if (resultCode == RESULT_OK) {
            String filename = data.getDataString();
            if (filename != null) {
                EditText fn = (EditText) findViewById(R.id.pass_keyfile);
                fn.setText(filename);
                mKeyUri = UriUtil.parseDefaultFile(filename);
            }
        }
        break;
    case GET_CONTENT:
    case OPEN_DOC:
        if (resultCode == RESULT_OK) {
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    if (requestCode == GET_CONTENT) {
                        uri = UriUtil.translate(this, uri);
                    }
                    String path = uri.toString();
                    if (path != null) {
                        EditText fn = (EditText) findViewById(R.id.pass_keyfile);
                        fn.setText(path);

                    }
                    mKeyUri = uri;
                }
            }
        }
        break;
    }
}

From source file:com.cleverzone.zhizhi.capture.CaptureActivity.java

@Override
protected void onResume() {
    super.onResume();

    // historyManager must be initialized here to update the history preference
    //        historyManager = new HistoryManager(this);
    //        historyManager.trimHistory();

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    resultView = findViewById(R.id.result_view);
    statusView = (TextView) findViewById(R.id.status_view);

    handler = null;//from  w ww.  j a  va 2  s  .  c  om
    lastResult = null;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    //        if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
    //            setRequestedOrientation(getCurrentOrientation());
    //        } else {
    //            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    //        }
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

    resetStatusView();

    beepManager.updatePrefs();
    //        ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    Intent intent = getIntent();

    //        copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true)
    //                && (intent == null || intent.getBooleanExtra(Intents.Scan.SAVE_HISTORY, true));

    source = IntentSource.NONE;
    sourceUrl = null;
    //        scanFromWebPageManager = null;
    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();
        String dataString = intent.getDataString();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result to the calling activity.
            source = IntentSource.NATIVE_APP_INTENT;
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
            decodeHints = DecodeHintManager.parseDecodeHints(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }

            if (intent.hasExtra(Intents.Scan.CAMERA_ID)) {
                int cameraId = intent.getIntExtra(Intents.Scan.CAMERA_ID, -1);
                if (cameraId >= 0) {
                    cameraManager.setManualCameraId(cameraId);
                }
            }

            String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
            if (customPromptMessage != null) {
                statusView.setText(customPromptMessage);
            }

        } else if (dataString != null && dataString.contains("http://www.google")
                && dataString.contains("/m/products/scan")) {

            // Scan only products and send the result to mobile Product Search.
            source = IntentSource.PRODUCT_SEARCH_LINK;
            sourceUrl = dataString;
            decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;

        } else if (isZXingURL(dataString)) {

            // Scan formats requested in query string (all formats if none specified).
            // If a return URL is specified, send the results there. Otherwise, handle it ourselves.
            source = IntentSource.ZXING_LINK;
            sourceUrl = dataString;
            Uri inputUri = Uri.parse(dataString);
            //                scanFromWebPageManager = new ScanFromWebPageManager(inputUri);
            decodeFormats = DecodeFormatManager.parseDecodeFormats(inputUri);
            // Allow a sub-set of the hints to be specified by the caller.
            decodeHints = DecodeHintManager.parseDecodeHints(inputUri);

        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }
}

From source file:com.nttec.everychan.ui.MainActivity.java

private void handleUriIntent(Intent intent) {
    TabsTrackerService.clearUnread();//from  w w w  .ja  va2 s. c  o m
    if (intent != null) {
        if (intent.getBooleanExtra(TabsTrackerService.EXTRA_CLEAR_SUBSCRIPTIONS, false))
            TabsTrackerService.clearSubscriptions();
        if (MainApplication.getInstance().settings.useFakeBrowser())
            FakeBrowser.dismiss();
        if (intent.getData() != null && URLUtil.isFileUrl(intent.getDataString())) {
            LocalHandler.open(intent.getData().getPath(), this);
            return;
        }
        String url = intent.getDataString();
        if (url != null && url.length() != 0) {
            UrlHandler.open(url, this, MainApplication.getInstance().settings.useFakeBrowser());
        }
        intent.setData(null);
    }
}

From source file:io.plaidapp.ui.DribbbleShot.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dribbble_shot);
    dribbblePrefs = DribbblePrefs.get(this);
    circleTransform = new CircleTransform(this);
    ButterKnife.bind(this);
    shotDescription = getLayoutInflater().inflate(R.layout.dribbble_shot_description, commentsList, false);
    shotSpacer = shotDescription.findViewById(R.id.shot_spacer);
    title = shotDescription.findViewById(R.id.shot_title);
    description = shotDescription.findViewById(R.id.shot_description);
    likeCount = (Button) shotDescription.findViewById(R.id.shot_like_count);
    viewCount = (Button) shotDescription.findViewById(R.id.shot_view_count);
    share = (Button) shotDescription.findViewById(R.id.shot_share_action);
    playerName = (TextView) shotDescription.findViewById(R.id.player_name);
    playerAvatar = (ImageView) shotDescription.findViewById(R.id.player_avatar);
    shotTimeAgo = (TextView) shotDescription.findViewById(R.id.shot_time_ago);

    setupCommenting();/*from   ww  w .  j ava 2s . c om*/
    commentsList.addOnScrollListener(scrollListener);
    commentsList.setOnFlingListener(flingListener);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResultAndFinish();
        }
    });
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this) {
        @Override
        public void onDragDismissed() {
            setResultAndFinish();
        }
    };

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_SHOT)) {
        shot = intent.getParcelableExtra(EXTRA_SHOT);
        bindShot(true);
    } else if (intent.getData() != null) {
        final HttpUrl url = HttpUrl.parse(intent.getDataString());
        if (url.pathSize() == 2 && url.pathSegments().get(0).equals("shots")) {
            try {
                final String shotPath = url.pathSegments().get(1);
                final long id = Long.parseLong(shotPath.substring(0, shotPath.indexOf("-")));

                final Call<Shot> shotCall = dribbblePrefs.getApi().getShot(id);
                shotCall.enqueue(new Callback<Shot>() {
                    @Override
                    public void onResponse(Call<Shot> call, Response<Shot> response) {
                        shot = response.body();
                        bindShot(false);
                    }

                    @Override
                    public void onFailure(Call<Shot> call, Throwable t) {
                        reportUrlError();
                    }
                });
            } catch (NumberFormatException | StringIndexOutOfBoundsException ex) {
                reportUrlError();
            }
        } else {
            reportUrlError();
        }
    }
}

From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
        super.onActivityResult(requestCode, resultCode, data);
        return;/*w  w  w . j  av  a 2  s  .c om*/
    }
    Uri[] results = null;
    if (resultCode == Activity.RESULT_OK) {
        if (data == null) {
            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;
}

From source file:com.waz.zclient.pages.main.conversation.AssetIntentsManager.java

public boolean onActivityResult(int requestCode, int resultCode, Intent data) {

    if (callback == null) {
        throw new IllegalStateException("A callback must be set!");
    }/*from ww w .ja v  a 2 s  .  c o m*/

    IntentType type = IntentType.get(requestCode);

    if (type == IntentType.UNKOWN) {
        return false;
    }

    if (resultCode == Activity.RESULT_CANCELED) {
        callback.onCanceled(type);
        return true;
    }

    if (resultCode != Activity.RESULT_OK) {
        callback.onFailed(type);
        return true;
    }

    File possibleFile = null;
    if (pendingFileUri != null) {
        possibleFile = new File(pendingFileUri.getPath());
    }
    if ((type == IntentType.CAMERA || type == IntentType.VIDEO || type == IntentType.VIDEO_CURSOR_BUTTON)
            && possibleFile != null && possibleFile.exists() && possibleFile.length() > 0) {
        callback.onDataReceived(type, pendingFileUri);
        pendingFileUri = null;
    } else if (data != null) {
        Uri uri;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            uri = Uri.parse(data.getDataString());
        } else {
            uri = data.getData();
        }
        if (uri == null) {
            callback.onFailed(type);
        } else {
            callback.onDataReceived(type, uri);
        }
    } else {
        callback.onFailed(type);
    }

    return true;
}