open android calendar with html link

后端 未结 2 988
悲哀的现实
悲哀的现实 2021-01-19 23:47

I need to open the calendar app on my Android Device using a simple html link. I was able to do this in iOS with href=CALSHOW:// is there something similar for android?

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-20 00:02

    I don't know to be such link that WebView would support, but it's very easy to handle that link for yourself. I am assuming you're loading the web content (html) in a WebView. Inside the html you will have this type of link:

    Open calendar
    

    In the Java code, you will overwrite that link:

    myWebView.setWebViewClient(new WebViewClient(){
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    if(url.startsWith("CALSHOW")) {
                        openCalendar();
                        return true;
                    }
                    return super.shouldOverrideUrlLoading(view, url);
                }
            });
    

    And the method to open the calendar:

    protected void openCalendar() {
            Intent calendarIntent = new Intent() ;
            /**
             * Set the time you need ...
             * */
            //calendarIntent.putExtra("beginTime", your_time);
            calendarIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            calendarIntent.setClassName("com.android.calendar","com.android.calendar.AgendaActivity");
            startActivity(calendarIntent);
        }
    

    That is the work-around

提交回复
热议问题