Friday, March 25, 2011

AutomateIt - Useful rules

Visit our new website at http://www.automateitapp.com

Since AutomateIt was published, I'm getting a lot of ideas and requests for some new features, triggers and actions, but along with those, I'm also getting some really interesting ideas of things that can already be performed with the application and I thought it would be a good  idea to share it so you can get the most out of this application.
I'll start with a list of the rules I have defined for my personal use:
  • Bluetooth State Trigger (ON) - Play Sound Action
  • Bluetooth State Trigger (OFF) - Play Sound Action
  • Power Connected Trigger - Set Bluetooth State Action (ON) - used to activate Bluetooth when connecting to charger in my car
  • Power Connected Trigger - Set Screen Timeout (Never)
  • Power Disconnected Trigger - Set Bluetooth State Action (OFF), with delayed execution of 10 seconds to allow the Bluetooth adapter to properly disconnect from paired device
  • Power Disconnected Trigger - Set Screen Timeout (15 seconds)
  • SMS With Text Trigger (Unmute) - Set Sound Mode Action (Normal)
  • Battery Level Trigger (Below 40%) - Notification Action (Low Battery)
  • Bluetooth Device Connected (Car) - Set Volume For Single Stream Action (Voice Call Stream to 100%)
  • Bluetooth Device Connected (Car) - Set Screen Brightness Action (100%)
  • Bluetooth Device Disconnected (Car) - Set Screen Brightness Action (Automatic)
  • Call State Trigger (Incoming from specific contact) - Play Sound Action
  • Time Trigger (Every day at 1:00) - Set Wifi State Action (Disabled)
  • Time Trigger (Every day at 6:30) - Set Wifi State Action (Enabled)
  • USB Connected State Trigger (Connected) - Set Wifi State Action (Enabled)
  • Location Trigger (Exiting region of 200m from home) - Set Wifi State Action (Disabled) - "Disable Wifi When not Home"
  • Time Trigger (every weekday at 7:00) - Enable/Disable Rule Action (Enable "Disable Wifi When not Home" rule)
  • Wifi State Trigger (Disabled) - Enable/Disable Rule Action (Disable "Disable Wifi When not Home" rule)
  • Location Trigger (Entering region of 1500m from home) - Set Wifi State Action (Enabled) - "Enable Wifi When Home"
  • Time Trigger (every weekday at 18:00) - Enable/Disable Rule Action (Enable "Enable Wifi When Home" rule)
  • Wifi State Trigger (Enabled) - Enable/Disable Rule Action (Disable "Enable Wifi When Home" rule)
  • Time Trigger (Every day at 23:00) - Set Sound Mode (Silent). See an Enhanced version of this rule at the "pro rules section" below (Silent at night when device is not used).
  • Time Trigger (Every day at 6:30) - Set Sound Mode (Normal)
  • Outgoing Call Trigger (All contacts) - Vibrate (0.3 seconds)
Some other useful rules that could be defined are:
  • Headset Plugged State Trigger (Plugged) - Start Application Action (some music app)
  • Headset Plugged State Trigger (Plugged) - Set Volume For Single Stream Action (Music Stream to 50%)
  • Headset Plugged State Trigger (Unplugged) - Kill Application Action (some music app)
  • Wifi Network Connection State (Connected) - Play Sound Action
  • Turn on/off GPS when Maps application activated/deactivated
