Example usage for android.net Uri getScheme

List of usage examples for android.net Uri getScheme

Introduction

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

Prototype

@Nullable
public abstract String getScheme();

Source Link

Document

Gets the scheme of this URI.

Usage

From source file:com.takondi.tartt.ARActivity.java

@Override
public boolean urlWasInvoked(String url) {
    Log.d(TAG, "urlWasInvoked " + url);
    if (url != null) {
        Uri uri = Uri.parse(url);
        if (URL_ARCHITECTSDK_SCHEME.equals(uri.getScheme())) {
            JSONObject paramJson = new JSONObject();
            if (!uri.getQueryParameterNames().isEmpty()) {
                for (String param : uri.getQueryParameterNames()) {
                    try {
                        paramJson.put(param, uri.getQueryParameter(param));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }/*from w ww.j a  v a2 s . co  m*/
                }
            }
            handleEvent(uri.getHost(), paramJson);
        }
    }
    return false;
}

From source file:com.zql.android.clippings.device.view.MainActivity.java

public String getFilePathByUri(Uri uri) {
    if (uri == null) {
        return null;
    }/*from   w  ww  .j ava  2 s .  co m*/
    String filePath = "unknown";//default fileName
    Uri filePathUri = uri;
    try {
        if (uri.getScheme().compareTo("content") == 0) {
            if (Build.VERSION.SDK_INT == 22 || Build.VERSION.SDK_INT == 23) {
                try {
                    String pathUri = uri.getPath();
                    String newUri = pathUri.substring(pathUri.indexOf("content"),
                            pathUri.lastIndexOf("/ACTUAL"));
                    uri = Uri.parse(newUri);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Cursor cursor = getApplicationContext().getContentResolver().query(uri,
                        new String[] { MediaStore.Images.Media.DATA }, null, null, null);
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                            filePath = cursor.getString(column_index);
                        }
                        cursor.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else {
                Cursor cursor = getApplicationContext().getContentResolver().query(uri,
                        new String[] { MediaStore.Images.Media.DATA }, null, null, null);
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                            filePathUri = Uri.parse(cursor.getString(column_index));
                            filePath = filePathUri.getPath();
                        }
                    } catch (Exception e) {
                        cursor.close();
                    }
                }
            }
        } else if (uri.getScheme().compareTo("file") == 0) {
            filePath = filePathUri.getPath();
        } else {
            filePath = filePathUri.getPath();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    return filePath;
}

From source file:edu.stanford.mobisocial.dungbeetle.HandleNfcContact.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();//  www . j  a v  a 2s .c o  m
    final Uri uri = intent.getData();

    setContentView(R.layout.handle_give);
    Button saveButton = (Button) findViewById(R.id.save_contact_button);
    Button cancelButton = (Button) findViewById(R.id.cancel_button);
    Button mutualFriendsButton = (Button) findViewById(R.id.mutual_friends_button);
    mutualFriendsButton.setVisibility(View.GONE);

    if (uri != null && (uri.getScheme().equals(HomeActivity.SHARE_SCHEME)
            || uri.getSchemeSpecificPart().startsWith(FriendRequest.PREFIX_JOIN))) {

        mEmail = uri.getQueryParameter("email");

        mName = uri.getQueryParameter("name");
        if (mName == null) {
            mName = mEmail;

        }

        TextView nameView = (TextView) findViewById(R.id.name_text);
        nameView.setText("Would you like to be friends with " + mName + "?");

        final long cid = FriendRequest.acceptFriendRequest(HandleNfcContact.this, uri, false);
        saveButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                DBHelper helper = DBHelper.getGlobal(HandleNfcContact.this);
                IdentityProvider ident = new DBIdentityProvider(helper);

                try {
                    JSONObject profile = new JSONObject(ident.userProfile());
                    byte[] data = FastBase64.decode(profile.getString("picture"));

                    Helpers.updatePicture(HandleNfcContact.this, data);
                } catch (Exception e) {
                }

                // If asymmetric friend request, send public key.
                if (!NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
                    FriendRequest.sendFriendRequest(HandleNfcContact.this, cid, uri.getQueryParameter("cap"));
                }

                Toast.makeText(HandleNfcContact.this, "Added " + mName + " as a friend.", Toast.LENGTH_SHORT)
                        .show();
                finish();
            }
        });

        cancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Helpers.deleteContact(HandleNfcContact.this, cid);
                finish();
            }
        });

        ImageView portraitView = (ImageView) findViewById(R.id.image);
        if (uri != null) {
            /*
                ((App)getApplication()).contactImages.lazyLoadImage(
            mEmail.hashCode(),
            Gravatar.gravatarUri(mEmail, 100), 
            portraitView);
            */

            //((App)getApplication()).contactImages.lazyLoadImage(mPicture.hashCode(), mPicture, portraitView);
        }
    } else {
        saveButton.setEnabled(false);
        cancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
        Toast.makeText(this, "Failed to receive contact.", Toast.LENGTH_SHORT).show();
        Log.d(TAG, "Failed to handle " + uri);
    }
}

