Example usage for android.net Uri getAuthority

List of usage examples for android.net Uri getAuthority

Introduction

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

Prototype

@Nullable
public abstract String getAuthority();

Source Link

Document

Gets the decoded authority part of this URI.

Usage

From source file:ir.keloud.android.lib.test_project.test.KeloudClientTest.java

public void testGetWebdavUri() {
    KeloudClient client = new KeloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
    client.setCredentials(KeloudCredentialsFactory.newBearerCredentials("fakeToken"));
    Uri webdavUri = client.getWebdavUri();
    assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + "authenticated servers",
            webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH));
    assertTrue("WebDAV URI is not a subpath of base URI",
            webdavUri.getAuthority().equals(mServerUri.getAuthority())
                    && webdavUri.getPath().startsWith(mServerUri.getPath()));

    client.setCredentials(KeloudCredentialsFactory.newBasicCredentials(mUsername, mPassword));
    webdavUri = client.getWebdavUri();//from  www  . j a  v a2s  .co  m
    assertTrue("WebDAV URI does not point to the right entry point",
            webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0));
    PropFindMethod propfind = null;
    try {
        propfind = new PropFindMethod(webdavUri + "/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0);
        int status = client.executeMethod(propfind);
        assertEquals("WebDAV request did not work on WebDAV URI", HttpStatus.SC_MULTI_STATUS, status);

    } catch (IOException e) {
        Log.e(TAG, "Exception in PROPFIND method execution", e);
        // TODO - make it fail? ; try several times, and make it fail if none
        //         is right?

    } finally {
        propfind.releaseConnection();
    }

}

From source file:com.activiti.android.app.fragments.account.AccountEditFragment.java

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

    if (getArguments() != null) {
        accountId = getArguments().getLong(ARGUMENT_ACCOUNT_ID);
    }/*from w w  w. j  a v  a2  s  . c  o  m*/
    acc = ActivitiAccountManager.getInstance(getActivity()).getByAccountId(accountId);
    Uri serverUri = Uri.parse(acc.getServerUrl());

    if (serverUri.getPath().equals("/activiti-app")) {
        // It's default url
        https = ("https".equals(serverUri.getScheme().toLowerCase()));
        hostname = serverUri.getAuthority();
    } else {
        // It's not default we display full url in hostname
        hostname = acc.getServerUrl();
        hide(R.id.signing_https);
    }

    // TITLE
    TextView tv = (TextView) viewById(R.id.signin_title);
    tv.setText(R.string.settings_userinfo_account_summary);

    // USERNAME
    mEmailView = (MaterialAutoCompleteTextView) viewById(R.id.username);
    Account[] accounts = AccountManager.get(getActivity()).getAccounts();
    List<String> names = new ArrayList<>(accounts.length);
    String accountName;
    for (int i = 0; i < accounts.length; i++) {
        accountName = accounts[i].name;
        if (!TextUtils.isEmpty(accountName) && !names.contains(accountName)) {
            names.add(accounts[i].name);
        }
    }
    ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, names);
    mEmailView.setAdapter(adapter);
    mEmailView.setText(acc.getUsername());

    // PASSWORD
    mPasswordView = (EditText) viewById(R.id.password);
    mPasswordView.setText(acc.getPassword());

    Button mEmailSignInButton = (Button) viewById(R.id.email_sign_in_button);
    mEmailSignInButton.setText(R.string.general_action_confirm);
    mEmailSignInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });

    mProgressView = viewById(R.id.login_progress);
    mFormView = viewById(R.id.login_form);

    // Server part
    httpsView = (CheckBox) viewById(R.id.signing_https);
    httpsView.setChecked(https);
    hostnameView = (MaterialEditText) viewById(R.id.signing_hostname);
    hostnameView.setText(hostname);

    show(R.id.server_form);
}

From source file:com.benefit.buy.library.http.query.callback.AbstractAjaxCallback.java

private static String extractUrl(Uri uri) {
    String result = uri.getScheme() + "://" + uri.getAuthority() + uri.getPath();
    String fragment = uri.getFragment();
    if (fragment != null) {
        result += "#" + fragment;
    }/*from   ww w . j a  v a 2 s . c  o m*/
    return result;
}

From source file:com.example.rapha.transpotsystem.RegisterActivity.java

@TargetApi(19)
private void handleImageOnKitKat(int requestCode, Intent data) {
    String imagePath = null;/*from w  ww .j a va  2  s .c o m*/
    Uri uri = data.getData();
    if (DocumentsContract.isDocumentUri(this, uri)) {
        String docId = DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
            String id = docId.split(":")[1];
            String selection = MediaStore.Images.Media._ID + "=" + id;
            imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
        } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(docId));
            imagePath = getImagePath(contentUri, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        imagePath = getImagePath(uri, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        imagePath = uri.getPath();
    }
    displayImage(requestCode, imagePath);

}