AutomateIt Pro Rules
Since there are several features that are only available on the Pro version, the following rules can only be defined using these advanced features:
  • Car or power connected rule
    • Composite OR Trigger
      • Bluetooth Device Connected Trigger (Car)
      • Bluetooth Device Connected Trigger (Other car)
      • Power Connected Trigger
    • Composite Action
      • Disable screen lock
      • Set Screen Brightness Action (60%)
      • Set Screen Timeout Action (Never)
      • Play Sound Action
  • Car or power disconnected rule
    • Composite OR Trigger
      • Bluetooth Device Disconnected Trigger (Car)
      • Bluetooth Device Disconnected Trigger (Other car)
      • Power Disconnected Trigger
    • Composite Action
      • Enable screen lock
      • Set Screen Brightness Action (Automatic)
      • Set Screen Timeout (30 seconds)
      • Set Bluetooth State Action (Off)
      • Play Sound Action
    • Using delayed execution of 10 seconds
  • Power on (not USB) connected rule
    • Composite AND Trigger
      • Power Connected Trigger
      • USB Connection State Trigger (Disconnected)
    • Set Bluetooth State Action (On)
  • Turn on wifi when home rule
    • Location Trigger (Entering region of 1500m from home)
    • Set Wifi State Action (Enabled)
    • Using Active Rule Period set to weekdays between 17:00 and 21:00
  • Turn on wifi when home rule
    • Location Trigger (Exiting region of 1500m from home)
    • Set Wifi State Action (Disabled)
    • Using Active Rule Period set to weekdays between 7:00 and 10:00
  • Low Battery rule
    • Composite AND Trigger
      • Battery Level Trigger (Below 30%)
      • Power Disconnected Trigger
    • Composite Action
      • Notification Action (Low Battery)
      • Enable/Disable GPS Action (Disable)
      • Enable/Disable Sync Action (Disable)
      • Set Wifi State State Action (Disabled)
      • Set Bluetooth State Action (Off)
  • Activate speaker during active call when device is away
    • Composite AND Trigger
      • Composite OR Trigger
        • Call State Trigger (Incoming from All Contacts)
        • Outgoing Call Trigger (All Contacts)
      • Bluetooth Device Disconnected Trigger (Any Device)
      • Sensor Trigger (Proximity Sensor in FAR state for 1.0 second)
    • Set Speakerphone State Action (Turn on)
    • Note: Several users have reported that when using the Proximity Sensor, it might have a significant impact on your battery consumption (If you experience similar results, try setting it up as described on this post on XDA-Developers.com)
  • Deactivate speaker during active call when device is near
    • Composite AND Trigger
      • Composite OR Trigger
        • Call State Trigger (Incoming from All Contacts)
        • Outgoing Call Trigger (All Contacts)
      • Sensor Trigger (Proximity Sensor in NEAR state for 0.5 second)
    • Set Speakerphone State Action (Turn off)
    • Note: Several users have reported that when using the Proximity Sensor, it might have a significant impact on your battery consumption ((If you experience similar results, try setting it up as described on this post on XDA-Developers.com))
  • Silent at night when device is not used
    • Composite OR Trigger
      • Composite AND Trigger
        • Time Trigger (Every day at 23:01)
        • Screen is off
      • Screen is off
    • Set Sound Mode (Silent)
    • Using Active Rule Period set to every day between 23:00 and 6:00 (Next Day)
    • Using delayed execution of 15 minutes
      • Cancel delayed execution by Screen On Trigger
  • Silent during meetings
    • Calendar Trigger (Start, All Busy events)
    • Set Sound Mode Action (Silent)
    • Using Active Rule Period set to weekdays between 7:00 and 18:00
  • Normal sound when not in meeting
    • Calendar Trigger (End, All Busy events)
    • Set Sound Mode Action (Normal)
    • Using Active Rule Period set to weekdays between 7:00 and 18:00
If you have some other rule that you think could be very useful to others, please share it by adding a comment to this post.

Thursday, March 17, 2011

AutomateIt Location Trigger - Tips and Tricks

For Location Trigger tips & tricks visit our new website at this link.

One of the most popular triggers provided by AutomateIt is the Location Trigger.
Although defining such triggers is very intuitive, still there might be some tips and tricks that can make it even better.
This post will walk you through the basic settings of a common location trigger, emphasizing some features that could help you get the best out of this trigger.
Let's start with a quick overview of the different controls on the location trigger configuration screen:

Most of the controls are pretty self-explanatory so I'll focus on the ones that could use some additional explanation:
  • Arrive at location - Notice that the location trigger defines “Inside or Entering” or “Outside or Exiting” a proximity region around a location. if you are inside the proximity region and defining a rule of "Inside or Entering" a proximity region, it will trigger immediately (dependent on other parameters as explained below). Same goes for defining a rule of "Outside or Exiting" a proximity region when you are already outside of that region.
  • Allow Coarse Accuracy/Use GPS - Select the appropriate location providers for your needs. if just a general location is required, it's safe to allow coarse accuracy. If a more accurate fix is required, uncheck this setting and only use the GPS. The level of accuracy for different providers varies significantly depending on available cells in your area, moving speed etc.
    Tip: I use the following guidelines for location provider accuracy (values are based on my personal experience while developing this application):
    • Network location provider (using cell location) accuracy varies from 200 meters to 2000 meters
    • When connected to Wifi network location estimated accuracy is ~100 meters
    • GPS accuracy can be estimated as 3 meters to ~50 meters (especially when you are moving fast)
    • For more details on location providers and fix accuracy, click here.
  • Location Sampling Rate - Sampling rate is the time interval the application wakes up to check the device location.
    Tip: Use short interval to be more responsive at the expense of activating the location provider(s) more frequently, thus, exhausting your battery (especially when there is no GPS reception) or longer intervals to balance your battery usage.
  • Proximity Radius - By default, this is taken from the application settings (see below). make sure you select an appropriate radius as recommended for the selected location providers (as defined for "Allow Coarse Accuracy").
