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.mobicage.rogerthat.registration.RegistrationActivity2.java

private void processIntent(Intent intent) {
    Uri uri = intent.getData();
    if (uri != null) {
        String url = uri.toString();

        if (RegexPatterns.FRIEND_INVITE_WITH_SECRET_URL.matcher(url).matches()) {
            popupRegisterFirst(uri);//w ww.ja va2  s  .c  om

            String invitorCode = url.substring(ProcessScanActivity.URL_ROGERTHAT_PREFIX.length(),
                    url.indexOf("?"));
            String secret = uri.getQueryParameter("s");
            Configuration cfg = mService.getConfigurationProvider()
                    .getConfiguration(RegistrationWizard2.CONFIGKEY);
            cfg.put(INVITOR_CODE_CONFIGKEY, invitorCode);
            cfg.put(INVITOR_SECRET_CONFIGKEY, secret);
            mService.getConfigurationProvider().updateConfigurationNow(RegistrationWizard2.CONFIGKEY, cfg);

        } else if (RegexPatterns.FRIEND_INVITE_URL.matcher(url).matches()
                || RegexPatterns.SERVICE_INTERACT_URL.matcher(url).matches()) {
            popupRegisterFirst(uri);

            Configuration cfg = mService.getConfigurationProvider()
                    .getConfiguration(RegistrationWizard2.CONFIGKEY);
            cfg.put(OPENED_URL_CONFIGKEY, url);
            mService.getConfigurationProvider().updateConfigurationNow(RegistrationWizard2.CONFIGKEY, cfg);
        }
    }
}

From source file:de.cachebox_test.splash.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!FileFactory.isInitial()) {
        new AndroidFileFactory();
    }//from  w w w .j  a  va  2 s.c  o  m

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.splash);

    DisplayMetrics displaymetrics = this.getResources().getDisplayMetrics();

    GlobalCore.displayDensity = displaymetrics.density;
    int h = displaymetrics.heightPixels;
    int w = displaymetrics.widthPixels;

    int sw = h > w ? w : h;
    sw /= GlobalCore.displayDensity;

    // check if tablet
    GlobalCore.isTab = sw > 400 ? true : false;

    int dpH = (int) (h / GlobalCore.displayDensity + 0.5);
    int dpW = (int) (w / GlobalCore.displayDensity + 0.5);

    if (dpH * dpW >= 960 * 720)
        GlobalCore.displayType = DisplayType.xLarge;
    else if (dpH * dpW >= 640 * 480)
        GlobalCore.displayType = DisplayType.Large;
    else if (dpH * dpW >= 470 * 320)
        GlobalCore.displayType = DisplayType.Normal;
    else
        GlobalCore.displayType = DisplayType.Small;

    // berprfen, ob ACB im Hochformat oder Querformat gestartet wurde.
    // Hochformat -> Handymodus
    // Querformat -> Tablet-Modus
    if (w > h)
        isLandscape = true;

    // Portrt erzwingen wenn Normal oder Small display
    if (isLandscape
            && (GlobalCore.displayType == DisplayType.Normal || GlobalCore.displayType == DisplayType.Small)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    // chek if use small skin
    GlobalCore.useSmallSkin = GlobalCore.displayType == DisplayType.Small ? true : false;

    // chk if tabletLayout posible
    GlobalCore.posibleTabletLayout = (GlobalCore.displayType == DisplayType.xLarge
            || GlobalCore.displayType == DisplayType.Large);

    // get parameters
    final Bundle extras = getIntent().getExtras();
    final Uri uri = getIntent().getData();

    // try to get data from extras
    if (extras != null) {
        GcCode = extras.getString("geocode");
        name = extras.getString("name");
        guid = extras.getString("guid");
    }

    // try to get data from URI
    if (GcCode == null && guid == null && uri != null) {
        String uriHost = uri.getHost().toLowerCase();
        String uriPath = uri.getPath().toLowerCase();
        // String uriQuery = uri.getQuery();

        if (uriHost.contains("geocaching.com")) {
            GcCode = uri.getQueryParameter("wp");
            guid = uri.getQueryParameter("guid");

            if (GcCode != null && GcCode.length() > 0) {
                GcCode = GcCode.toUpperCase();
                guid = null;
            } else if (guid != null && guid.length() > 0) {
                GcCode = null;
                guid = guid.toLowerCase();
            } else {
                // warning.showToast(res.getString(R.string.err_detail_open));
                finish();
                return;
            }
        } else if (uriHost.contains("coord.info")) {
            if (uriPath != null && uriPath.startsWith("/gc")) {
                GcCode = uriPath.substring(1).toUpperCase();
            } else {
                // warning.showToast(res.getString(R.string.err_detail_open));
                finish();
                return;
            }
        }
    }

    if (uri != null) {
        if (uri.getEncodedPath().endsWith(".gpx")) {
            GpxPath = uri.getEncodedPath();
        }
    }

    // if ACB running, call this instance
    if (main.mainActivity != null) {

        Bundle b = new Bundle();
        if (GcCode != null) {

            b.putSerializable("GcCode", GcCode);
            b.putSerializable("name", name);
            b.putSerializable("guid", guid);

        }

        if (GpxPath != null) {
            b.putSerializable("GpxPath", GpxPath);
        }

        Intent mainIntent = main.mainActivity.getIntent();

        mainIntent.putExtras(b);

        startActivity(mainIntent);
        finish();
    }

    splashActivity = this;

    LoadImages();

    if (savedInstanceState != null) {
        mSelectDbIsStartet = savedInstanceState.getBoolean("SelectDbIsStartet");
        mOriantationRestart = savedInstanceState.getBoolean("OriantationRestart");
    }

    if (mOriantationRestart)
        return; // wait for result

}