From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java

private void displayIntent(Intent intent) {
    final String queryAction = intent.getAction();
    final String orderby = Tracks.CREATION_TIME + " DESC";
    Cursor tracksCursor = null;//  w  w  w. ja v a 2  s. c  o  m
    if (Intent.ACTION_SEARCH.equals(queryAction)) {
        // Got to SEARCH a query for tracks, make a list
        tracksCursor = doSearchWithIntent(intent);
    } else if (Intent.ACTION_VIEW.equals(queryAction)) {
        final Uri uri = intent.getData();
        if ("content".equals(uri.getScheme()) && GPStracking.AUTHORITY.equals(uri.getAuthority())) {
            // Got to VIEW a single track, instead hand it of to the LoggerMap
            Intent notificationIntent = new Intent(this, LoggerMap.class);
            notificationIntent.setData(uri);
            startActivity(notificationIntent);
            finish();
        } else if (uri.getScheme().equals("file") || uri.getScheme().equals("content")) {

            mImportTrackName = uri.getLastPathSegment();
            // Got to VIEW a GPX filename
            mImportAction = new Runnable() {
                @Override
                public void run() {
                    new GpxParser(TrackList.this, TrackList.this).execute(uri);
                }
            };
            showDialog(DIALOG_IMPORT);
            tracksCursor = managedQuery(Tracks.CONTENT_URI,
                    new String[] { Tracks._ID, Tracks.NAME, Tracks.CREATION_TIME }, null, null, orderby);
        } else {
            Log.e(this, "Unable to VIEW " + uri);
        }
    } else {
        // Got to nothing, make a list of everything
        tracksCursor = managedQuery(Tracks.CONTENT_URI,
                new String[] { Tracks._ID, Tracks.NAME, Tracks.CREATION_TIME }, null, null, orderby);
    }
    displayCursor(tracksCursor);

}

From source file:mobisocial.musubi.objects.WebAppObj.java

String getAppName(Obj obj) {
    Uri appUri = Uri.parse(obj.getJson().optString(OBJ_URL));
    String given = appUri.getQueryParameter("n");
    if (given == null) {
        given = appUri.getLastPathSegment();
        if (given == null || given.length() <= 1 || given.startsWith("index")) {
            List<String> segs = appUri.getPathSegments();
            if (segs.size() > 1) {
                given = segs.get(segs.size() - 2);
            } else {
                given = appUri.getAuthority();
            }//from w  w  w  .j  av  a 2 s . c  o m
        }
    }
    return given;
}

From source file:com.anhubo.anhubo.ui.activity.unitDetial.UploadingActivity1.java

@TargetApi(19)
private Bitmap handleImageOnKitKat(Intent data) {
    String imagePath = null;/* w ww. j a va2 s .c  om*/
    Uri uri = data.getData();
    Log.d("TAG", "handleImageOnKitKat: uri is " + uri);
    if (DocumentsContract.isDocumentUri(this, uri)) {
        // documentUridocument id?
        String docId = DocumentsContract.getDocumentId(uri);
        if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
            String id = docId.split(":")[1]; // ??id
            String selection = MediaStore.Images.Media._ID + "=" + id;
            imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
        } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(docId));
            imagePath = getImagePath(contentUri, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        // contentUri??
        imagePath = getImagePath(uri, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        // fileUri???
        imagePath = uri.getPath();
    }
    Bitmap bitmap = displayImage(imagePath);// ?
    return bitmap;
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SuggestionsAdapter.java

public Drawable getTheDrawable(Uri uri) throws FileNotFoundException {
    String authority = uri.getAuthority();
    Resources r;// w w  w  . ja  va2s  . c o  m
    if (TextUtils.isEmpty(authority)) {
        throw new FileNotFoundException("No authority: " + uri);
    } else {
        try {
            r = mContext.getPackageManager().getResourcesForApplication(authority);
        } catch (NameNotFoundException ex) {
            throw new FileNotFoundException("No package found for authority: " + uri);
        }
    }
    List<String> path = uri.getPathSegments();
    if (path == null) {
        throw new FileNotFoundException("No path: " + uri);
    }
    int len = path.size();
    int id;
    if (len == 1) {
        try {
            id = Integer.parseInt(path.get(0));
        } catch (NumberFormatException e) {
            throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
        }
    } else if (len == 2) {
        id = r.getIdentifier(path.get(1), path.get(0), authority);
    } else {
        throw new FileNotFoundException("More than two path segments: " + uri);
    }
    if (id == 0) {
        throw new FileNotFoundException("No resource found for: " + uri);
    }
    return r.getDrawable(id);
}

From source file:com.wiret.arbrowser.AbstractArchitectCamActivity.java

private boolean isExternalStorageDocument(Uri uri) {
    return "com.android.externalstorage.documents".equals(uri.getAuthority());
}