Example #1
1
  // build query
  @Override
  protected String buildQueryUrl(RequestParams params) {
    String uri = params.getUri();
    StringBuilder queryBuilder = new StringBuilder(uri);
    if (!uri.contains("?")) {
      queryBuilder.append("?");
    } else if (!uri.endsWith("?")) {
      queryBuilder.append("&");
    }
    HashMap<String, String> queryParams = params.getQueryStringParams();
    if (queryParams != null) {
      for (Map.Entry<String, String> entry : queryParams.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) {
          queryBuilder.append(Uri.encode(name)).append("=").append(Uri.encode(value)).append("&");
        }
      }
      if (queryBuilder.charAt(queryBuilder.length() - 1) == '&') {
        queryBuilder.deleteCharAt(queryBuilder.length() - 1);
      }
    }

    if (queryBuilder.charAt(queryBuilder.length() - 1) == '?') {
      queryBuilder.deleteCharAt(queryBuilder.length() - 1);
    }
    return queryBuilder.toString();
  }
  private String getSignatureBaseString(HttpPost req, OAuthParameters params) {
    final String method = req.getMethod();
    final String url = Uri.encode(req.getURI().toString());

    final String sortedParams = Uri.encode(params.getSortedEncodedParamsAsString());
    return method + '&' + url + '&' + sortedParams;
  }
 public static URI getAuthorizationUrl(
     URI loginServer,
     String clientId,
     String callbackUrl,
     String[] scopes,
     String clientSecret,
     String displayType) {
   if (displayType == null) displayType = "touch";
   final StringBuilder sb = new StringBuilder(loginServer.toString());
   sb.append(OAUTH_AUTH_PATH);
   sb.append(displayType);
   if (clientSecret != null) {
     sb.append("&").append(RESPONSE_TYPE).append("=").append(ACTIVATED_CLIENT_CODE);
   } else {
     sb.append("&").append(RESPONSE_TYPE).append("=").append(TOKEN);
   }
   sb.append("&").append(CLIENT_ID).append("=").append(Uri.encode(clientId));
   if ((null != scopes) && (scopes.length > 0)) {
     // need to always have the refresh_token scope to reuse our refresh token
     sb.append("&").append(SCOPE).append("=").append(REFRESH_TOKEN);
     StringBuilder scopeStr = new StringBuilder();
     for (String scope : scopes) {
       if (!scope.equalsIgnoreCase(REFRESH_TOKEN)) {
         scopeStr.append(" ").append(scope);
       }
     }
     String safeScopeStr = Uri.encode(scopeStr.toString());
     sb.append(safeScopeStr);
   }
   sb.append("&redirect_uri=");
   sb.append(callbackUrl);
   return URI.create(sb.toString());
 }
Example #4
0
  /** @return URI identifying this HostBean */
  public Uri getUri() {
    StringBuilder sb = new StringBuilder();
    sb.append(protocol).append("://");

    if (username != null) sb.append(Uri.encode(username)).append('@');

    sb.append(Uri.encode(hostname)).append(':').append(port).append("/#").append(nickname);
    return Uri.parse(sb.toString());
  }
 public static ParseRESTObjectCommand deleteObjectCommand(
     ParseObject.State state, String sessionToken) {
   String httpPath = String.format("classes/%s", Uri.encode(state.className()));
   String objectId = state.objectId();
   if (objectId != null) {
     httpPath += String.format("/%s", Uri.encode(objectId));
   }
   return new ParseRESTObjectCommand(httpPath, Method.DELETE, null, sessionToken);
 }
