Example usage for android.net Uri getQueryParameter

List of usage examples for android.net Uri getQueryParameter

Introduction

In this page you can find the example usage for android.net Uri getQueryParameter.

Prototype

@Nullable
public String getQueryParameter(String key) 

Source Link

Document

Searches the query string for the first value with the given key.

Usage

From source file:com.phonegap.plugins.videoplayer.VideoPlayer.java

private void playVideo(String url) throws IOException {

    if (url.contains("bit.ly/") || url.contains("goo.gl/") || url.contains("tinyurl.com/")
            || url.contains("youtu.be/")) {
        //support for google / bitly / tinyurl / youtube shortens
        URLConnection con = new URL(url).openConnection();
        con.connect();/*from   w ww.  j a va2s.c o  m*/
        InputStream is = con.getInputStream();
        //new redirected url
        url = con.getURL().toString();
        is.close();
    }

    // Create URI
    Uri uri = Uri.parse(url);

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
        // If we don't do it this way you don't have the option for youtube
        uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
        if (isYouTubeInstalled()) {
            intent = new Intent(Intent.ACTION_VIEW, uri);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=com.google.android.youtube"));
        }
    } else if (url.contains(ASSETS)) {
        // get file path in assets folder
        String filepath = url.replace(ASSETS, "");
        // get actual filename from path as command to write to internal storage doesn't like folders
        String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

        // Don't copy the file if it already exists
        File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);
        if (!fp.exists()) {
            this.copy(filepath, filename);
        }

        // change uri to be to the new file in internal storage
        uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);

        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else {
        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
}

From source file:org.runnerup.export.FacebookSynchronizer.java

@Override
public Status getAuthResult(int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        try {
            String authConfig = data.getStringExtra(DB.ACCOUNT.AUTH_CONFIG);
            Uri uri = Uri.parse("http://keso?" + authConfig);
            access_token = uri.getQueryParameter("access_token");
            expire_time = Long.valueOf(uri.getQueryParameter("expires"));
            token_now = System.currentTimeMillis();
            return Status.OK;
        } catch (Exception ex) {
            ex.printStackTrace();/*from   w ww .j a v  a  2s .  c o  m*/
        }
    }
    return Status.ERROR;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false))
        setTheme(R.style.AppThemeLight);

    super.onCreate(savedInstanceState);
    manager = new AppListManager(this);
    setContentView(R.layout.fdroid);/*from  w  w  w  .  ja  v  a  2  s.  c o m*/
    createViews();
    // getTabManager().createTabs();

    // Start a search by just typing
    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);

    Intent i = getIntent();
    Uri data = getIntent().getData();
    if (data != null) {
        String appid = data.getQueryParameter("fdid");
        // If appid == null, we just browse all the apps.
        // If appid != null, we browse the app specified.
        if (appid != null) {
            Intent call = new Intent(this, AppDetails.class);
            call.putExtra("appid", appid);
            startActivityForResult(call, REQUEST_APPDETAILS);
        }
    } else if (i.hasExtra("uri")) {
        Intent call = new Intent(this, ManageRepo.class);
        call.putExtra("uri", i.getStringExtra("uri"));
        startActivityForResult(call, REQUEST_MANAGEREPOS);
    } else if (i.hasExtra(EXTRA_TAB_UPDATE)) {
        boolean showUpdateTab = i.getBooleanExtra(EXTRA_TAB_UPDATE, false);
        if (showUpdateTab) {
            getTabManager().selectTab(2);
        }
    }
}

From source file:com.afreire.plugins.video.VideoPlayer.java

private void playVideo(String url) throws IOException {
    if (url.contains("bit.ly/") || url.contains("goo.gl/") || url.contains("tinyurl.com/")
            || url.contains("youtu.be/")) {
        //support for google / bitly / tinyurl / youtube shortens
        URLConnection con = new URL(url).openConnection();
        con.connect();//from w  w w . ja  va 2s  . com
        InputStream is = con.getInputStream();
        //new redirected url
        url = con.getURL().toString();
        is.close();
    }

    // Create URI
    Uri uri = Uri.parse(url);

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
        // If we don't do it this way you don't have the option for youtube
        uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
        if (isYouTubeInstalled()) {
            intent = new Intent(Intent.ACTION_VIEW, uri);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=com.google.android.youtube"));
        }
    } else if (url.contains(ASSETS)) {
        // get file path in assets folder
        String filepath = url.replace(ASSETS, "");
        //Remove the path to the file from any location
        if (filepath.contains("www/file:")) {
            filepath = filepath.replace("www/file://", "");
        }
        // get actual filename from path as command to write to internal storage doesn't like folders
        String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

        // Don't copy the file if it already exists
        //File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);

        //It uses a fixed name to optimize memory space
        File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + VIDEO_FILE_NAME);
        //Always copy the file
        //if (!fp.exists()) {
        this.copy(filepath, filename);
        //}

        // change uri to be to the new file in internal storage
        uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);

        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else {
        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
}

