Example usage for android.net Uri getEncodedSchemeSpecificPart

List of usage examples for android.net Uri getEncodedSchemeSpecificPart

Introduction

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

Prototype

public abstract String getEncodedSchemeSpecificPart();

Source Link

Document

Gets the scheme-specific part of this URI, i.e. everything between the scheme separator ':' and the fragment separator '#'.

Usage

From source file:com.openlocationcode.android.main.MainActivity.java

/**
 * Handles intent URIs, extracts the query part and sends it to the search function.
 * <p/>/*  w ww . j a  v a  2  s . com*/
 * URIs may be of the form:
 * <ul>
 * <li>{@code geo:37.802,-122.41962}
 * <li>{@code geo:37.802,-122.41962?q=7C66CM4X%2BC34&z=20}
 * <li>{@code geo:0,0?q=WF59%2BX67%20Praia}
 * </ul>
 * <p/>
 * Only the query string is used. Coordinates and zoom level are ignored. If the query string
 * is not recognised by the search function (say, it's a street address), it will fail.
 */
private void handleGeoIntent(Intent intent) {
    Uri uri = intent != null ? intent.getData() : null;
    if (uri == null) {
        return;
    }
    String schemeSpecificPart = uri.getEncodedSchemeSpecificPart();
    if (schemeSpecificPart == null || schemeSpecificPart.isEmpty()) {
        return;
    }
    // Get everything after q=
    int queryIndex = schemeSpecificPart.indexOf(URI_QUERY_SEPARATOR);
    if (queryIndex == -1) {
        return;
    }
    String searchQuery = schemeSpecificPart.substring(queryIndex + 2);
    if (searchQuery.contains(URI_ZOOM_SEPARATOR)) {
        searchQuery = searchQuery.substring(0, searchQuery.indexOf(URI_ZOOM_SEPARATOR));
    }
    final String searchString = Uri.decode(searchQuery);
    Log.i(TAG, "Search string is " + searchString);

    // Give the map some time to get ready.
    Handler h = new Handler();
    Runnable r = new Runnable() {
        @Override
        public void run() {
            if (mMainPresenter.getSearchActionsListener().searchCode(searchString)) {
                mMainPresenter.getSearchActionsListener().setSearchText(searchString);
            }
        }
    };
    h.postDelayed(r, 2000);
}

From source file:edu.mit.mobile.android.demomode.Preferences.java

private void fromCfgString(String cfg) {
    final Uri cfgUri = Uri.parse(cfg);
    if ("data".equals(cfgUri.getScheme())) {
        final String[] cfgParts = cfgUri.getEncodedSchemeSpecificPart().split(",", 2);
        if (CFG_MIME_TYPE.equals(cfgParts[0])) {
            final Editor ed = mPrefs.edit();
            final ArrayList<ContentProviderOperation> cpos = new ArrayList<ContentProviderOperation>();

            // first erase everything
            cpos.add(ContentProviderOperation.newDelete(LauncherItem.CONTENT_URI).build());

            try {
                final StringEntity entity = new StringEntity(cfgParts[1]);
                entity.setContentType("application/x-www-form-urlencoded");
                final List<NameValuePair> nvp = URLEncodedUtils.parse(entity);
                for (final NameValuePair pair : nvp) {
                    final String name = pair.getName();
                    Log.d(TAG, "parsed pair: " + pair);
                    if (CFG_K_SECRETKEY.equals(name)) {
                        ed.putString(KEY_PASSWORD, pair.getValue());

                    } else if (CFG_K_APPS.equals(name)) {
                        final String[] app = pair.getValue().split(CFG_PKG_SEP, 2);
                        final ContentProviderOperation cpo = ContentProviderOperation
                                .newInsert(LauncherItem.CONTENT_URI)
                                .withValue(LauncherItem.PACKAGE_NAME, app[0])
                                .withValue(LauncherItem.ACTIVITY_NAME, app[1]).build();
                        cpos.add(cpo);// w  ww.j ava 2 s .co m
                        Log.d(TAG, "adding " + cpo);
                    }
                }

                ed.commit();
                getContentResolver().applyBatch(HomescreenProvider.AUTHORITY, cpos);
            } catch (final UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (final IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (final RemoteException e) {
                // TODO Auto-generated catch block

                e.printStackTrace();
            } catch (final OperationApplicationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } else {
            Log.e(TAG, "unknown MIME type for data URI: " + cfgParts[0]);
        }

    } else {
        Log.e(TAG, "not a data URI");
    }
}

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

public void startCertify(Uri dataUri) {
    // example: openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282
    if (dataUri.getScheme().equals(Constants.FINGERPRINT_SCHEME)) {
        String fingerprint = dataUri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH);
        importKeys(fingerprint);//  w  w w.j a  v a2 s. c o m
    } else {
        SingletonResult result = new SingletonResult(SingletonResult.RESULT_ERROR,
                OperationResult.LogType.MSG_WRONG_QR_CODE);
        Intent intent = new Intent();
        intent.putExtra(SingletonResult.EXTRA_RESULT, result);
        returnResult(intent);
    }
}

From source file:org.linphone.setup.RemoteProvisioningActivity.java

private void checkIntentForConfigUri(final Intent intent) {
    new Thread(new Runnable() {

        @Override//  w  ww.ja v a2  s .c  o m
        public void run() {
            Uri openUri = intent.getData();
            if (openUri != null) {
                // We expect something like linphone-config://http://linphone.org/config.xml
                configUriParam = openUri.getEncodedSchemeSpecificPart().substring(2); // Removes the linphone-config://
                Log.d("Using config uri: " + configUriParam);
            }

            if (configUriParam == null) {
                if (!LinphonePreferences.instance().isFirstRemoteProvisioning()) {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            goToLinphoneActivity();
                        }
                    });
                } else if (!getResources()
                        .getBoolean(R.bool.forbid_app_usage_until_remote_provisioning_completed)) {
                    // Show this view for a few seconds then go to the dialer
                    mHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            goToLinphoneActivity();
                        }
                    }, 1500);
                } // else we do nothing if there is no config uri parameter and if user not allowed to leave this screen
            } else {
                if (getResources().getBoolean(R.bool.display_confirmation_popup_after_first_configuration)
                        && !LinphonePreferences.instance().isFirstRemoteProvisioning()) {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            displayDialogConfirmation();
                        }
                    });
                } else {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            setRemoteProvisioningAddressAndRestart(configUriParam);
                        }
                    });
                }
            }
        }
    }).start();
}

