0

I just started playing with services in Android and I am trying to make a hidden app which mutes the phone on startup. I was following this thread:Android hidden application

It doesn't show any errors but the service doesn't semm to be called on startup.

This is my Android/manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.timer"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

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



<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">

       <receiver android:name="org.example.timer.serviceCode" >
              <intent-filter >
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
              </intent-filter>
        </receiver>
         <service android:name="org.example.timer.service" />
</application>

Also my serviceCode:`

package com.example.timer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class serviceCode extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    Intent i = new Intent("com.example.service");
        i.setClass(context, serviceCode.class);
        context.startService(i);
}

}

And my service:

package com.example.timer;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;

public class service extends Service {
  private AudioManager myAudioManager;

  @Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
@Override  
public void onCreate() {
        super.onCreate();
        myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        myAudioManager.setStreamMute(AudioManager.STREAM_ALARM, true);
        myAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
        myAudioManager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        myAudioManager.setStreamMute(AudioManager.STREAM_RING, true);
        myAudioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
}
}

I am kinda confused becouse I was following the guide and nothing happens. When I turn on the phone the sound is on the same value. I also tried putting there toast to find out whether the service even starts but it didn't show up.

My LogCat:

[2014-09-06 16:13:46 - timer] ------------------------------
[2014-09-06 16:13:46 - timer] Android Launch!
[2014-09-06 16:13:46 - timer] adb is running normally.
[2014-09-06 16:13:46 - timer] No Launcher activity found!
[2014-09-06 16:13:46 - timer] The launch will only sync the application package on the device!
[2014-09-06 16:13:46 - timer] Performing sync
[2014-09-06 16:13:47 - timer] Uploading timer.apk onto device '0c295416'
[2014-09-06 16:13:47 - timer] Installing timer.apk...
[2014-09-06 16:13:49 - timer] Success!
[2014-09-06 16:13:49 - timer] \timer\bin\timer.apk installed on device
[2014-09-06 16:13:49 - timer] Done!

Thank you for help.

Community
  • 1
  • 1
user3000140
  • 319
  • 2
  • 11

1 Answers1

-1

check package names in your AndroidManifest.

You register receiver with android:name="org.example.timer.serviceCode" but in java class package is package "com.example.timer"

upd:

first you must create activity and launch it at least one time. http://commonsware.com/blog/2011/07/05/boot-completed-regression.html

I just test it on my own - works nice.

ant
  • 397
  • 1
  • 5
  • 19
  • Actually what I am trying to do is to make an app that automaticly mutes my phone during school time. I don't want this app to be shown in the app list because I hate useless icons. That's why I decided to make an app that is hidden-has no activiy. I would like to know whether there is a way around it to make it possible. It is a shame that it is how it is since hidden apps are the only thing to modify the system like Task Scheduler for windows. I would be happy if u could recommend me a way of doing this. Also I have a rooted phone so if there is something please share it. But still thanks. – user3000140 Sep 06 '14 at 15:31
  • Is there a way to simulate user interaction to get the app from stopped state after installation? Or is there a way to make the activity delete itself after launch and leave the service running while the app is hidden? – user3000140 Sep 06 '14 at 15:41
  • i think i have one way for you. just use command line to start the app. look here http://devmaze.wordpress.com/2011/12/05/activating-applications/ – ant Sep 06 '14 at 15:42