From source file:com.android.settings.SettingsLicenseActivity.java

private void showHtmlFromUri(Uri uri) {
    // Kick off external viewer due to WebView security restrictions; we
    // carefully point it at HTMLViewer, since it offers to decompress
    // before viewing.
    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, "text/html");
    intent.putExtra(Intent.EXTRA_TITLE, getString(R.string.settings_license_activity_title));
    if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }/* w w w. j  a  va2  s . c  o  m*/
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setPackage("com.android.htmlviewer");

    try {
        startActivity(intent);
        finish();
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to find viewer", e);
        showErrorAndFinish();
    }
}

From source file:com.takondi.tartt.ARActivity.java

private void processQr(String qrContent) {
    Uri qrUri = Uri.parse(qrContent);
    if (QR_TARTT_SCHEME.equals(qrUri.getScheme()) && QR_CHANNEL_HOST.equals(qrUri.getHost())
            && qrUri.getQueryParameter(Channel.CHANNEL_KEY) != null) {
        //we now might also be receiving a scanned qr/barcode out of an active world, so let's make sure to deactivate the world's AR
        loadDefaultWorld();/*from  w w w  .  j a va 2s.c o m*/

        mGuiHelper.changeGuiState(GUI_STATE.LOADING);
        TarttRequestOptions newConfig = Tartt
                .getInitialConfigForChannel(qrUri.getQueryParameter(Channel.CHANNEL_KEY));
        try {
            if (qrUri.getQueryParameter(Channel.STATE) != null) {
                newConfig.setState(TarttRequestOptions.State
                        .getStateForValue(Integer.valueOf(qrUri.getQueryParameter(Channel.STATE))));
            }
            if (qrUri.getQueryParameter(Channel.TARGET_TYPE) != null) {
                newConfig.setTargetType(
                        TarttRequestOptions.TargetType.valueOf(qrUri.getQueryParameter(Channel.TARGET_TYPE)));
            }
            if (qrUri.getQueryParameter(Channel.ENV_TYPE) != null) {
                newConfig.setEnvType(
                        TarttRequestOptions.EnvironmentType.valueOf(qrUri.getQueryParameter(Channel.ENV_TYPE)));
            }
            if (qrUri.getQueryParameter(Channel.TARGET_API) != null) {
                newConfig.setTargetApi(Integer.valueOf(qrUri.getQueryParameter(Channel.TARGET_API)));
            }
            if (qrUri.getQueryParameter(Channel.LANGUAGE) != null) {
                newConfig.setLanguage(qrUri.getQueryParameter(Channel.LANGUAGE));
            }
        } catch (NumberFormatException eNFE) {
            Log.e(TAG, "QR-Code contained invalid value for parameter (requires a number)");
        } catch (IllegalArgumentException eIAE) {
            Log.e(TAG, "QR-Code contained invalid value for a parameter (not in valid range)");
        }
        mChannelManager.fetchFilesForChannelWithConfig(newConfig, this);
    } else {
        mQrPlugin.activate();
    }
}

From source file:com.entertailion.android.overlaynews.Downloader.java

