B
B
bigbaraboom2015-06-02 20:58:54
JavaScript
bigbaraboom, 2015-06-02 20:58:54

How to open a specific browser URL?

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yandex.ru"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

So I'm trying to open the URL in the browser, but with such a call, a window pops up where you need to choose which browser to open. Something like that - Share%20URL%20From%20One%20Browser%20to%
Is it possible to somehow make this window not pop out? How can I specify what to open the url with the default browser?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2018-08-01
@RatiboR1978

Let's start with the alphabet:

let alphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'.split('')
charcode cannot be used, because in Unicode the letter "ё" comes after the letter "i". And it seems to be forever.
Further function which defines "distance" between letters.
function getRange(a, b) {
  let iA = alphabet.indexOf(a), iB = alphabet.indexOf(b) // ищем на каких позициях встречаются эти буквы в алфавите
  if (iA === -1 || iB === -1) return Infinity // если вообще не встречаются - расстояние бесконечность.
  return Math.abs(iA - iB)
}


getRange('а', 'р') // -> 17
getRange('а', 'я') // -> 32
getRange('к', 'в') // -> 9
getRange('а', 'f') // -> Infinity  (и никто не мешает добавить английский алфавит)

Based on this function, it is not difficult to write sorting by distance:
function getClosestWord(letter) {
  return [...words].sort((word1, word2) => {
  	return getRange(word1[0], letter) - getRange(word2[0], letter)
  })
}

getClosestWord('а') // ->
["аметист", "баржа", "дом", "еж", "креветка", "каток", "кот", "лимон", "море", "морж", "нора", "рога", "рыба", "рак", "сани", "сом", "собака", "том", "танк"]

getClosestWord('п') // ->
["рыба", "рак", "рога", "нора", "собака", "сани", "сом", "танк", "море", "том", "морж", "лимон", "каток", "кот", "креветка", "еж", "дом", "баржа", "аметист"]

The point is small - repeat until the words run out.

I
Ivan Lebedev, 2015-06-03
@kamiLLxiii

Here is an example code, how you can specify which application should be launched by Intent

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yandex.ru"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

//запрос всех activity, которые могут этот intent обработать
List<ResolveInfo> resInfo = activity.getPackageManager().queryIntentActivities(intent, 0);
if (!resInfo.isEmpty()) {
  for (ResolveInfo info : resInfo) {
      if (/*здесь проверяй info на предмет нужной тебе activtiy*/) {
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        intent.setPackage(info.activityInfo.packageName);
        context.startActivity(intent);
        break;
      }
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question