From source file:com.dosse.bwentrain.androidPlayer.MainActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    new AdsController().start();
    try {// w  ww. j  av  a 2  s .co m
        if (getIntent().getData() != null) { //called from an url
            Uri u = getIntent().getData();
            if (u == null)
                throw new Exception();
            String url = u.getScheme() + ":" + u.getEncodedSchemeSpecificPart();
            if (url.toLowerCase().startsWith("http://sine.adolfintel.com/forum")
                    || url.toLowerCase().startsWith("http://isochronic.io/forum"))
                startActivity(new Intent(this, CommunityActivity.class).putExtra("path", url)); //throw the url to the community activity
            else if (url.toLowerCase().startsWith("http://sine.adolfintel.com/goto.php")
                    || url.toLowerCase().startsWith("http://sine.adolfintel.com/presets.php")
                    || url.toLowerCase().startsWith("http://isochronic.io/goto.php")
                    || url.toLowerCase().startsWith("http://isochronic.io/presets.php")) { //link to a preset, or to the preset page
                //attempt to convert to mobile and localized link
                try {
                    String newUrl = getString(R.string.presets_url);
                    //find preset id (if present) and add it to the new url
                    String q = new URL(url).getQuery();
                    if (q != null) {
                        String[] query = q.split("\\?");
                        for (String s : query) {
                            String[] ss = s.split("=");
                            if (ss[0].trim().equalsIgnoreCase("id")) {
                                newUrl += "%26id=" + Integer.parseInt(ss[1].trim());
                                break;
                            }
                        }
                    }
                    Intent i = new Intent(this, BrowserActivity.class);
                    i.putExtra("path", newUrl);
                    startActivity(i);
                } catch (Throwable t) {
                    Toast.makeText(getApplicationContext(), getString(R.string.community_invalid_presetId),
                            Toast.LENGTH_SHORT).show();
                }
            } else
                throw new Exception(); //ignore unknown urls
        } else
            throw new Exception();
    } catch (Throwable t) {
    }
    try {
        openFileInput("material.run");
        //material.run exists, go straight to the app
    } catch (Throwable t) {
        Intent i = new Intent(MainActivity.this, IntroActivity.class);
        try {
            openFileInput("first.run");
            //first.run exists, the user just updated the app to the material design version, show update intro
            i.putExtra("update", true);
        } catch (Throwable t1) {
            //first.run does not exist, show intro
            i.putExtra("update", false);
        }
        startActivity(i);
        try {
            openFileOutput("material.run", MODE_PRIVATE).close();
        } catch (Throwable t1) {
        }
    }
    super.onPostCreate(savedInstanceState);
}

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

