0

I have created android service that access the ContentObserver to get the sms details, Now i want to start the service when phone boot and restart.

Now everything works fine, but when i restart the phone it doesn't run the service, but when i power off and power on again it runs without any issues, please let me know the issue.

Given below is my AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.situmina.callmanager"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.situmina.callmanager.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       <service   android:enabled="true" android:name="com.situmina.callmanager.CallService"/>
        <receiver android:name="com.situmina.callmanager.OutgoingCallReceiver" android:enabled="true" android:exported="false">
            <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />                      
            </intent-filter>
        </receiver>
    </application>

</manifest>
Bishan
  • 15,211
  • 52
  • 164
  • 258
Sajeewa
  • 74
  • 1
  • 13
  • can you post your **Service** and **BroadcastReceiver** code? – The Badak Jan 28 '14 at 09:02
  • possible duplicate of [Trying to start a service on boot on Android](http://stackoverflow.com/questions/2784441/trying-to-start-a-service-on-boot-on-android) – Bishan Jan 28 '14 at 09:38
  • i am doing the same way as in the threat, but when the phone is restated it wont work but when i swith on the phone it works, i have a Huawei phone. – Sajeewa Jan 28 '14 at 11:25

1 Answers1

0

If you have checked https://stackoverflow.com/a/5439320/715269 and it won't help, I think that you have a problem tied to the gadget.

What about trying more automatic way? You could create a widget and launch the service from it. All installed widgets are started at restart.

As for Widget, you need absolutely minimalistic widget. The only thing s it will do: It will have a layout of one picture - to show that your service is installed, and it will launch your service from its own onStart(). Later you can add the possibility to turn your service on/off by user.

How to do widgets - look at developers. Don't forget to put your service into the widget manifest, too.

Community
  • 1
  • 1
Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • thank you for your quick response, can you please explain how can i create a widget for my service. – Sajeewa Jan 28 '14 at 09:07
  • Using a widget to start a service doesn't sound right. You should be able to start the service on boot - many apps already do that, and I don't think they use widgets to do it. – ADTC Jan 28 '14 at 09:40
  • @ADTC Please, what do you mean - application starts a service? Applications are NOT started automatically, so their widgets won't be started automatically, too. – Gangnus Jan 28 '14 at 09:45
  • _"their widgets won't be started automatically"_ Then what do you mean by _"All installed widgets are started at restart."_ ? – ADTC Jan 28 '14 at 09:48
  • My service starts automatically when phone on, but if i restart the phone it doesnt work, is that a phone specific issue? – Sajeewa Jan 28 '14 at 09:49
  • @ADTC Mostly applications are activities, not widgets. If you mean widgets, we are returning to my answer. – Gangnus Jan 28 '14 at 09:50
  • @Sajeewa Have you checked http://stackoverflow.com/a/5439320/715269? If yes, then you have a gadget-specific problem. Or some conflicts of services. – Gangnus Jan 28 '14 at 09:51
  • What I meant to say is that apps when installed (or through an user configuration) can register services that should be started when Android starts up. This is done by many existing apps that require background services to start up as soon as the phone is started. **I just wanted to point out that your proposal** to hack up a "widget" simply to enable the starting up of a service **is rather odd**, when Android already provides a standard way to start up a service at boot. (Ref: *"You could create a widget and launch the service from it."*) – ADTC Jan 28 '14 at 10:33
  • I am doing the same way as in the threat http://stackoverflow.com/a/5439320/715269 it works fine when switch on the phone, but not the restart. – Sajeewa Jan 28 '14 at 10:46
  • Then, as I said, IMHO, there is a conflict with firmware, version or some services/widgets already installed. Try to do it by widget. Try also to remove all other widgets and services from the device. – Gangnus Jan 28 '14 at 11:21
  • @Gangnus i managed to solve the issue using Widgets, thank for your help. – Sajeewa Feb 03 '14 at 09:38