Example #6
0
  @Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.image:
        startActivityForResult(
            new Intent(
                Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI),
            0);
        break;

      case R.id.cancel:
        finish();
        break;

      case R.id.add:
        // Get the fields
        String issuer = Uri.encode(mIssuer.getText().toString());
        String label = Uri.encode(mLabel.getText().toString());
        String secret = Uri.encode(mSecret.getText().toString());
        String algorithm = mAlgorithm.getSelectedItem().toString().toLowerCase(Locale.US);
        int interval = Integer.parseInt(mInterval.getText().toString());
        int digits = ((RadioButton) findViewById(R.id.digits6)).isChecked() ? 6 : 8;

        // Create the URI
        String uri =
            String.format(
                Locale.US,
                "otpauth://%sotp/%s:%s?secret=%s&algorithm=%s&digits=%d&period=%d",
                mHOTP.isChecked() ? "h" : "t",
                issuer,
                label,
                secret,
                algorithm,
                digits,
                interval);

        // Add optional parameters.
        if (mHOTP.isChecked()) {
          int counter = Integer.parseInt(mCounter.getText().toString());
          uri = uri.concat(String.format("&counter=%d", counter));
        }
        if (mImageURL != null) {
          try {
            String enc = URLEncoder.encode(mImageURL.toString(), "utf-8");
            uri = uri.concat(String.format("&image=%s", enc));
          } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
          }
        }

        // Add the token
        if (TokenPersistence.addWithToast(this, uri) != null) finish();

        break;
    }
  }
  public void sendEmail(View view) {
    Intent send = new Intent(Intent.ACTION_SENDTO);
    String uriText =
        "mailto:"
            + Uri.encode("*****@*****.**")
            + "?subject="
            + Uri.encode("Kids World Animals Jungle")
            + "&body="
            + Uri.encode("Hi!...");
    Uri uri = Uri.parse(uriText);

    send.setData(uri);
    startActivity(Intent.createChooser(send, "Send mail..."));
  }
  private static String buildSubscriptionCodeQuery(Context context, String code, String fileName) {

    StringBuilder query = new StringBuilder(LibrelioApplication.getServerUrl(context));

    String command =
        context
            .getString(R.string.command_pswd)
            .replace(PARAM_CODE, Uri.encode(code))
            .replace(PARAM_URLSTRING, Uri.encode(LibrelioApplication.getUrlString(fileName)))
            .replace(PARAM_CLIENT, Uri.encode(LibrelioApplication.getClientName(context)))
            .replace(PARAM_APP, Uri.encode(LibrelioApplication.getMagazineName(context)))
            .replace(PARAM_DEVICEID, LibrelioApplication.getAndroidId(context));

    return query.append(command).toString();
  }
  /** Factory method to start query with a number */
  public static CallerInfoAsyncQuery startQuery(
      int token, Context context, String number, OnQueryCompleteListener listener, Object cookie) {
    // contruct the URI object and start Query.
    Uri contactRef = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

    CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
    c.allocate(context, contactRef);

    if (DBG) log("starting query for number: " + number + " handler: " + c.toString());

    // create cookieWrapper, start query
    CookieWrapper cw = new CookieWrapper();
    cw.listener = listener;
    cw.cookie = cookie;
    cw.number = number;

    // check to see if these are recognized numbers, and use shortcuts if we can.
    if (PhoneNumberUtils.isEmergencyNumber(number)) {
      cw.event = EVENT_EMERGENCY_NUMBER;
    } else if (PhoneNumberUtils.isVoiceMailNumber(number)) {
      cw.event = EVENT_VOICEMAIL_NUMBER;
    } else {
      cw.event = EVENT_NEW_QUERY;
    }

    c.mHandler.startQuery(token, cw, contactRef, null, null, null, null);

    return c;
  }