private synchronized void updateFeeds() {
    Log.d(LOG_TAG, "updateFeeds");
    updateTime = System.currentTimeMillis();
    try {/*from   www .  j av a2s . c  o m*/
        // iterate through feeds in database
        ArrayList<RssFeed> feeds = FeedsTable.getFeeds(context);
        Log.d(LOG_TAG, "feeds=" + feeds);
        if (feeds != null) {
            for (RssFeed feed : feeds) {
                // Check if TTL set for feed
                if (feed.getTtl() != -1) {
                    if (System.currentTimeMillis()
                            - (feed.getDate().getTime() + feed.getTtl() * 60 * 1000) < 0) {
                        // too soon
                        Log.d(LOG_TAG, "TTL not reached: " + feed.getTitle());
                        break;
                    }
                }
                String rss = Utils.getRssFeed(feed.getLink(), context, true);
                RssHandler rh = new RssHandler();
                RssFeed rssFeed = rh.getFeed(rss);
                if (rssFeed.getTitle() == null) {
                    try {
                        Uri uri = Uri.parse(feed.getLink());
                        rssFeed.setTitle(uri.getHost());
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "get host", e);
                    }
                }
                Uri uri = Uri.parse(feed.getLink());
                Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost());
                String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost());
                Log.d(LOG_TAG, "icon1=" + icon);
                if (icon == null) {
                    // try base host address
                    int count = StringUtils.countMatches(uri.getHost(), ".");
                    if (count > 1) {
                        int index = uri.getHost().indexOf('.');
                        String baseHost = uri.getHost().substring(index + 1);
                        icon = Utils.getWebSiteIcon(context, "http://" + baseHost);
                        Log.d(LOG_TAG, "icon2=" + icon);
                    }
                }
                if (icon != null) {
                    try {
                        FileInputStream fis = context.openFileInput(icon);
                        Bitmap bitmap = BitmapFactory.decodeStream(fis);
                        fis.close();
                        rssFeed.setImage(icon);
                        rssFeed.setBitmap(bitmap);
                    } catch (Exception e) {
                        Log.d(LOG_TAG, "updateFeeds", e);
                    }
                }
                if (rssFeed.getBitmap() == null && rssFeed.getLogo() != null) {
                    Log.d(LOG_TAG, "logo=" + rssFeed.getLogo());
                    Bitmap bitmap = Utils.getBitmapFromURL(rssFeed.getLogo());
                    if (bitmap != null) {
                        icon = Utils.WEB_SITE_ICON_PREFIX + Utils.clean(rssFeed.getLogo()) + ".png";
                        Utils.saveToFile(context, bitmap, bitmap.getWidth(), bitmap.getHeight(), icon);
                        rssFeed.setImage(icon);
                        rssFeed.setBitmap(bitmap);
                    }
                }
                // update database
                long time = 0;
                if (rssFeed.getDate() != null) {
                    time = rssFeed.getDate().getTime();
                }
                FeedsTable.updateFeed(context, feed.getId(), rssFeed.getTitle(), feed.getLink(),
                        rssFeed.getDescription(), time, rssFeed.getViewDate().getTime(), rssFeed.getLogo(),
                        rssFeed.getImage(), rssFeed.getTtl());
                ItemsTable.deleteItems(context, feed.getId());
                for (RssItem item : rssFeed.getItems()) {
                    if (item.getTitle() != null) {
                        time = 0;
                        if (item.getDate() != null) {
                            time = item.getDate().getTime();
                        }
                        ItemsTable.insertItem(context, feed.getId(), item.getTitle(), item.getLink(),
                                item.getDescription(), item.getContent(), time);
                    }
                }
                // release resources
                Bitmap bitmap = rssFeed.getBitmap();
                if (bitmap != null) {
                    rssFeed.setBitmap(null);
                    bitmap.recycle();
                    bitmap = null;
                }
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "updateFeeds", e);
    }
}

From source file:mobisocial.musubi.ui.FeedListActivity.java

