Open calendar from a link

Asked

Viewed 691 times

0

I’ve seen many different ways to do it, but none of it works

I need to put a link on my site, where when click, open the schedule for the save person in her calendar

just like tel: mailto:, I saw some things like Calendar: calshow:, but none works

I tried to create ics and download, but android does not work if you do not have some third program to do ics Handle

Has anyone been there? Any tips?

2 answers

1


Looks like I found my own answer. Unfortunately I don’t know if I can answer it, but if I can’t, I ask the moderators to correct and instruct me so that I can understand better

Well, on iOS we have Webcal, as I said earlier. Building links like this:

<a href="webcal://192.168.1.102/scripts/apptest/teste.ics">Agendar</a>

iOS opens the event right

To solve this problem, in the shouldOverrideUrlLoading of my webview, I check if the URL has Webcal, and open a new Internet calendar, so I download the ICS and assemble a calendar. I know there are better ways to parse the ICS, but follow the code I used

Anyway, now I have the same HTML working for both devices

// Verifica se começa com o protocolo de calendario (webcal para manter padrão com ios)
        if(url.startsWith("webcal")) {

            if (android.os.Build.VERSION.SDK_INT > 9) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                StrictMode.setThreadPolicy(policy);
            }
            try {
                // Cria o link para o ICS
                URL urla = new URL(url.replace("webcal", "http"));

                // Coloca em buffer todo o texto
                BufferedReader in = new BufferedReader(new InputStreamReader(urla.openStream()));
                String str;

                // Inicia o calendario e percorre linha à linha
                Calendar cal = Calendar.getInstance();
                Intent intent = new Intent(Intent.ACTION_EDIT);
                intent.setType("vnd.android.cursor.item/event");
                while ((str = in.readLine()) != null) {
                    /*
                        Verificar de não ter espaços entre o :
                        Não usar Z no final do datetime
                     */

                    // Verifica data de inicio
                    if(str.contains("DTSTART:")) {
                        // Cria o formato da data e da o parse
                        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
                        Date date = format.parse(str.replace("DTSTART:", ""));

                        // Adiciona o parametro
                        intent.putExtra(CalendarContract.Events.DTSTART, (date.getTime()));
                    }

                    // Verifica data de fim
                    else if(str.contains("DTEND:")) {
                        // Cria o formato da data e da o parse
                        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
                        Date date = format.parse(str.replace("DTEND:", ""));

                        // Adiciona o parametro
                        intent.putExtra(CalendarContract.Events.DTEND, (date.getTime()));
                    }

                    // Verifica o titulo
                    else if(str.contains("SUMMARY:")) {
                        intent.putExtra(CalendarContract.Events.TITLE, str.replace("SUMMARY:", ""));
                    }

                    // Verifica o organizador
                    else if(str.contains("ORGANIZER:")) {
                        intent.putExtra(CalendarContract.Events.ORGANIZER, str.replace("ORGANIZER:", ""));
                    }

                    // Verifica o local
                    else if(str.contains("LOCATION:")) {
                        intent.putExtra(CalendarContract.Events.EVENT_LOCATION, str.replace("LOCATION:", ""));
                    }

                    // Verifica o descrição
                    else if(str.contains("DESCRIPTION:")) {
                        intent.putExtra(CalendarContract.Events.DESCRIPTION, str.replace("DESCRIPTION:", ""));
                    }
                }

                // Fecha a conexão
                in.close();

                // Inicia o intent do calendário
                startActivity(intent);

            } catch (MalformedURLException e) {
                Log.d("Log", "Erro: " + e);
            } catch (IOException e) {
                Log.d("Log", "Erro: " + e);
            } catch (ParseException e) {
                Log.d("Log", "Erro: " + e);
            } catch (Exception e) {
                Log.d("Log", "Erro: " + e);
            }

            return true;
        }

inserir a descrição da imagem aqui

1

(function() {
  if (window.addtocalendar)
    if (typeof window.addtocalendar.start == "function") return;
  if (window.ifaddtocalendar == undefined) {
    window.ifaddtocalendar = 1;
    var d = document,
      s = d.createElement('script'),
      g = 'getElementsByTagName';
    s.type = 'text/javascript';
    s.charset = 'UTF-8';
    s.async = true;
    s.src = ('https:' == window.location.protocol ? 'https' : 'http') + '://addtocalendar.com/atc/1.5/atc.min.js';
    var h = d[g]('body')[0];
    h.appendChild(s);
  }
})();
<link href="http://addtocalendar.com/atc/1.5/atc-style-blue.css" rel="stylesheet" />

<span class="addtocalendar atc-style-blue">
  <var class="atc_event">
    <var class="atc_date_start">2016-05-04 12:00:00</var>
    <var class="atc_date_end">2016-05-04 18:00:00</var>
    <var class="atc_timezone">Europe/London</var>
    <var class="atc_title">Star Wars Day Party</var>
    <var class="atc_description">May the force be with you</var>
    <var class="atc_location">Tatooine</var>
    <var class="atc_organizer">Luke Skywalker</var>
    <var class="atc_organizer_email">[email protected]</var>
  </var>
</span>

jsFiddle: http://jsfiddle.net/AddToCalendar/Df86Z/

Bookstore: http://addtocalendar.com/

  • The idea is very good. However by what I tested here it gave the option for the user to add in the most convenient calendar. Hence if the user does not know what he has, he does not know what to do. Another problem is that if on the mobile he does not use google Calendar, it does not work. The same would be good if when opening the . ics (for example) he asks that famous "open as", or something like that knows? porem ics does not work on android

  • Opening . ics will prompt you for the calendar you want, but you still need to execute the file.. You can simply see what type of device to access the site and then forward it to the default calendar. Edited reply.

  • If you try to open the ICS on android, see that it will appear: "cannot open file"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.