private void processScannedContent(Uri uri) {
    String action = getIntent().getAction();

    Log.d(Constants.TAG, "scanned: " + uri);

    // example: openpgp4fpr:73EE2314F65FA92EC2390D3A718C070100012282
    if (uri == null || uri.getScheme() == null
            || !uri.getScheme().toLowerCase(Locale.ENGLISH).equals(Constants.FINGERPRINT_SCHEME)) {
        SingletonResult result = new SingletonResult(SingletonResult.RESULT_ERROR, LogType.MSG_WRONG_QR_CODE);
        Intent intent = new Intent();
        intent.putExtra(SingletonResult.EXTRA_RESULT, result);
        returnResult(intent);/*from  w w w  . j a va 2  s . c o  m*/
        return;
    }
    final String fingerprint = uri.getEncodedSchemeSpecificPart().toLowerCase(Locale.ENGLISH);
    if (!fingerprint.matches("[a-fA-F0-9]{40}")) {
        SingletonResult result = new SingletonResult(SingletonResult.RESULT_ERROR,
                LogType.MSG_WRONG_QR_CODE_FP);
        Intent intent = new Intent();
        intent.putExtra(SingletonResult.EXTRA_RESULT, result);
        returnResult(intent);
        return;
    }

    if (ACTION_SCAN_WITH_RESULT.equals(action)) {
        Intent result = new Intent();
        result.putExtra(EXTRA_FINGERPRINT, fingerprint);
        setResult(RESULT_OK, result);
        finish();
    } else {
        importKeys(fingerprint);
    }

}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

@Override
protected void onCreate(Bundle pSavedInstanceState) {
    super.onCreate(pSavedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // create the layout of the view
    setupView();//  ww  w.  j a  v a  2  s.  c  o  m

    // determine the messages to be displayed as the view loads the video
    extractMessages();

    // grab a wake-lock so that the video can play without the screen being turned off
    PowerManager lPwrMgr = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = lPwrMgr.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG_WAKELOCK);
    mWakeLock.acquire();

    mProgressMessage.setText(mMsgInit);

    // extract the playlist or video id from the intent that started this video

    Uri lVideoIdUri = this.getIntent().getData();

    if (lVideoIdUri == null) {
        Log.i(this.getClass().getSimpleName(),
                "No video ID was specified in the intent.  Closing video activity.");
        finish();
    }
    String lVideoSchemeStr = lVideoIdUri.getScheme();
    String lVideoIdStr = lVideoIdUri.getEncodedSchemeSpecificPart();
    if (lVideoIdStr == null) {
        Log.i(this.getClass().getSimpleName(),
                "No video ID was specified in the intent.  Closing video activity.");
        finish();
    }
    if (lVideoIdStr.startsWith("//")) {
        if (lVideoIdStr.length() > 2) {
            lVideoIdStr = lVideoIdStr.substring(2);
        } else {
            Log.i(this.getClass().getSimpleName(),
                    "No video ID was specified in the intent.  Closing video activity.");
            finish();
        }
    }

    ///////////////////
    // extract either a video id or a playlist id, depending on the uri scheme
    YouTubeId lYouTubeId = null;
    if (lVideoSchemeStr != null && lVideoSchemeStr.equalsIgnoreCase(SCHEME_YOUTUBE_PLAYLIST)) {
        lYouTubeId = new PlaylistId(lVideoIdStr);
    }

    else if (lVideoSchemeStr != null && lVideoSchemeStr.equalsIgnoreCase(SCHEME_YOUTUBE_VIDEO)) {
        lYouTubeId = new VideoId(lVideoIdStr);
    }

    if (lYouTubeId == null) {
        Log.i(this.getClass().getSimpleName(),
                "Unable to extract video ID from the intent.  Closing video activity.");
        finish();
    }

    mQueryYouTubeTask = (QueryYouTubeTask) new QueryYouTubeTask().execute(lYouTubeId);
}