From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection,
        final String[] selectionArgs, final String sortOrder) {
    try {// w w w .ja v a  2 s  .c o  m
        final int tableId = getTableId(uri);
        final String table = getTableNameById(tableId);
        switch (tableId) {
        case VIRTUAL_TABLE_ID_DATABASE_READY: {
            if (mDatabaseWrapper.isReady())
                return new MatrixCursor(projection != null ? projection : new String[0]);
            return null;
        }
        case VIRTUAL_TABLE_ID_ALL_PREFERENCES: {
            return getPreferencesCursor(mPreferences, null);
        }
        case VIRTUAL_TABLE_ID_PREFERENCES: {
            return getPreferencesCursor(mPreferences, uri.getLastPathSegment());
        }
        case VIRTUAL_TABLE_ID_DNS: {
            return getDNSCursor(uri.getLastPathSegment());
        }
        case VIRTUAL_TABLE_ID_CACHED_IMAGES: {
            return getCachedImageCursor(uri.getQueryParameter(QUERY_PARAM_URL));
        }
        case VIRTUAL_TABLE_ID_NOTIFICATIONS: {
            final List<String> segments = uri.getPathSegments();
            if (segments.size() == 2)
                return getNotificationsCursor(ParseUtils.parseInt(segments.get(1), -1));
            else
                return getNotificationsCursor();
        }
        case VIRTUAL_TABLE_ID_UNREAD_COUNTS: {
            final List<String> segments = uri.getPathSegments();
            if (segments.size() == 2)
                return getUnreadCountsCursor(ParseUtils.parseInt(segments.get(1), -1));
            else
                return getUnreadCountsCursor();
        }
        case VIRTUAL_TABLE_ID_UNREAD_COUNTS_BY_TYPE: {
            final List<String> segments = uri.getPathSegments();
            if (segments.size() != 3)
                return null;
            return getUnreadCountsCursorByType(segments.get(2));
        }
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION: {
            final List<String> segments = uri.getPathSegments();
            if (segments.size() != 4)
                return null;
            final long accountId = ParseUtils.parseLong(segments.get(2));
            final long conversationId = ParseUtils.parseLong(segments.get(3));
            final SQLSelectQuery query = ConversationQueryBuilder.buildByConversationId(projection, accountId,
                    conversationId, selection, sortOrder);
            final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs);
            setNotificationUri(c, DirectMessages.CONTENT_URI);
            return c;
        }
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION_SCREEN_NAME: {
            final List<String> segments = uri.getPathSegments();
            if (segments.size() != 4)
                return null;
            final long accountId = ParseUtils.parseLong(segments.get(2));
            final String screenName = segments.get(3);
            final SQLSelectQuery query = ConversationQueryBuilder.buildByScreenName(projection, accountId,
                    screenName, selection, sortOrder);
            final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs);
            setNotificationUri(c, DirectMessages.CONTENT_URI);
            return c;
        }
        case VIRTUAL_TABLE_ID_CACHED_USERS_WITH_RELATIONSHIP: {
            final long accountId = ParseUtils.parseLong(uri.getLastPathSegment(), -1);
            final SQLSelectQuery query = CachedUsersQueryBuilder.buildWithRelationship(projection, selection,
                    sortOrder, accountId);
            final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs);
            setNotificationUri(c, CachedUsers.CONTENT_URI);
            return c;
        }
        case VIRTUAL_TABLE_ID_CACHED_USERS_WITH_SCORE: {
            final long accountId = ParseUtils.parseLong(uri.getLastPathSegment(), -1);
            final SQLSelectQuery query = CachedUsersQueryBuilder.buildWithScore(projection, selection,
                    sortOrder, accountId);
            final Cursor c = mDatabaseWrapper.rawQuery(query.getSQL(), selectionArgs);
            setNotificationUri(c, CachedUsers.CONTENT_URI);
            return c;
        }
        case VIRTUAL_TABLE_ID_DRAFTS_UNSENT: {
            final TwittnukerApplication app = TwittnukerApplication.getInstance(getContext());
            final AsyncTwitterWrapper twitter = app.getTwitterWrapper();
            final RawItemArray sendingIds = new RawItemArray(twitter.getSendingDraftIds());
            final Expression where;
            if (selection != null) {
                where = Expression.and(new Expression(selection),
                        Expression.notIn(new Column(Drafts._ID), sendingIds));
            } else {
                where = Expression.and(Expression.notIn(new Column(Drafts._ID), sendingIds));
            }
            final Cursor c = mDatabaseWrapper.query(Drafts.TABLE_NAME, projection, where.getSQL(),
                    selectionArgs, null, null, sortOrder);
            setNotificationUri(c, getNotificationUri(tableId, uri));
            return c;
        }
        }
        if (table == null)
            return null;
        final Cursor c = mDatabaseWrapper.query(table, projection, selection, selectionArgs, null, null,
                sortOrder);
        setNotificationUri(c, getNotificationUri(tableId, uri));
        return c;
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

