Create calendar event using app.SendIntent

657 views
Skip to first unread message

Timo Octazid

unread,
Nov 2, 2015, 1:03:30 PM11/2/15
to AndroidScript
Hi,
Can everybody help me with this problem?
I find: https://developer.android.com/guide/topics/providers/calendar-provider.html#intents
But it is to high for me at the moment. :-) Which parameters must I use in app.SendIntent()?
How can I send an intent to create a new calendar event in my standard android account?

Many Greetings
Timo

Timo Octazid

unread,
Nov 3, 2015, 3:59:17 AM11/3/15
to AndroidScript
Hi,
This is my code at the moment. It opens the calendar app but I'm not able to create a new event... All I try fails.
I hope, someone can help me with this problem.

//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );

//Create a button 1/3 of screen width and 1/10 screen height.
btn = app.CreateButton( "Send Intent", 0.3, 0.1 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );

//Add layout to app.
app.AddLayout( lay );
}

//Called when user touches our button.
function btn_OnTouch()
{
    var packageName = "com.android.calendar";
var className = "com.android.calendar.LaunchActivity";

    var action = "android.intent.ACTION_INSERT";
    var category = null;
    var uri = "android.intent.Events.CONTENT_URI";
    var type = "vnd.android.cursor.item/event";

var starttime = new Date(2015, 10, 3, 15, 15, 0);
var startms = starttime.getTime();
var endtime = new Date(2015, 10, 3, 16, 30, 0);
var endms = endtime.getTime();
//app.ShowPopup(startms + " " + endms)
    
    var extras = [ 
        {name:"android.intent.CalenderContract.EXTRA_EVENT_BEGIN_TIME", type:"date", value: startms},
        {name:"android.intent.CalendarContract.EXTRA_EVENT_END_TIME", type:"date", value: endms},
        {name:"android.intent.Events.TITLE", type:"string", value:"TestEntry"},
        {name:"android.intent.EXTRA_EMAIL", type:"string", value:"te...@test.com"} 
    ];
    extras = JSON.stringify( extras );

    app.SendIntent( packageName, className, action, category, uri, type, extras ); 
}

Many Greetings
Timo

RuslanX

unread,
Nov 4, 2015, 5:49:09 PM11/4/15
to AndroidScript
I need this too ...

RuslanX

unread,
Nov 4, 2015, 6:06:00 PM11/4/15
to AndroidScript
error in debuger: "Unable to find explicit activity class {com.google.android.calendar/com.android.calendar.LaunchActivity}; have you declared this activity in your AndroidManifest.xml?"

RuslanX

unread,
Nov 4, 2015, 6:58:54 PM11/4/15
to AndroidScript
I think need to add
<uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission>
to
AndroidManifest.xml ..

RuslanX

unread,
Nov 6, 2015, 6:03:31 AM11/6/15
to AndroidScript
Message has been deleted

Frank Vizza

unread,
Mar 4, 2019, 4:56:47 PM3/4/19
to DroidScript
The permissions route did not work.

The SendIntent does not operate, I still get the message:
"Unable to find explicit activity class {com.google.android.calendar/com.android.calendar.LaunchActivity}; have you declared this activity in your AndroidManifest.xml?".

BareK

unread,
Mar 6, 2019, 6:15:04 AM3/6/19
to DroidScript
Maybe posting a sample code will make it clearer.
Message has been deleted

Frank Vizza

unread,
Jun 27, 2019, 8:26:54 AM6/27/19
to DroidScript
Apparently, Google changed the name of the calendar package.

If you change the packageName line in Timo's example to:

var packageName = "com.google.android.calendar";

there is no debugger error and the calendar appears on the screen. However, no new calendar entry is made.

Adding :

_AddPermissions("WRITE_CALENDAR");

to the top of the script also has no effect, but I think both of these changes are a good step forward.

I will devote more time to this when script when possible.

Message has been deleted

Frank Vizza

unread,
Jun 29, 2019, 3:31:54 PM6/29/19
to DroidScript
The following code successfully executes the calendar using sendintent as was originally attempted.

There are a limited number of fields that can be modified using this method.

You don't need to add any permissions to the code because it automatically brings up a calendar application. If then pre-populate the number of fields and allows you to save it to the calendar.

If you have a number of email addresses, and have calendars for each one of them, this program will simply pick the last email address use for the last calendar entry made. As far as I can determine there is no control over what calendar you put the entry into with the send intent method.

In order to gain more control over information that is in the calendar, I believe the sync adapter method must be used, which is what I am going to be investigating next.

The following code does work for making calendar entries with the send intent method.

function OnStart()
{

lay = app.CreateLayout( "linear", "VCenter,FillXY" );

btn = app.CreateButton( "Send Intent", 0.3, 0.1 );

btn.SetOnTouch( cal_si_insert );
lay.AddChild( btn );
app.AddLayout( lay );
}


function cal_si_insert()
{
var today = new Date().getTime();
var packageName = null;
var className = null;
var action = "android.intent.action.INSERT";


var category = null;
var uri = "android.intent.Events.CONTENT_URI";
var type = "vnd.android.cursor.item/event";

var extras = [
{name:"description", type:"string", value:"DS SendIntent Description"},
{name:"title", type:"string", value: "DS SendIntent Title"},
{name:"beginTime", type:"long", value: today},
{name:"eventLocation", type:"string", value: "DS SendIntent Address"},
{name:"endTime", type:"long", value: today + 3600000},
]

Reply all
Reply to author
Forward
0 new messages