From source file:com.newcell.calltext.ui.SipHome.java

private void selectTabWithAction(Intent intent) {
    if (intent != null) {
        String callAction = intent.getAction();

        if (!TextUtils.isEmpty(callAction)) {

            ActionBar ab = getSupportActionBar();
            Tab toSelectTab = null;/* ww  w  . j a va2 s.c  o m*/
            Integer toSelectId = null;
            if (callAction.equalsIgnoreCase(SipManager.ACTION_SIP_DIALER)
                    || callAction.equalsIgnoreCase(Intent.ACTION_DIAL)
                    || callAction.equalsIgnoreCase(Intent.ACTION_VIEW)) {
                Integer pos = mTabsAdapter.getPositionForId(TAB_ID_DIALER);
                if (pos != null) {
                    toSelectTab = ab.getTabAt(pos);
                    Uri data = intent.getData();
                    String nbr = UriUtils.extractNumberFromIntent(intent, this);

                    if (!TextUtils.isEmpty(nbr)) {
                        if (data != null && mDialpadFragment != null) {
                            mDialpadFragment.setTextDialing(true);
                            mDialpadFragment.setTextFieldValue(nbr);
                        } else {
                            initDialerWithText = nbr;
                        }
                    }
                    toSelectId = TAB_ID_DIALER;
                }
            } else if (callAction.equalsIgnoreCase(SipManager.ACTION_SIP_CALLLOG)) {
                Integer pos = mTabsAdapter.getPositionForId(TAB_ID_CALL_LOG);
                if (pos != null) {
                    toSelectTab = ab.getTabAt(pos);
                    toSelectId = TAB_ID_CALL_LOG;
                }
            } else if (callAction.equalsIgnoreCase(SipManager.ACTION_SIP_MESSAGES)
                    || callAction.equalsIgnoreCase(Intent.ACTION_SENDTO)) {
                Uri callUri = intent.getData();
                Integer pos = mTabsAdapter.getPositionForId(TAB_ID_MESSAGES);

                if (pos != null) {
                    toSelectTab = ab.getTabAt(pos);
                    toSelectId = TAB_ID_MESSAGES;

                    if (callUri != null) {
                        String phoneNumber = callUri.getEncodedSchemeSpecificPart();
                        // User selected 'Send text message' from a contact in their contact list
                        // Switch to the messaging tab, and then open up the MessageFragment to them

                        // Open up a new MessageFragment to the contact they selected
                        Bundle b = MessageFragment.getArguments(phoneNumber, null);
                        Intent it = new Intent(this, MessageActivity.class);
                        it.putExtras(b);
                        startActivity(it);
                    }
                }
            }
            if (toSelectTab != null) {
                ab.selectTab(toSelectTab);
                initTabId = toSelectId;
            } else {
                initTabId = 0;
            }

        }
    }
}

From source file:org.geometerplus.android.fbreader.FBReader.java