From source file:com.deliciousdroid.activity.FragmentBaseActivity.java

@Override
@TargetApi(14)/*  w w  w  . ja va 2  s.c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mContext = this;
    mAccountManager = AccountManager.get(this);
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    loadSettings();
    init();

    if (android.os.Build.VERSION.SDK_INT >= 14) {
        getActionBar().setHomeButtonEnabled(true);
    }

    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction()) && !intent.hasExtra("MainSearchResults")) {
        if (intent.hasExtra(SearchManager.QUERY)) {
            Intent i = new Intent(this, MainSearchResults.class);
            i.putExtras(intent.getExtras());
            startActivity(i);
            finish();
        } else {
            onSearchRequested();
        }
    } else if (Constants.ACTION_SEARCH_SUGGESTION.equals(intent.getAction())) {
        Uri data = intent.getData();
        String path = null;
        String tagname = null;

        if (data != null) {
            path = data.getPath();
            tagname = data.getQueryParameter("tagname");
        }

        if (data.getScheme() == null || !data.getScheme().equals("content")) {
            Intent i = new Intent(Intent.ACTION_VIEW, data);
            startActivity(i);
            finish();
        } else if (path.contains("bookmarks") && TextUtils.isDigitsOnly(data.getLastPathSegment())
                && intent.hasExtra(SearchManager.USER_QUERY)) {
            Intent viewBookmark = new Intent(this, ViewBookmark.class);
            viewBookmark.setAction(Intent.ACTION_VIEW);
            viewBookmark.setData(data);
            viewBookmark.removeExtra(SearchManager.USER_QUERY);
            Log.d("View Bookmark Uri", data.toString());
            startActivity(viewBookmark);
            finish();
        } else if (tagname != null) {
            Intent viewTags = new Intent(this, BrowseBookmarks.class);
            viewTags.setData(data);

            Log.d("View Tags Uri", data.toString());
            startActivity(viewTags);
            finish();
        }
    }
}

From source file:com.moust.cordova.videoplayer.VideoPlayer.java

private void playVideo(String url) throws IOException {
    if (url.contains("bit.ly/") || url.contains("goo.gl/") || url.contains("tinyurl.com/")
            || url.contains("youtu.be/")) {
        //support for google / bitly / tinyurl / youtube shortens
        URLConnection con = new URL(url).openConnection();
        con.connect();/*ww w  . j  a va2s .  co  m*/
        InputStream is = con.getInputStream();
        //new redirected url
        url = con.getURL().toString();
        is.close();
    }

    // Create URI
    Uri uri = Uri.parse(url);

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
        // If we don't do it this way you don't have the option for youtube
        uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
        if (isYouTubeInstalled()) {
            intent = new Intent(Intent.ACTION_VIEW, uri);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=com.google.android.youtube"));
        }
    } else if (url.contains(ASSETS)) {
        // get file path in assets folder
        String filepath = url.replace(ASSETS, "");
        //Remove the path to the file from any location
        if (filepath.contains("www/file:")) {
            filepath = filepath.replace("www/file://", "");
        }
        // get actual filename from path as command to write to internal storage doesn't like folders
        String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

        // Don't copy the file if it already exists
        //File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);

        //It uses a fixed name to optimize memory space
        File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + VIDEO_FILE_NAME);

        //Always copy the file
        //if (!fp.exists()) {
        this.copy(filepath, filename);
        //}

        // change uri to be to the new file in internal storage
        uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);

        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else {
        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
}

From source file:com.tapchatapp.android.app.activity.BuffersActivity.java

@Subscribe
public void onServiceStateChanged(ServiceStateChangedEvent event) {
    final TapchatService service = event.getService();
    if (service.getConnectionState() != TapchatService.STATE_LOADED) {
        return;/*from   w  ww  .  java 2 s .  c  o m*/
    }

    if (mCurrentPage != null) {
        mBus.post(new BufferSelectedEvent(mCurrentPage.getConnectionId(), mCurrentPage.getBufferId(), true));
    }

    Uri data = getIntent().getData();
    final long connectionId = Long.parseLong(data.getHost());
    final long bufferId = Long.parseLong(data.getPath().substring(1));
    final BuffersToDisplay display = BuffersToDisplay.parseString(data.getQueryParameter("display"));

    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

    mTabsAdapter = (BuffersPagerAdapter) viewPager.getAdapter();
    if (mTabsAdapter == null) {
        mTabsAdapter = new BuffersPagerAdapter(BuffersActivity.this, connectionId, display);
        mTabsAdapter.registerBus();
        viewPager.setAdapter(mTabsAdapter);

        final TitlePageIndicator tabs = (TitlePageIndicator) findViewById(R.id.pager_tabs);
        tabs.setViewPager(viewPager);
        tabs.setOnPageChangeListener(mPageChangeListener);

        if (display == BuffersToDisplay.ConsoleOnly) {
            tabs.setVisibility(View.GONE);
        }

        int selectedItem = mTabsAdapter.getBufferIndex(bufferId);
        if (selectedItem < 0) {
            // FIXME: What to do here? finish() ?
            return;
        }

        viewPager.setCurrentItem(selectedItem);

        // onPageSelected doesn't fire if selectedItem is already
        // selected, causing title to not display.
        mPageChangeListener.onPageSelected(selectedItem);
    }
}

