开发者

Add a calendar event using a webpage button via webview

开发者 https://www.devze.com 2023-03-20 07:19 出处:网络
I want to use a webview to pull up a page and on it is a label of an event and a button that says add to calendar. When pushed it will add the details of the event to the google cal on the android pho

I want to use a webview to pull up a page and on it is a label of an event and a button that says add to calendar. When pushed it will add the details of the event to the google cal on the android phone.

I am attempting to use content values but with no luck as of yet. This is what I have but I am open for suggestions. I think I have read every post on stackoverflow concerning this so I am looking for something new or more complete than whats been posted already.

public class button7 extends Activity{

 WebView wb = null;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.buttons);
  wb = new WebView(this);
  wb.setWebViewClient(new HelloWebViewClient());
  wb.getSettings().setJavaScriptEnabled(true);
  wb.loadUrl("http://whatever website.com");
  setContentView(wb);
 }

 private class He开发者_Python百科lloWebViewClient extends WebViewClient {

  public boolean shouldOverrideUrlLoading(WebView view, String url) {
   view.loadUrl(url);
   SetCalenderEntry(1,"Test","Is this working","At home");
   return true;
  }

 }




 private void SetCalenderEntry(int i,  String subject, String body, String location) 
 {
    ContentValues event = new ContentValues();
    event.put("calendar_id", i);
    event.put("title", subject);
    event.put("description", body);
    event.put("eventLocation", location);
    long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
    long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;
    event.put("dtstart", startTime);
    event.put("dtend", endTime);
    Uri eventsUri = Uri.parse("content://calendar/events");
    getContentResolver().insert(eventsUri, event);
 }

 public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK && wb.canGoBack())
   wb.goBack();
  return super.onKeyDown(keyCode, event);
 }
}


Use the Google Calendar GData API if you are trying to manipulate the user's Google Calendar.

0

精彩评论

暂无评论...
验证码 换一张
取 消