When defining different parameters for this trigger keep in mind that it will be activated once it can be determined with 100% certainty that you are inside/outside the defined region, considering the accuracy level of the fix.
For instance, let's say the proximity radius is defined as 10 meters and the fix accuracy is 40 meters - in such case even if the fix location is exactly the center of the defined region, the trigger will not be activated since it can't be guaranteed that you are indeed inside/outside the defined region.
Tip: Define a proximity radius that is the maximum reasonable for your needs (I use 1500m for "Entering" rules and 200m for "Exiting" rules).

Some of the default values for settings described above can be set from the settings screen:

One setting I'd like to highlight is the "Location Provider Timeout" which defines an upper bound for trying to get a fix. In case the location provider does not get a fix after this time has passed, it will stop trying to get a fix until the next time defined by "Location Sampling Rate".
On the other hand, once a location provider gets a fix, it will not keep waiting until the defined timeout but it will stop immediately.
This is mainly used to conserve battery so feel free to adjust this setting to your needs.
Tip: Don't push this setting too high (could drain your battery) or too low (could be too short to get a fix).

Last Tip: Avoid setting a "Location Sampling Rate" that is shorter than the "Location Provider Timeout". This will cause the location trigger to constantly request location updates.

New Feature on version 1.16.0 - Since version 1.16.0 each rule stores its history so you can keep track of events related to your rules (for more details on this feature click here). Rules with location triggers have a more detailed history log:
This log shows the recent events for the rule "Turn on wifi at home". You can see that all GPS related events are shown in cyan and all network location events are shown in white.
By looking at this log we see that the location trigger requested location update on 20:45:49 from both GPS and network (two bottom events), received location from network provider 2 seconds later and triggered the rule. At 20:46:19, which is exactly 30 seconds after the first event, the GPS timed-out since we didn't receive any location update (I was indoors when creating this demo).
To better understand the "Is Inside Target Region" response which might be Yes, No or Unknown, take a look at the following diagram (click on the image to enlarge):
One Interesting feature is that once a location is received, you can click on the hyperlink (the coordinates on the screenshot are smudged) and show it on Maps application or using the Browser:
This log can be very useful to better understand and fine-tune your location triggers since it shows you each location received, level of accuracy and the distance to your defined location. Here is a list of all events related to location triggers that you might see on your rule history log:


  • Start waiting for location (provider=GPS/Network, timeout=XX)
  • Location received (provider: GPS/Network) - Includes location details
  • Location provider timeout. no location received (provider=GPS/Network)
  • Location provider enabled/disabled (provider=GPS/Network)
Feel free to add more tips and best practices to the comments of this post.

Friday, March 11, 2011

Send Email from Android Application

One of the most common tasks a developer would like to add to his/her application in order to keep in touch with its users is to allow the user send emails from within the application.

Following the Android Developers Reference for the Intent.ACTION_SEND lacks the documentation you would expect in order to properly send an email (not SMS, Twit, file, image etc...).


In order for you to enforce email submission you need to specify the correct type for the created intent. Normally, you would write something like:
emailIntent.setType("text/plain");
but that would let you choose all kinds of applications for performing tasks that are completely unrelated to sending emails.


This is the snippet I use to send email from my applications. notice the type used to force email application.

private void sendEmail()
{
try
{
Intent emailIntent = new Intent(Intent.ACTION_SEND);

String aEmailList[] = { "some_email@domain.com"};

emailIntent.putExtra(Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Sample Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "");

emailIntent.setType("message/rfc822");

startActivity(Intent.createChooser(emailIntent, "Select Email Application"));
}
catch (Exception ex)
{
Log.e("SendEmail", "Can't send email", ex);
}
}