Example #10
0
  private String generateAdUrl() {
    StringBuilder sz = new StringBuilder("http://" + MoPubView.HOST + MoPubView.AD_HANDLER);
    sz.append("?v=4&id=" + mAdUnitId);

    String udid = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
    String udidDigest = (udid == null) ? "" : sha1(udid);
    sz.append("&udid=sha:" + udidDigest);

    if (mKeywords != null) sz.append("&q=" + Uri.encode(mKeywords));

    if (mLocation != null) {
      sz.append("&ll=" + mLocation.getLatitude() + "," + mLocation.getLongitude());
    }

    sz.append("&z=" + getTimeZoneOffsetString());

    int orientation = getResources().getConfiguration().orientation;
    String orString = DEVICE_ORIENTATION_UNKNOWN;
    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
      orString = DEVICE_ORIENTATION_PORTRAIT;
    } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
      orString = DEVICE_ORIENTATION_LANDSCAPE;
    } else if (orientation == Configuration.ORIENTATION_SQUARE) {
      orString = DEVICE_ORIENTATION_SQUARE;
    }
    sz.append("&o=" + orString);

    DisplayMetrics metrics = new DisplayMetrics();
    Activity activity = (Activity) getContext();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    sz.append("&sc_a=" + metrics.density);

    return sz.toString();
  }
Example #11
0
  /**
   * Common method for performing a query of the music database, called for both top-level queries
   * and filtering.
   *
   * @param sync If true, this query should be done synchronously and the resulting cursor returned.
   *     If false, it will be done asynchronously and null returned.
   * @param filterstring If non-null, this is a filter to apply to the query.
   */
  Cursor doQuery(boolean sync, String filterstring) {
    // Cancel any pending queries
    mQueryHandler.cancelOperation(MY_QUERY_TOKEN);

    StringBuilder where = new StringBuilder();
    where.append(MediaStore.Audio.Media.TITLE + " != ''");

    // We want to show all audio files, even recordings.  Enforcing the
    // following condition would hide recordings.
    // where.append(" AND " + MediaStore.Audio.Media.IS_MUSIC + "=1");

    Uri uri = mBaseUri;
    if (!TextUtils.isEmpty(filterstring)) {
      uri = uri.buildUpon().appendQueryParameter("filter", Uri.encode(filterstring)).build();
    }

    if (sync) {
      try {
        return getContentResolver().query(uri, CURSOR_COLS, where.toString(), null, mSortOrder);
      } catch (UnsupportedOperationException ex) {
      }
    } else {
      mAdapter.setLoading(true);
      setProgressBarIndeterminateVisibility(true);
      mQueryHandler.startQuery(
          MY_QUERY_TOKEN, null, uri, CURSOR_COLS, where.toString(), null, mSortOrder);
    }
    return null;
  }
  /**
   * Get all contacts for a given number
   *
   * @param number
   * @return All contacts with that number.
   */
  public Collection<Contact> contactsByNumber(String number) {
    if (!contactsReadModuleInstalled()) return null;

    number = ContactNumber.cleanNumber(number);
    if (!ContactNumber.isNumber(number)) return null;

    Uri uri = Uri.withAppendedPath(MAXS_PHONE_LOOKUP_CONTENT_FILTER_URI, Uri.encode(number));
    final String[] projection = new String[] {PhoneLookup.LOOKUP_KEY, DISPLAY_NAME};
    Cursor c = mContentResolver.query(uri, projection, null, null, null);

    Map<String, Contact> contactMap = new HashMap<String, Contact>();
    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
      String displayName = c.getString(c.getColumnIndexOrThrow(DISPLAY_NAME));
      String lookupKey = c.getString(c.getColumnIndexOrThrow(PhoneLookup.LOOKUP_KEY));

      Contact contact = contactMap.get(lookupKey);
      if (contact == null) {
        contact = new Contact(displayName, lookupKey);
        contactMap.put(lookupKey, contact);
        lookupContactNumbersFor(contact);
      }
    }
    c.close();

    return contactMap.values();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Find contact by given number
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode("xxxxxxxxx"));
    String[] projection =
        new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup.NUMBER, PhoneLookup.NORMALIZED_NUMBER};
    Cursor c = getContentResolver().query(uri, projection, null, null, null);
    if (c.moveToFirst()) { // while(c.moveToNext()){
      // get display name
      String name = c.getString(c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
      // get number assigned by user to given contact
      String number = c.getString(c.getColumnIndexOrThrow(PhoneLookup.NUMBER));
      // get normalized E164 number
      String normalized = c.getString(c.getColumnIndexOrThrow(PhoneLookup.NORMALIZED_NUMBER));
      Toast.makeText(
              getApplicationContext(),
              "Name: " + name + "Number: " + number + "; normalized: " + normalized,
              Toast.LENGTH_LONG)
          .show();
    }
    c.close();
  }
