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;
}
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
– Bruno Pitteli Gonçalves
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.
– Skramewell
If you try to open the ICS on android, see that it will appear: "cannot open file"
– Bruno Pitteli Gonçalves