From source file:co.edu.uniajc.vtf.ar.ARViewActivity.java

public boolean listenURL(String uriString) {
    Uri invokedUri = Uri.parse(uriString);
    if ("markerselected".equalsIgnoreCase(invokedUri.getHost())) {
        final Intent poiDetailIntent = new Intent(ARViewActivity.this, PoiDetailActivity.class);
        String lsId = invokedUri.getQueryParameter("id");
        poiDetailIntent.putExtra("id", Integer.parseInt(lsId));
        ARViewActivity.this.startActivity(poiDetailIntent);
        return true;
    } else {// w w w .  j  av  a  2  s. c o  m
        return false;
    }
}

From source file:org.ohmage.app.MainActivity.java

private boolean handleNewIntent(Intent intent) {
    boolean handled = false;
    boolean showStreams = intent.getBooleanExtra(EXTRA_VIEW_STREAMS, false);
    boolean showSurveys = intent.getBooleanExtra(EXTRA_VIEW_SURVEYS, false);

    Uri data = intent.getData();
    if (data != null && "/stream/authorized".equals(data.getPath())) {

        String packageName = data.getQueryParameter("packageName");
        String error = data.getQueryParameter("error");
        if (error != null) {
            StreamNotAuthorizedError e = StreamNotAuthorizedError.newInstance(packageName, error);
            e.show(getSupportFragmentManager(), "stream_error");
            Log.d(TAG, "There was an error authorizing " + packageName + ": " + error);
        } else {//from   w w  w . j a  v  a  2 s  .  c o  m
            Log.d(TAG, "Successfully authorized: " + packageName);
        }

        showStreams = true;
    }

    if (showStreams || showSurveys) {
        String page = showSurveys ? getString(R.string.home) : getString(R.string.streams);
        for (int i = 0; i < mNavigationItems.length; i++) {
            if (page.equals(mNavigationItems[i])) {
                setFragment(i);
                handled = true;
                break;
            }
        }
    }
    return handled;
}

From source file:ph.com.globe.connect.AuthenticationActivity.java

/**
 * On activity create process.//from  w w  w .  j ava  2  s .  c om
 *
 * @param savedInstanceState instance state
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    // call base create
    super.onCreate(savedInstanceState);

    // initialize web view
    final WebView webview = new WebView(this);

    // set content view of the activity
    setContentView(webview);

    // get the app id from intent
    final String appId = getIntent().getStringExtra("app_id");
    // get the app secret from intent
    final String appSecret = getIntent().getStringExtra("app_secret");

    // set web view client
    webview.setWebViewClient(new WebViewClient() {
        /**
         * Let's catch all url changes.
         *
         * @param view current view
         * @param url current url
         * @return boolean
         */
        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // parse the uri
            final Uri uri = Uri.parse(url);

            // are we still on globe labs?
            if (uri.toString().indexOf(ROOT_URL) != 0) {
                // get the code
                String code = uri.getQueryParameter("code");

                // get access token request
                try {
                    getAccessToken(appId, appSecret, code);
                } catch (ApiException | HttpRequestException e) {
                    e.printStackTrace();
                }

                return false;
            }

            // load uri
            view.loadUrl(uri.toString());

            return false;
        }

        /**
         * Let's catch all url changes.
         *
         * @param view current view
         * @param request web resource request
         * @return boolean
         */
        @TargetApi(Build.VERSION_CODES.N)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            // parse the uri
            final Uri uri = Uri.parse(request.getUrl().toString());

            // are we still on globe labs?
            if (uri.toString().indexOf(ROOT_URL) != 0) {
                // get the code
                String code = uri.getQueryParameter("code");

                // get access token request
                try {
                    getAccessToken(appId, appSecret, code);
                } catch (ApiException | HttpRequestException e) {
                    e.printStackTrace();
                }

                return false;
            }

            // load uri
            view.loadUrl(uri.toString());

            return false;
        }
    });

    try {
        // set dialog url
        String DIALOG_URL = this.buildUrl(this.DIALOG_URL, appId);

        // load the url
        webview.loadUrl(DIALOG_URL);
    } catch (ApiException e) {
        e.printStackTrace();
    }
}