Example #14
0
 private ContactInfo getContactInfoFromEmailUri(Uri emailLookupUri, String email) {
   Uri uri = Uri.withAppendedPath(emailLookupUri, Uri.encode(email));
   Cursor cursor =
       mResolver.query(
           uri,
           new String[] {
             Email.CONTACT_ID,
             Email.DISPLAY_NAME_PRIMARY,
             Email.PHOTO_URI,
             Email.PHOTO_ID,
             Email.PHOTO_THUMBNAIL_URI,
           },
           null,
           null,
           null);
   if (cursor == null) {
     return null;
   }
   ContactInfo result = null;
   if (cursor.moveToFirst()) {
     result =
         new ContactInfo(
             cursor.getString(cursor.getColumnIndexOrThrow(Email.CONTACT_ID)),
             cursor.getString(cursor.getColumnIndexOrThrow(Email.DISPLAY_NAME_PRIMARY)),
             cursor.getString(cursor.getColumnIndexOrThrow(Email.PHOTO_URI)),
             cursor.getString(cursor.getColumnIndexOrThrow(Email.PHOTO_THUMBNAIL_URI)),
             cursor.getString(cursor.getColumnIndexOrThrow(Email.PHOTO_ID)));
   }
   cursor.close();
   return result;
 }
  private String getContactDisplayNameByNumber(String number) {
    Uri uri =
        Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    String name = number;

    if (number == null || number.equals("")) {
      return name;
    }

    ContentResolver contentResolver = getContentResolver();
    Cursor contactLookup = contentResolver.query(uri, null, null, null, null);

    try {
      if (contactLookup != null && contactLookup.getCount() > 0) {
        contactLookup.moveToNext();
        name =
            contactLookup.getString(
                contactLookup.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
      }
    } finally {
      if (contactLookup != null) {
        contactLookup.close();
      }
    }

    return name;
  }
Example #16
0
 protected boolean onLogin(boolean paramBoolean)
 {
   if (paramBoolean)
   {
     Object localObject;
     switch (this.loginFlag)
     {
     default:
       localObject = new Intent("android.intent.action.VIEW", Uri.parse("dianping://mopaylist"));
       ((Intent)localObject).setFlags(67108864);
       startActivity((Intent)localObject);
     case 10:
     case 20:
     }
     while (true)
     {
       return true;
       localObject = Uri.encode("http://m.dianping.com/hui/ticket/usabletickets?dpshare=0&token=" + accountService().token());
       startActivity(new Intent("android.intent.action.VIEW", Uri.parse("dianping://web?url=" + (String)localObject)));
       if (this.header != null)
         this.listView.removeHeaderView(this.header);
       this.adapter.reset();
       loadNewPage();
       continue;
       localObject = new Intent("android.intent.action.VIEW", Uri.parse("dianping://mopaylist"));
       ((Intent)localObject).setFlags(67108864);
       startActivity((Intent)localObject);
     }
   }
   return false;
 }
Example #17
0
  /**
   * Get the saved contact name related to the number from the phonebook
   *
   * @param number
   * @return
   */
  public String getContactByNbr(String number) {
    String contact = "";

    Uri uri =
        Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    ContentResolver contentResolver = getContentResolver();
    Cursor cursor =
        contentResolver.query(
            uri,
            new String[] {BaseColumns._ID, ContactsContract.PhoneLookup.DISPLAY_NAME},
            null,
            null,
            null);

    if (cursor != null && cursor.getCount() > 0) {
      try {
        cursor.moveToNext();
        contact = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
      } catch (Exception e) {

      } finally {
        cursor.close();
      }
    }
    if (contact.length() == 0) return number;
    return contact;
  }
Example #18
0
 // ID is name>number
 public static String numberToID(String phoneNumber, Context context) {
   try {
     ContentResolver localContentResolver = context.getContentResolver();
     Cursor contactLookupCursor =
         localContentResolver.query(
             Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)),
             new String[] {PhoneLookup.DISPLAY_NAME, BaseColumns._ID},
             null,
             null,
             null);
     try {
       while (contactLookupCursor.moveToNext()) {
         String contactName =
             contactLookupCursor.getString(
                 contactLookupCursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME));
         return contactName;
       }
     } finally {
       contactLookupCursor.close();
     }
     String spacedNumber = "";
     for (char c : phoneNumber.toCharArray()) {
       spacedNumber += c + " ";
     }
     return spacedNumber;
   } catch (Exception e) {
     return "Unknown Number";
   }
 }