@Override
protected void onNewIntent(final Intent intent) {
    final String action = intent.getAction();
    final Uri data = intent.getData();

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
        super.onNewIntent(intent);
    } else if (Intent.ACTION_VIEW.equals(action) && data != null
            && "fbreader-action".equals(data.getScheme())) {
        myFBReaderApp.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
    } else if (Intent.ACTION_VIEW.equals(action) || FBReaderIntents.Action.VIEW.equals(action)) {
        myOpenBookIntent = intent;//ww  w  .  j  a  v a  2  s.  co m
        if (myFBReaderApp.Model == null && myFBReaderApp.ExternalBook != null) {
            final ExternalFormatPlugin plugin = (ExternalFormatPlugin) myFBReaderApp.ExternalBook
                    .getPluginOrNull();
            try {
                startActivity(PluginUtil.createIntent(plugin, PluginUtil.ACTION_KILL));
            } catch (ActivityNotFoundException e) {
                e.printStackTrace();
            }
        }
    } else if (FBReaderIntents.Action.PLUGIN.equals(action)) {
        new RunPluginAction(this, myFBReaderApp, data).run();
    } else if (Intent.ACTION_SEARCH.equals(action)) {
        final String pattern = intent.getStringExtra(SearchManager.QUERY);
        final Runnable runnable = new Runnable() {
            public void run() {
                final TextSearchPopup popup = (TextSearchPopup) myFBReaderApp.getPopupById(TextSearchPopup.ID);
                popup.initPosition();
                myFBReaderApp.MiscOptions.TextSearchPattern.setValue(pattern);
                if (myFBReaderApp.getTextView().search(pattern, true, false, false, false) != 0) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            myFBReaderApp.showPopup(popup.getId());
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            UIUtil.showErrorMessage(FBReader.this, "textNotFound");
                            popup.StartPosition = null;
                        }
                    });
                }
            }
        };
        UIUtil.wait("search", runnable, this);
    } else if (FBReaderIntents.Action.CLOSE.equals(intent.getAction())) {
        myCancelIntent = intent;
        myOpenBookIntent = null;
    } else if (FBReaderIntents.Action.PLUGIN_CRASH.equals(intent.getAction())) {
        final Book book = FBReaderIntents.getBookExtra(intent);
        myFBReaderApp.ExternalBook = null;
        myOpenBookIntent = null;
        getCollection().bindToService(this, new Runnable() {
            public void run() {
                Book b = myFBReaderApp.Collection.getRecentBook(0);
                if (b.equals(book)) {
                    b = myFBReaderApp.Collection.getRecentBook(1);
                }
                myFBReaderApp.openBook(b, null, null, FBReader.this);
            }
        });
    } else {
        super.onNewIntent(intent);
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {

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

    super.onCreate(savedInstanceState);
    ActionBarCompat abCompat = ActionBarCompat.create(this);
    abCompat.setDisplayHomeAsUpEnabled(true);

    setContentView(R.layout.appdetails);

    Intent i = getIntent();/*from  w w w  .j  ava 2s.c  om*/
    appid = "";
    Uri data = getIntent().getData();
    if (data != null) {
        if (data.isHierarchical()) {
            if (data.getHost().equals("details")) {
                // market://details?id=app.id
                appid = data.getQueryParameter("id");
            } else {
                // https://f-droid.org/app/app.id
                appid = data.getLastPathSegment();
            }
        } else {
            // fdroid.app:app.id (old scheme)
            appid = data.getEncodedSchemeSpecificPart();
        }
        Log.d("FDroid", "AppDetails launched from link, for '" + appid + "'");
    } else if (!i.hasExtra("appid")) {
        Log.d("FDroid", "No application ID in AppDetails!?");
    } else {
        appid = i.getStringExtra("appid");
    }

    // Set up the list...
    headerView = new LinearLayout(this);
    ListView lv = (ListView) findViewById(android.R.id.list);
    lv.addHeaderView(headerView);
    ApkListAdapter la = new ApkListAdapter(this, null);
    setListAdapter(la);

    mPm = getPackageManager();
    // Get the preferences we're going to use in this Activity...
    AppDetails old = (AppDetails) getLastNonConfigurationInstance();
    if (old != null) {
        copyState(old);
    } else {
        if (!reset()) {
            finish();
            return;
        }
        resetRequired = false;
    }
    startViews();

}