Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Service application

I'm writing a software suite for Android devices that will keep track of call times and various other call info. I'd like one of the applications to run as a Service without being started from an Activity, and I'd like it to initialize immediately when the phone boots, and stay running constantly, listening for phone calls, logging information to a database as necessary. The Service will need to present a dialog to the user at the end of each call.

2 questions:

  1. How do I get the program (Service) to initialize at boot automatically with no user setting or interaction required?

  2. I was under the impression that you cannot instantiate and display dialogs without using an Activity. I would like the dialogs to appear laid over whatever the user currently has on the screen, and display a dialog. Is there a way to make an Activity completely transparent over the current Activity or is there a way to display dialogs from a Service?

thanks in advance.

like image 486
moonlightcheese Avatar asked Mar 09 '11 20:03

moonlightcheese


People also ask

What is Android service app?

Android service is a component that is used to perform operations on the background such as playing music, handle network transactions, interacting content providers etc. It doesn't has any UI (user interface). The service runs in the background indefinitely even if application is destroyed.

What is service in application?

A Service is an application component that can perform long-running operations in the background. It does not provide a user interface. Once started, a service might continue running for some time, even after the user switches to another application.

What is Android service in mobile application development?

Android app development services comprise design, development, and enhancement of mobile software that runs on all supported Android OS versions. Targeting Android with native, hybrid, and cross-platform development, ScienceSoft always guarantees sustainable and seamless mobile experience.


1 Answers

How do I get the program (Service) to initialize at boot automatically with no user setting or interaction required?

Add this permission to your manifest:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Then add a receiver to your manifest:

<receiver android:name="your.package.BootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.HOME" />
    </intent-filter>
</receiver>

Create a receiver in Java code:

public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // start the service from here
    }
}

I was under the impression that you cannot instantiate and display dialogs without using an Activity. I would like the dialogs to appear laid over whatever the user currently has on the screen, and display a dialog. Is there a way to make an Activity completely transparent over the current Activity or is there a way to display dialogs from a Service?

Yes, that's true. You have to have an activity that pops up the dialog. To create a transparent activity add the following style in your res/values/styles.xml file (if you don’t have one, create it.) Here’s a complete file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">#00000000</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>

Then apply the style to your activity, for example:

<activity android:name=".TransparentActivity" android:theme="@style/Theme.Transparent">
...
</activity>
like image 131
Cristian Avatar answered Sep 27 '22 21:09

Cristian