Example #19
0
  /**
   * getCallerInfo given a phone number and subscription, look up in the call-log database for the
   * matching caller id info.
   *
   * @param context the context used to get the ContentResolver
   * @param number the phone number used to lookup caller id
   * @param subId the subscription for checking for if voice mail number or not
   * @return the CallerInfo which contains the caller id for the given number. The returned
   *     CallerInfo is null if no number is supplied. If a matching number is not found, then a
   *     generic caller info is returned, with all relevant fields empty or null.
   */
  public static CallerInfo getCallerInfo(Context context, String number, int subId) {

    if (TextUtils.isEmpty(number)) {
      return null;
    }

    // Change the callerInfo number ONLY if it is an emergency number
    // or if it is the voicemail number.  If it is either, take a
    // shortcut and skip the query.
    if (PhoneNumberUtils.isLocalEmergencyNumber(context, number)) {
      return new CallerInfo().markAsEmergency(context);
    } else if (PhoneNumberUtils.isVoiceMailNumber(subId, number)) {
      return new CallerInfo().markAsVoiceMail();
    }

    Uri contactUri =
        Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(number));

    CallerInfo info = getCallerInfo(context, contactUri);
    info = doSecondaryLookupIfNecessary(context, number, info);

    // if no query results were returned with a viable number,
    // fill in the original number value we used to query with.
    if (TextUtils.isEmpty(info.phoneNumber)) {
      info.phoneNumber = number;
    }

    return info;
  }
Example #20
0
  private String buildVerifyQuery(String dataResponse, String signatureResponse) {

    StringBuilder query = new StringBuilder(LibrelioApplication.getServerUrl(getContext()));

    String command =
        getString(R.string.command_android_verify)
            .replace(";", "&")
            .replace(PARAM_PRODUCT_ID, Uri.encode(productId))
            .replace(PARAM_DATA, Uri.encode(dataResponse))
            .replace(PARAM_SIGNATURE, Uri.encode(signatureResponse))
            .replace(
                PARAM_URLSTRING,
                Uri.encode(LibrelioApplication.getUrlString(getContext(), fileName)));

    return query.append(command).toString();
  }
Example #21
0
  /**
   * 对url参数的value进行utf-8编码.
   *
   * @param str Url.
   * @return Url.
   */
  private static String urlEncode(String str) {
    if (TextUtils.isEmpty(str)) {
      return "";
    }
    StringBuffer sb = new StringBuffer(str.length() * 2);
    String[] pairs = str.split("&");
    int size = pairs.length;
    String pair;
    for (int i = 0; i < size; i++) {
      pair = pairs[i];
      int idx = pair.indexOf("=");
      if (idx > 0 && pair.indexOf("%") < 0) {
        String value = pair.substring(idx + 1);
        sb.append(pair.substring(0, idx));
        sb.append('=');
        sb.append(Uri.encode(value));
      } else {
        sb.append(pair);
      }
      if (i < size - 1) {
        sb.append('&');
      }
    }

    return sb.toString().trim();
  }
