Cordova получает URL от браузера - PullRequest
0 голосов
/ 12 апреля 2020

Я хочу, чтобы мое приложение android могло получать URL-адрес от браузера пользователей следующим образом:

Является ли плагин для этого, как я обнаружил это

И мне удалось заставить их пример работать с изображениями.

Но как мне заставить мое приложение получать URL-адрес из браузера?

Это используется код (тот же самый код, который используется в документации по плагинам)

document.addEventListener('deviceready', setupOpenwith, false);

function setupOpenwith() {

  // Increase verbosity if you need more logs
  //cordova.openwith.setVerbosity(cordova.openwith.DEBUG);

  // Initialize the plugin
  cordova.openwith.init(initSuccess, initError);

  function initSuccess()  { console.log('init success!'); }
  function initError(err) { console.log('init failed: ' + err); }

  // Define your file handler
  cordova.openwith.addHandler(myHandler);

  function myHandler(intent) {
    console.log('intent received');

    console.log('  action: ' + intent.action); // type of action requested by the user
    console.log('  exit: ' + intent.exit); // if true, you should exit the app after processing

    for (var i = 0; i < intent.items.length; ++i) {
      var item = intent.items[i];
      console.log('  type: ', item.type);   // mime type
      console.log('  uri:  ', item.uri);     // uri to the file, probably NOT a web uri

      // some optional additional info
      console.log('  text: ', item.text);   // text to share alongside the item, iOS only
      console.log('  name: ', item.name);   // suggested name of the image, iOS 11+ only
      console.log('  utis: ', item.utis);
      console.log('  path: ', item.path);   // path on the device, generally undefined
    }

    // ...
    // Here, you probably want to do something useful with the data
    // ...
    // An example...

    if (intent.items.length > 0) {
      cordova.openwith.load(intent.items[0], function(data, item) {

        // data is a long base64 string with the content of the file
        console.log("the item weights " + data.length + " bytes");
        uploadToServer(item);

        // "exit" when done.
        // Note that there is no need to wait for the upload to finish,
        // the app can continue while in background.
        if (intent.exit) { cordova.openwith.exit(); }
      });
    }
    else {
      if (intent.exit) { cordova.openwith.exit(); }
    }
  }
}

Затем я создал приложение android с использованием Cordova CLI

и добавил плагин с помощью этой команды ( это команда, указанная в документации к плагинам):

cordova plugin add cc.fovea.cordova.openwith \
  --variable ANDROID_MIME_TYPE="image/*" \
  --variable IOS_URL_SCHEME=ccfoveaopenwithdemo \
  --variable IOS_UNIFORM_TYPE_IDENTIFIER=public.image

Приведенный выше код работает, он отображает количество байтов в изображении, которое предоставляется приложению, но как я могу изменить это, чтобы получать URL-адреса из браузера.

...