@Override
public int bulkInsert(final Uri uri, final ContentValues[] values) {
    try {// ww w. j  a  v a  2s.co m
        final int table_id = getTableId(uri);
        final String table = getTableNameById(table_id);
        checkWritePermission(table_id, table);
        switch (table_id) {
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
        case TABLE_ID_DIRECT_MESSAGES:
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRY:
            return 0;
        }
        int result = 0;
        if (table != null && values != null) {
            final int old_count;
            switch (table_id) {
            case TABLE_ID_STATUSES: {
                old_count = getAllStatusesCount(mContext, Statuses.CONTENT_URI);
                break;
            }
            case TABLE_ID_MENTIONS: {
                old_count = getAllStatusesCount(mContext, Mentions.CONTENT_URI);
                break;
            }
            default:
                old_count = 0;
            }
            mDatabase.beginTransaction();
            for (final ContentValues contentValues : values) {
                mDatabase.insert(table, null, contentValues);
                result++;
            }
            mDatabase.setTransactionSuccessful();
            mDatabase.endTransaction();
            if (!"false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY))) {
                switch (table_id) {
                case TABLE_ID_STATUSES: {
                    mNewStatusesCount += getAllStatusesCount(mContext, Statuses.CONTENT_URI) - old_count;
                    break;
                }
                }
            }
        }
        if (result > 0) {
            onDatabaseUpdated(uri);
        }
        onNewItemsInserted(uri, values);
        return result;
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.gelakinetic.mtgfam.FamiliarActivity.java

private boolean processIntent(Intent intent) {
    boolean isDeepLink = false;

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        /* Do a search by name, launched from the quick search */
        String query = intent.getStringExtra(SearchManager.QUERY);
        Bundle args = new Bundle();
        SearchCriteria sc = new SearchCriteria();
        sc.name = query;//www.  j  a  v a 2s. c  om
        args.putSerializable(SearchViewFragment.CRITERIA, sc);
        selectItem(R.string.main_card_search, args, false,
                true); /* Don't clear backstack, do force the intent */

    } else if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        boolean shouldSelectItem = true;

        Uri data = intent.getData();
        Bundle args = new Bundle();
        assert data != null;

        boolean shouldClearFragmentStack = true; /* Clear backstack for deep links */
        if (data.getAuthority().toLowerCase().contains("gatherer.wizards")) {
            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                String queryParam;
                if ((queryParam = data.getQueryParameter("multiverseid")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByMultiverseId(Long.parseLong(queryParam),
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else if ((queryParam = data.getQueryParameter("name")) != null) {
                    Cursor cursor = CardDbAdapter.fetchCardByName(queryParam,
                            new String[] { CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                            true, database);
                    if (cursor.getCount() != 0) {
                        isDeepLink = true;
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    }
                    cursor.close();
                    if (args.size() == 0) {
                        throw new Exception("Not Found");
                    }
                } else {
                    throw new Exception("Not Found");
                }
            } catch (Exception e) {
                /* empty cursor, just return */
                ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                this.finish();
                shouldSelectItem = false;
            } finally {
                DatabaseManager.getInstance(this, false).closeDatabase(false);
            }
        } else if (data.getAuthority().contains("CardSearchProvider")) {
            /* User clicked a card in the quick search autocomplete, jump right to it */
            args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                    new long[] { Long.parseLong(data.getLastPathSegment()) });
            shouldClearFragmentStack = false; /* Don't clear backstack for search intents */
        } else {
            /* User clicked a deep link, jump to the card(s) */
            isDeepLink = true;

            SQLiteDatabase database = DatabaseManager.getInstance(this, false).openDatabase(false);
            try {
                Cursor cursor = null;
                boolean screenLaunched = false;
                if (data.getScheme().toLowerCase().equals("card")
                        && data.getAuthority().toLowerCase().equals("multiverseid")) {
                    if (data.getLastPathSegment() == null) {
                        /* Home screen deep link */
                        launchHomeScreen();
                        screenLaunched = true;
                        shouldSelectItem = false;
                    } else {
                        try {
                            /* Don't clear the fragment stack for internal links (thanks Meld cards) */
                            if (data.getPathSegments().contains("internal")) {
                                shouldClearFragmentStack = false;
                            }
                            cursor = CardDbAdapter.fetchCardByMultiverseId(
                                    Long.parseLong(data.getLastPathSegment()),
                                    new String[] {
                                            CardDbAdapter.DATABASE_TABLE_CARDS + "." + CardDbAdapter.KEY_ID },
                                    database);
                        } catch (NumberFormatException e) {
                            cursor = null;
                        }
                    }
                }

                if (cursor != null) {
                    if (cursor.getCount() != 0) {
                        args.putLongArray(CardViewPagerFragment.CARD_ID_ARRAY,
                                new long[] { cursor.getInt(cursor.getColumnIndex(CardDbAdapter.KEY_ID)) });
                    } else {
                        /* empty cursor, just return */
                        ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                        this.finish();
                        shouldSelectItem = false;
                    }
                    cursor.close();
                } else if (!screenLaunched) {
                    /* null cursor, just return */
                    ToastWrapper.makeText(this, R.string.no_results_found, ToastWrapper.LENGTH_LONG).show();
                    this.finish();
                    shouldSelectItem = false;
                }
            } catch (FamiliarDbException e) {
                e.printStackTrace();
            }
            DatabaseManager.getInstance(this, false).closeDatabase(false);
        }
        args.putInt(CardViewPagerFragment.STARTING_CARD_POSITION, 0);
        if (shouldSelectItem) {
            selectItem(R.string.main_card_search, args, shouldClearFragmentStack, true);
        }
    } else if (ACTION_ROUND_TIMER.equals(intent.getAction())) {
        selectItem(R.string.main_timer, null, true, false);
    } else if (ACTION_CARD_SEARCH.equals(intent.getAction())) {
        selectItem(R.string.main_card_search, null, true, false);
    } else if (ACTION_LIFE.equals(intent.getAction())) {
        selectItem(R.string.main_life_counter, null, true, false);
    } else if (ACTION_DICE.equals(intent.getAction())) {
        selectItem(R.string.main_dice, null, true, false);
    } else if (ACTION_TRADE.equals(intent.getAction())) {
        selectItem(R.string.main_trade, null, true, false);
    } else if (ACTION_MANA.equals(intent.getAction())) {
        selectItem(R.string.main_mana_pool, null, true, false);
    } else if (ACTION_WISH.equals(intent.getAction())) {
        selectItem(R.string.main_wishlist, null, true, false);
    } else if (ACTION_RULES.equals(intent.getAction())) {
        selectItem(R.string.main_rules, null, true, false);
    } else if (ACTION_JUDGE.equals(intent.getAction())) {
        selectItem(R.string.main_judges_corner, null, true, false);
    } else if (ACTION_MOJHOSTO.equals(intent.getAction())) {
        selectItem(R.string.main_mojhosto, null, true, false);
    } else if (ACTION_PROFILE.equals(intent.getAction())) {
        selectItem(R.string.main_profile, null, true, false);
    } else if (ACTION_DECKLIST.equals(intent.getAction())) {
        selectItem(R.string.main_decklist, null, true, false);
    } else if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        /* App launched as regular, show the default fragment if there isn't one already */
        if (getSupportFragmentManager().getFragments() == null) {
            launchHomeScreen();
        }
    } else {
        /* Some unknown intent, just finish */
        finish();
    }

    mDrawerList.setItemChecked(mCurrentFrag, true);
    return isDeepLink;
}

From source file:edwardawebb.queueman.classes.NetFlix.java

public Uri getRequestLoginUri() {
    Uri result = null;

    // we'll always need a request and access token (I think)
    // callbak only if users first time, but needed to get request token, so
    // aove may be wrong
    String callbackUrl = "flixman:///";// get url for user to link netflix

    // NetFlix.oaprovider.setOAuth10a(false);

    try {// w ww .  ja  v  a  2s . c  om

        // Log.d("NetFlix","token end:"+oaprovider.getRequestTokenEndpointUrl());
        // get url for user to lologin and request token
        String tmp = NetFlix.oaprovider.retrieveRequestToken(callbackUrl);
        // NetFlix.oaprovider.getResponseParameters().get("request_token");
        // Log.d("NetFlix","Url:"+tmp)
        result = Uri
                .parse(tmp + "&application_name=" + APPLICATION_NAME + "&oauth_consumer_key=" + CONSUMER_KEY);

        Log.i("oauth", "request token:" + result.getQueryParameter("oauth_token"));
        Log.i("oauth", "secret:" + result.getQueryParameter("oauth_token_secret"));
    } catch (OAuthMessageSignerException e) {

        reportError(e, lastResponseMessage);
    } catch (OAuthNotAuthorizedException e) {

        reportError(e, lastResponseMessage);
    } catch (OAuthExpectationFailedException e) {

        reportError(e, lastResponseMessage);
    } catch (OAuthCommunicationException e) {

        reportError(e, lastResponseMessage);
    }
    return result;
}

From source file:com.aimfire.gallery.GalleryActivity.java

/**
 * parse the link that led us here. check if the file already exists. if not, start
 * DownloadFileFragment. // ww  w.j a  va 2s . c  om
 * 
 * @param uri
 * @return path to the file download location. in the case of a chained download, we 
 * will always return the path to the cvr file (rather than the preview file)
 */
private String handleDownload(Uri uri) {
    if (!isDeviceOnline()) {
        Toast.makeText(this, R.string.error_no_network, Toast.LENGTH_LONG).show();
        return null;
    }

    String mePath = null;
    String sharePath = null;

    String resId = uri.getQueryParameter("id");
    String origName = uri.getQueryParameter("name");

    if ((resId == null) || (origName == null)) {
        Toast.makeText(this, R.string.error_incorrect_link, Toast.LENGTH_LONG).show();
        return null;
    }

    saveDriveFileRecord(origName, resId);

    /*
     * we could have the size if this is the cvr download (chained-mode)
     */
    int size = -1;
    String sizeStr = uri.getQueryParameter("size");
    if (sizeStr != null) {
        try {
            size = Integer.parseInt(sizeStr);
        } catch (Exception e) {
            Toast.makeText(this, R.string.error_incorrect_link, Toast.LENGTH_LONG).show();
            return null;
        }
    }

    /*
     * we check if the file already exists. file name may be:
     * 
     * SBS...jpg - this is a 3D SBS image, non-chained mode
     * MPG...jpeg - this is a preview frame of movie, chained mode
     * 
     * if a jpg or movie file exists in my media or shared media path, then we
     * either have successfully downloaded the photo or preview or we are 
     * currently downloading it - remember we delete the placeholder jpg or 
     * cvr file in case of failure. 
     * 
     * the link may specify a movie (cvr) file - we have the legacy code here 
     * for it, but we currently don't use it. in that case the file name is:
     * 
     * MPG...cvr - this is a 3D cvr movie, non-chained mode
     */
    mePath = MediaScanner.getMyMediaPathFromOrigName(origName);
    sharePath = MediaScanner.getSharedMediaPathFromOrigName(origName);

    if (new File(mePath).exists()) {
        /*
         * this only happens if we click on the link that we sent to ourselves
         */
        if (BuildConfig.DEBUG)
            Log.d(TAG, "handleDownload: file already exists in My Media!");
        mIsMyMedia = true;
        return mePath;
    } else if (new File(sharePath).exists()) {
        /*
         * this happens if we have downloaded this file before
         */
        if (BuildConfig.DEBUG)
            Log.d(TAG, "handleDownload: file already exists in Shared Media!");
        mIsMyMedia = false;
        return sharePath;
    }

    /*
     * the file doesn't exist and we need to download it.
     * 
      * create an empty, placeholder file, so GalleryActivity/ThumbsFragment knows 
      * its existence and show a progress bar while this file is downloaded
      */
    try {
        MediaScanner.addItemMediaList(sharePath);
        (new File(sharePath)).createNewFile();
    } catch (IOException e) {
        Toast.makeText(this, R.string.error_accessing_storage, Toast.LENGTH_LONG).show();
        return null;
    }

    if (MediaScanner.isMovie(origName)) {
        /*
         * legacy code - download cvr from a link.
         */
        addDownloadFileFragment(resId, origName, size);
    } else {
        Intent serviceIntent = new Intent(this, FileDownloaderService.class);

        if (MediaScanner.isPreview(origName)) {
            serviceIntent.putExtra(MainConsts.EXTRA_PATH, MediaScanner.getPreviewPathFromOrigName(origName));
        } else {
            serviceIntent.putExtra(MainConsts.EXTRA_PATH, sharePath);
        }
        startService(serviceIntent);
    }

    return sharePath;
}

From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java

@Override
public ParcelFileDescriptor openFile(final Uri uri, final String mode) throws FileNotFoundException {
    if (uri == null || mode == null)
        throw new IllegalArgumentException();
    final int table_id = getTableId(uri);
    final String table = getTableNameById(table_id);
    final int mode_code;
    if ("r".equals(mode)) {
        mode_code = ParcelFileDescriptor.MODE_READ_ONLY;
    } else if ("rw".equals(mode)) {
        mode_code = ParcelFileDescriptor.MODE_READ_WRITE;
    } else if ("rwt".equals(mode)) {
        mode_code = ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_TRUNCATE;
    } else//from   w w w .  j  a va  2s  .  c o m
        throw new IllegalArgumentException();
    if (mode_code == ParcelFileDescriptor.MODE_READ_ONLY) {
        checkReadPermission(table_id, table, null);
    } else if ((mode_code & ParcelFileDescriptor.MODE_READ_WRITE) != 0) {
        checkReadPermission(table_id, table, null);
        checkWritePermission(table_id, table);
    }
    switch (table_id) {
    case VIRTUAL_TABLE_ID_CACHED_IMAGES: {
        return getCachedImageFd(uri.getQueryParameter(QUERY_PARAM_URL));
    }
    case VIRTUAL_TABLE_ID_CACHE_FILES: {
        return getCacheFileFd(uri.getLastPathSegment());
    }
    }
    return null;
}

From source file:android.webkit.cts.WebViewTest.java

@UiThreadTest
public void testLoadUrlDoesNotStripParamsWhenLoadingContentUrls() throws Exception {
    if (!NullWebViewUtils.isWebViewAvailable()) {
        return;/*from  w w w. j a  v  a2 s  .  co m*/
    }

    Uri.Builder uriBuilder = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
            .authority(MockContentProvider.AUTHORITY);
    uriBuilder.appendPath("foo.html").appendQueryParameter("param", "bar");
    String url = uriBuilder.build().toString();
    mOnUiThread.loadUrlAndWaitForCompletion(url);
    // verify the parameter is not stripped.
    Uri uri = Uri.parse(mWebView.getTitle());
    assertEquals("bar", uri.getQueryParameter("param"));
}

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

private void handleIntent(Intent intent) {

    String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {

        // check what type of search we need
        SearchTypes searchType = AnyPlaceSeachingHelper.getSearchType(mMap.getCameraPosition().zoom);
        String query = intent.getStringExtra(SearchManager.QUERY);
        GeoPoint gp = userData.getLatestUserPosition();

        // manually launch the real search activity
        Intent searchIntent = new Intent(UnifiedNavigationActivity.this, SearchPOIActivity.class);
        // add query to the Intent Extras
        searchIntent.setAction(action);/*from w  ww. j  av  a 2  s .  c o  m*/
        searchIntent.putExtra("searchType", searchType);
        searchIntent.putExtra("query", query);
        searchIntent.putExtra("lat", (gp == null) ? csLat : gp.dlat);
        searchIntent.putExtra("lng", (gp == null) ? csLon : gp.dlon);
        startActivityForResult(searchIntent, SEARCH_POI_ACTIVITY_RESULT);

    } else if (Intent.ACTION_VIEW.equals(action)) {
        String data = intent.getDataString();

        if (data != null && data.startsWith("http")) {
            final Uri uri = intent.getData();
            if (uri != null) {
                String path = uri.getPath();

                if (path != null && path.equals("/getnavigation")) {
                    String poid = uri.getQueryParameter("poid");
                    if (poid == null || poid.equals("")) {
                        // Share building
                        // http://anyplace.rayzit.com/getnavigation?buid=username_1373876832005&floor=0
                        String buid = uri.getQueryParameter("buid");
                        if (buid == null || buid.equals("")) {
                            Toast.makeText(getBaseContext(), "Buid parameter expected", Toast.LENGTH_SHORT)
                                    .show();
                        } else {
                            mAutomaticGPSBuildingSelection = false;
                            mAnyplaceCache.loadBuilding(buid, new FetchBuildingTaskListener() {

                                @Override
                                public void onSuccess(String result, final BuildingModel b) {

                                    bypassSelectBuildingActivity(b, uri.getQueryParameter("floor"), true);

                                }

                                @Override
                                public void onErrorOrCancel(String result) {
                                    Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();

                                }
                            }, UnifiedNavigationActivity.this);
                        }
                    } else {
                        // Share POI
                        // http://anyplace.rayzit.com/getnavigation?poid=username_username_1373876832005_0_35.14424091022549_33.41139659285545_1382635428093
                        mAutomaticGPSBuildingSelection = false;
                        new FetchPoiByPuidTask(new FetchPoiByPuidTask.FetchPoiListener() {

                            @Override
                            public void onSuccess(String result, final PoisModel poi) {

                                if (userData.getSelectedBuildingId() != null
                                        && userData.getSelectedBuildingId().equals(poi.buid)) {
                                    // Building is Loaded
                                    startNavigationTask(poi.puid);
                                } else {
                                    // Load Building
                                    mAnyplaceCache.loadBuilding(poi.buid, new FetchBuildingTaskListener() {

                                        @Override
                                        public void onSuccess(String result, final BuildingModel b) {

                                            bypassSelectBuildingActivity(b, poi.floor_number, true, poi);

                                        }

                                        @Override
                                        public void onErrorOrCancel(String result) {
                                            Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();

                                        }
                                    }, UnifiedNavigationActivity.this);
                                }
                            }

                            @Override
                            public void onErrorOrCancel(String result) {
                                Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();
                            }
                        }, this, poid).execute();
                    }
                }
            }
        } else {

            // Search TextBox results only

            // PoisModel or Place Class
            IPoisClass place_selected = AnyPlaceSeachingHelper.getClassfromJson(data);

            if (place_selected.id() != null) {
                // hide the search view when a navigation route is drawn
                if (searchView != null) {
                    searchView.setIconified(true);
                    searchView.clearFocus();
                }
                handleSearchPlaceSelection(place_selected);
            }

        }

    }
}