Example #22
0
      private Data get_lookup(Context context, String Number) {
        Cursor c = null;
        try {
          Uri lookupUri =
              Uri.withAppendedPath(
                  ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(Number));
          c =
              context
                  .getContentResolver()
                  .query(
                      lookupUri,
                      new String[] {
                        ContactsContract.Data.DISPLAY_NAME, ContactsContract.Data.PHOTO_URI
                      },
                      null,
                      null,
                      null);

          if (c.moveToFirst()) {
            if (c.getString(0) != null) {
              return new Data(c.getString(1), c.getString(0));
            }
          } else {
            return new Data(null, null);
          }

        } catch (Exception e) {
          e.getMessage();
        } finally {
          c.close();
        }
        return null;
      }
Example #23
0
 @Override
 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
   final String personPhone = getPersonPhone();
   String sortOrder = SQL_SORT_DEFAULT;
   String selection = null;
   String[] selectionArgs = null;
   Uri searchPhoneUri = null;
   if (isPhoneExactMatch(personPhone)) {
     searchPhoneUri = GeoTrackerProvider.Constants.CONTENT_URI;
     selection =
         String.format(
             "%s = ? and %2$s >= ? and %2$s < ?",
             GeoTrackColumns.COL_PHONE, GeoTrackColumns.COL_TIME);
     selectionArgs =
         new String[] {
           getPersonPhone(), String.valueOf(timeBeginInMs), String.valueOf(timeEndInMs)
         };
     Log.d(
         TAG,
         String.format(
             "Sql request : %s / for param : user [%s] with date range(%s, %s)",
             selection, selectionArgs[0], selectionArgs[1], selectionArgs[2]));
   } else {
     selection = String.format("%1$s >= ? and %1$s < ?", GeoTrackColumns.COL_TIME);
     selectionArgs =
         new String[] {String.valueOf(timeBeginInMs), String.valueOf(timeEndInMs)};
     searchPhoneUri =
         Uri.withAppendedPath(
             GeoTrackerProvider.Constants.CONTENT_URI_PHONE_FILTER, Uri.encode(personPhone));
   }
   // Loader
   CursorLoader cursorLoader =
       new CursorLoader(context, searchPhoneUri, null, selection, selectionArgs, sortOrder);
   return cursorLoader;
 }