protected void doHandleInput(Uri uri) {
    if (DBG)//  w  w  w .ja  va2  s  .  c o  m
        Log.d(TAG, "Handling input uri " + uri);
    if (uri == null) {
        return;
    }

    if (uri.getScheme() == null) {
        Log.w(TAG, "Null uri scheme for " + uri);
        return;
    }

    //TODO: if there are URI's that are opened with the FeedListActivity that we want to 
    //handle, e.g. an NFC url, then we put that code here.  We used to have friend invites
    //but now we don't have to worry about that. 

    //If we want to share a URL that opens a specific Musubi feed, then we need to create a 
    //URL that links to it without giving away the secret feed capability.
    if (uri.getScheme().equals("content")) {
        if (uri.getAuthority().equals("vnd.mobisocial.db")) {
            if (uri.getPath().startsWith("/feed")) {
                //                    Intent view = new Intent(Intent.ACTION_VIEW, uri);
                //                    view.addCategory(Intent.CATEGORY_DEFAULT);
                //                    // TODO: fix in AndroidManifest.
                //                    //view.setClass(this, FeedActivity.class);
                //                    view.setClass(this, FeedHomeActivity.class);
                //                    startActivity(view);
                //                    finish();
                //                    return;
            }
        }
    }

    // Re-push the contact info ndef
    pushContactInfoViaNfc();
}

From source file:mobisocial.musubi.util.UriImage.java

public UriImage(Context context, Uri uri) {
    if ((null == context) || (null == uri)) {
        throw new IllegalArgumentException();
    }/*from  w w w .  j  a v  a 2  s  . com*/

    mRotation = PhotoTaker.rotationForImage(context, uri);
    String scheme = uri.getScheme();
    if (scheme.equals("content")) {
        try {
            initFromContentUri(context, uri);
        } catch (Exception e) {
            Log.w(TAG, "last-ditch image params");
            mPath = uri.getPath();
            mContentType = context.getContentResolver().getType(uri);
        }
    } else if (uri.getScheme().equals("file")) {
        initFromFile(context, uri);
    } else {
        mPath = uri.getPath();
    }

    mSrc = mPath.substring(mPath.lastIndexOf('/') + 1);

    if (mSrc.startsWith(".") && mSrc.length() > 1) {
        mSrc = mSrc.substring(1);
    }

    // Some MMSCs appear to have problems with filenames
    // containing a space.  So just replace them with
    // underscores in the name, which is typically not
    // visible to the user anyway.
    mSrc = mSrc.replace(' ', '_');

    mContext = context;
    mUri = uri;
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display dialog to the user for the browser bookmarks. Allow the user to add a
 * browser bookmark to an existing row or a new row.
 * /*from   w  w  w  .  j  a  va 2s . co m*/
 * @param context
 */
public static void displayAddBrowserBookmark(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.add_browser_bookmarks_list);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
        }

    });

    ListView listView = (ListView) dialog.findViewById(R.id.list);
    final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context);
    Collections.sort(bookmarks, new Comparator<BookmarkInfo>() {

        @Override
        public int compare(BookmarkInfo lhs, BookmarkInfo rhs) {
            return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase());
        }

    });
    listView.setAdapter(new BookmarkAdapter(context, bookmarks));
    listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            // run in thread since network logic needed to get bookmark icon
            new Thread(new Runnable() {
                public void run() {
                    // if the new row radio button is selected, the user must enter
                    // a name for the new row
                    String name = nameEditText.getText().toString().trim();
                    if (newRadioButton.isChecked() && name.length() == 0) {
                        nameEditText.requestFocus();
                        displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                        return;
                    }
                    boolean currentRow = !newRadioButton.isChecked();
                    try {
                        BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position);
                        int rowId = 0;
                        int rowPosition = 0;
                        if (currentRow) {
                            rowId = context.getCurrentGalleryId();
                            ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId);
                            rowPosition = items.size(); // in last
                            // position
                            // for selected
                            // row
                        } else {
                            rowId = (int) RowsTable.insertRow(context, name, 0, RowInfo.FAVORITE_TYPE);
                            rowPosition = 0;
                        }
                        Intent intent = new Intent(Intent.ACTION_VIEW);
                        intent.setData(Uri.parse(bookmark.getUrl()));

                        Uri uri = Uri.parse(bookmark.getUrl());
                        Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost());
                        String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost());
                        Log.d(LOG_TAG, "icon1=" + icon);
                        if (icon == null) {
                            // try base host address
                            int count = StringUtils.countMatches(uri.getHost(), ".");
                            if (count > 1) {
                                int index = uri.getHost().indexOf('.');
                                String baseHost = uri.getHost().substring(index + 1);
                                icon = Utils.getWebSiteIcon(context, "http://" + baseHost);
                                Log.d(LOG_TAG, "icon2=" + icon);
                            }
                        }

                        ItemsTable.insertItem(context, rowId, rowPosition, bookmark.getTitle(), intent, icon,
                                DatabaseHelper.SHORTCUT_TYPE);
                    } catch (Exception e) {
                        Log.e(LOG_TAG, "displayAddBrowserBookmark", e);
                    }

                    // need to do this on UI thread
                    context.getHandler().post(new Runnable() {
                        public void run() {
                            context.showCover(false);
                            dialog.dismiss();
                            context.reloadAllGalleries();
                        }
                    });

                    if (currentRow) {
                        Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK);
                    } else {
                        Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK_WITH_ROW);
                    }

                }
            }).start();
        }
    });
    listView.setDrawingCacheEnabled(true);
    listView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ADD_BROWSER_BOOKMARK);
}

