4

Introduction

As some of you might know, the new Samsung Galaxy S3 have some cool motion features that can be used for making some "tasks" easier. For those who don't, here is the link for the explanation

Motivation

I want to write an background service to act as this Touchwizz-exclusive set of features.

What its possible

According to the android documentation about sensor providers and background-services, and the useful information found at this link (provided by @Michal K), it is possible to intercept those sensor events, from a background service. Even tho it would be very battery expensive, it is still possible.

What i'm not sure it's possible

I am not sure if interacting with the foreground app (be it "Contacts", or "Messaging", or w.e) is possible using a background service or any other way.

By interacting, i mean, be able to do something like this, for instance:

  1. BGService intercepts event "saying" that the phone is in "call position"
  2. BGService checks if the foreground app is either "Contacts" or "Messaging"
  3. If it is, BGService checks if there is any opened sms or contact
  4. If there is a opened (focused) contact or sms thread, the BgService starts a call for that contact (or sender of the sms).

This is the core idea of what i am trying to achieve, is this possible or such integration between apps and events is only possible because all of them are bundled in a single framework (which is Touchwizz, in this case) ?

If it is possible, any tip is welcome.

Thanks in advance

Marcello Grechi Lins
  • 3,350
  • 8
  • 38
  • 72

1 Answers1

1

1.BGService intercepts event "saying" that the phone is in "call position"

You can use the TelephonyManager API to determine the phone state

2.BGService checks if the foreground app is either "Contacts" or "Messaging"

You can use the ActivityManager API to determine the foreground application. See the following post for an example : Determining the current foreground application from a background task or service

3.If it is, BGService checks if there is any opened sms or contact

This I do not know if its possible to do. You would need a way to query the SMS or Contacts applications to find out what is focused in the view. The SmsManager API only provides methods for sending SMS's.

4.If there is a opened (focused) contact or sms thread, the BgService starts a call for that contact (or sender of the sms).

Same answer as #3.

Alternatively, if you are only interested in content changes in the SMS and Contacts app you might be able to do something with the ContentObserver API.

Also look at the API documentation for ContentProviders, and the Content Provider Basics docs.

Community
  • 1
  • 1
Akos Cz
  • 12,711
  • 1
  • 37
  • 32