Example #24
0
 private Uri lookupContact(String phone) {
   Cursor c = null;
   try {
     Uri phoneUri =
         Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
     String[] projection =
         new String[] {ContactsContract.Contacts._ID, ContactsContract.Contacts.LOOKUP_KEY};
     c = mContext.getContentResolver().query(phoneUri, projection, null, null, null);
     if (c != null && c.getCount() > 0) {
       c.moveToFirst();
       int lookupIdx = c.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY);
       int idIdx = c.getColumnIndex(ContactsContract.Contacts._ID);
       String lookupKey = c.getString(lookupIdx);
       long contactId = c.getLong(idIdx);
       return ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
     }
   } catch (Throwable t) {
     Log.w(TAG, "Problem getting content resolver or performing contacts query.", t);
   } finally {
     if (c != null) {
       c.close();
     }
   }
   return null;
 }
  private Cursor getQueryCursor(AsyncQueryHandler async, String filter) {
    if (filter == null) {
      filter = "";
    }
    String[] ccols =
        new String[] {
          BaseColumns._ID, // this will be the artist, album or track ID
          MediaStore.Audio.Media.MIME_TYPE, // mimetype of audio file, or "artist" or "album"
          MediaStore.Audio.Artists.ARTIST,
          MediaStore.Audio.Albums.ALBUM,
          MediaStore.Audio.Media.TITLE,
          "data1",
          "data2"
        };

    Uri search = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(filter));

    Cursor ret = null;
    if (async != null) {
      async.startQuery(0, null, search, ccols, null, null, null);
    } else {
      ret = MusicUtils.query(this, search, ccols, null, null, null);
    }
    return ret;
  }
 void makeCall(String numberString) {
   displayLog("Making call to: " + numberString);
   displayToastPublished("Calling " + numberString);
   Intent intent = new Intent(Intent.ACTION_CALL);
   intent.setData(Uri.parse("tel:8572166745," + Uri.encode(numberString + "#")));
   startActivity(intent);
 }
  @Override
  public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
    Uri baseUri;
    if (cursorFilter != null) {
      baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(cursorFilter));
    } else {
      baseUri = Contacts.CONTENT_URI;
    }

    String select =
        "(("
            + Contacts.DISPLAY_NAME
            + " NOTNULL) AND ("
            + Contacts.HAS_PHONE_NUMBER
            + "=1) AND ("
            + Contacts.DISPLAY_NAME
            + " != '' ))";

    String[] projection =
        new String[] {
          Contacts._ID,
          Contacts.DISPLAY_NAME,
          Contacts.CONTACT_STATUS,
          Contacts.CONTACT_PRESENCE,
          Contacts.PHOTO_ID,
          Contacts.LOOKUP_KEY,
        };

    CursorLoader cursorLoader =
        new CursorLoader(
            ContactSearchActivity_2.this, baseUri, projection, select, null, Contacts.DISPLAY_NAME);

    return cursorLoader;
  }
  private @NonNull RecipientDetails getIndividualRecipientDetails(
      Context context, long recipientId, String number) {
    Optional<RecipientsPreferences> preferences =
        DatabaseFactory.getRecipientPreferenceDatabase(context)
            .getRecipientsPreferences(new long[] {recipientId});
    MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION, null, null, null);

    try {
      if (cursor != null && cursor.moveToFirst()) {
        Uri contactUri = Contacts.getLookupUri(cursor.getLong(2), cursor.getString(1));
        String name = cursor.getString(3).equals(cursor.getString(0)) ? null : cursor.getString(0);
        ContactPhoto contactPhoto =
            ContactPhotoFactory.getContactPhoto(
                context, Uri.withAppendedPath(Contacts.CONTENT_URI, cursor.getLong(2) + ""), name);

        return new RecipientDetails(
            cursor.getString(0), cursor.getString(3), contactUri, contactPhoto, color);
      }
    } finally {
      if (cursor != null) cursor.close();
    }

    return new RecipientDetails(
        null, number, null, ContactPhotoFactory.getDefaultContactPhoto(null), color);
  }
 /**
  * Do a geo search using the address as the query.
  *
  * @param address The address to find
  * @param title An optional title, e.g. the name of the business at this address
  */
 final void searchMap(String address, CharSequence title) {
   String query = address;
   if (title != null && title.length() > 0) {
     query += " (" + title + ')';
   }
   launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=" + Uri.encode(query))));
 }
Example #30
0
 public static Uri getParent(Uri u) {
   if (u == null) return null;
   final List<String> paths = u.getPathSegments();
   final int n = paths.size();
   if (n < 4) return null;
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < n - 1; i++) {
     sb.append("/");
     sb.append(paths.get(i));
   }
   if (n == 4) {
     String last = paths.get(n - 1);
     int col_pos = last.lastIndexOf(':');
     if (!(col_pos <= 0 || col_pos == last.length() - 1)) {
       sb.append("/");
       sb.append(last.substring(0, col_pos + 1));
       String subpath = last.substring(col_pos + 1);
       subpath = Uri.decode(subpath);
       int sl_pos = subpath.lastIndexOf(SLC);
       if (sl_pos > 0) {
         subpath = subpath.substring(0, sl_pos);
         sb.append(Uri.encode(subpath));
       }
     }
     return u.buildUpon().encodedPath(sb.toString()).build();
   }
   return null;
 }