Open calendar from a link

1

I've seen many different ways of doing this, but none works

I need to put a link on my website, where when I click, open the schedule for the person to save 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 in Android it does not work if you do not have any third-party program to do ics handle

Has anyone ever been through this? Any tips?

    
asked by anonymous 11.07.2016 / 03:34

2 answers

1

I seem to have found my own answer. Unfortunately I do not know if I can answer it, but if I can not, I ask the moderators to correct and instruct me so I can understand better.

Well, in iOS we have the webcal, as I said earlier. Mounting 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 the webcal, and open a new intent for the calendar, so I drop the ICS and set up a calendar. I know there are better ways to parse in ICS, but follow the code I used

Anyway, I now 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;
        }

    
12.07.2016 / 04:13
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: link

Bookstore: link

    
11.07.2016 / 13:01