0

how to start background services using broadcast receiver. made one services for camera lock operation but after some time function is not working . service is running in android devices. but method of services in onstartcommand not working.

used action.user_present but its not working .

 public class camerareceiver extends BroadcastReceiver{ 
public static String TESTACT_S = "android.intent.action.USER_PRESENT"; 
     @Override
     public void onReceive(Context context, Intent intent) {
     if(intent.getAction().equals(TESTACT_S))
      { context.startService(newIntent("com.simsys.camera.ServiceTemplate")); } }
Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • What is problem? Show the relevant code and Logcat. – Gaurav Agarwal May 10 '12 at 11:01
  • used action.user_present but its not working .public class camerareceiver extends BroadcastReceiver{ public static String TESTACT_S = "android.intent.action.USER_PRESENT"; @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(TESTACT_S)){ context.startService(new Intent("com.simsys.camera.ServiceTemplate")); } }in log cat no bug displayed . but when run service , camera is working instead of to lock camera. – user1345747 May 10 '12 at 11:13
  • See if these can help you http://stackoverflow.com/questions/10329810/intent-action-user-present-not-received-on-honeycomb-or-ics-samsung-devices and http://stackoverflow.com/questions/8750854/bring-task-to-front-on-android-intent-action-user-present – Gaurav Agarwal May 10 '12 at 11:21

1 Answers1

0

start service from BroadcastReceiver as:

public class CamReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
   Toast.makeText(context, "ACTION_USER_PRESENT",  Toast.LENGTH_LONG).show();
 context.startService(new Intent(context,ServiceTemplate.class));
}
}
}

In manifest :

<receiver android:name= ".CamReceiver">
           <intent-filter>
             <action android:name="android.intent.action.USER_PRESENT"/>
           </intent-filter>
        </receiver>
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • used action.user_present but its not working .public class camerareceiver extends BroadcastReceiver{ public static String TESTACT_S = "android.intent.action.USER_PRESENT"; @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(TESTACT_S)){ context.startService(new Intent("com.simsys.camera.ServiceTemplate")); } } – user1345747 May 10 '12 at 11:11
  • see my edit answer or if not get solved then post your catlog stacktrace and code – ρяσѕρєя K May 10 '12 at 11:17
  • com.simsys.camera.ServiceTemplate your package or another app? – ρяσѕρєя K May 10 '12 at 11:18
  • com.simsys.camera is my package name and service template is service name – user1345747 May 10 '12 at 11:23
  • @user1345747 : just wait it'will work sure bez we are doing in right way. i have add a toast in broadcast reciver so it's appear or not when you have testing on device? – ρяσѕρєя K May 10 '12 at 11:41
  • when i use alarm manager to wake up camera feature it will not work . it gives fail to open camera service error. – user1345747 May 16 '12 at 04:59