From source file:com.vuze.android.remote.activity.IntentHandler.java

private boolean handleIntent(Intent intent, Bundle savedInstanceState) {
    boolean forceProfileListOpen = (intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_TOP) > 0;

    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "ForceOpen? " + forceProfileListOpen);
        Log.d(TAG, "IntentHandler intent = " + intent);
    }//w  w  w .  j a v a 2 s. c  o  m

    appPreferences = VuzeRemoteApp.getAppPreferences();

    Uri data = intent.getData();
    if (data != null) {
        try {
            // check for vuze://remote//*
            String scheme = data.getScheme();
            String host = data.getHost();
            String path = data.getPath();
            if ("vuze".equals(scheme) && "remote".equals(host) && path != null && path.length() > 1) {
                String ac = path.substring(1);
                if (AndroidUtils.DEBUG) {
                    Log.d(TAG, "got ac '" + ac + "' from " + data);
                }

                intent.setData(null);
                if (ac.equals("cmd=advlogin")) {
                    DialogFragmentGenericRemoteProfile dlg = new DialogFragmentGenericRemoteProfile();
                    AndroidUtils.showDialog(dlg, getSupportFragmentManager(), "GenericRemoteProfile");
                    forceProfileListOpen = true;
                } else if (ac.length() < 100) {
                    RemoteProfile remoteProfile = new RemoteProfile("vuze", ac);
                    new RemoteUtils(this).openRemote(remoteProfile, true);
                    finish();
                    return true;
                }
            }

            // check for http[s]://remote.vuze.com/ac=*
            if (host != null && host.equals("remote.vuze.com") && data.getQueryParameter("ac") != null) {
                String ac = data.getQueryParameter("ac");
                if (AndroidUtils.DEBUG) {
                    Log.d(TAG, "got ac '" + ac + "' from " + data);
                }
                intent.setData(null);
                if (ac.length() < 100) {
                    RemoteProfile remoteProfile = new RemoteProfile("vuze", ac);
                    new RemoteUtils(this).openRemote(remoteProfile, true);
                    finish();
                    return true;
                }
            }
        } catch (Exception e) {
            if (AndroidUtils.DEBUG) {
                e.printStackTrace();
            }
        }
    }

    if (!forceProfileListOpen) {
        int numRemotes = getRemotesWithLocal().length;
        if (numRemotes == 0) {
            // New User: Send them to Login (Account Creation)
            Intent myIntent = new Intent(Intent.ACTION_VIEW, null, this, LoginActivity.class);
            myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);

            startActivity(myIntent);
            finish();
            return true;
        } else if (numRemotes == 1 || intent.getData() == null) {
            try {
                RemoteProfile remoteProfile = appPreferences.getLastUsedRemote();
                if (remoteProfile != null) {
                    if (savedInstanceState == null) {
                        new RemoteUtils(this).openRemote(remoteProfile, true);
                        finish();
                        return true;
                    }
                } else {
                    Log.d(TAG, "Has Remotes, but no last remote");
                }
            } catch (Throwable t) {
                if (AndroidUtils.DEBUG) {
                    Log.e(TAG, "onCreate", t);
                }
                VuzeEasyTracker.getInstance(this).logError(t);
            }
        }
    }
    return false;
}