Atif
Atif

Reputation: 29

Get the name of all tasks in Tasker programmatically

I am trying to develop a List Activity(initially) that is populated with the tasks created in Tasker. Is there any way I can get the Task names from Tasker? The only way i can communicate with tasker programmatically is using the TaskerIntent class. But there is no function that can retrieve the names.

What I want to do is get the list of tasks and then execute those tasks from the PC. Inorder to run the task, i need to either pass the task name to tasker or send a Task Select Intent.

Thanks!

Upvotes: 1

Views: 1312

Answers (1)

indivisible
indivisible

Reputation: 5012

The Tasker Docs have an example on how to do this.

The user must have enabled "ext_access"/External Access for this to work so remember to inform the user if your read fails.
I'm not sure if you get an Exception or an empty result set, you'll need to test that yourself to handle both cases:

  1. The user has not enabled external access
  2. The user has not created any Tasks

Here's the code to log all tasks wrapped in a method for your convenience:

public void logAllTaskerTasks() {
    Cursor c = getContentResolver().query(
                     Uri.parse( "content://net.dinglisch.android.tasker/tasks" ),
                     null, null, null, null );

    if ( c != null ) {
        int nameCol = c.getColumnIndex( "name" );
        int projNameCol = c.getColumnIndex( "project_name" );

        while ( c.moveToNext() ) {
            Log.d( TAG,  c.getString( projNameCol ) + "/" + c.getString( nameCol ) );
        }
        c.close();
    }
}

Upvotes: 4

Related Questions