2012-06-08 2 views
0

응용 프로그램을 시작하지 않고 서비스를 시작할 수 있습니까? 매시간마다 응용 프로그램의 데이터를 새로 고쳐야합니다. 응용 프로그램에 사용자가 없으면 어떻게 할 수 있습니까?응용 프로그램을 시작하지 않고 Android 서비스를 시작 하시겠습니까?

+0

가능한 복제본 - http://stackoverflow.com/questions/2127044/how-to-start-android-service-on-installation 하지만 ... 설치 후 서비스를 시작할 수있는 직접적인 방법은 없습니다. 나는 거기에 언급 된 해결책을 시도하지 않았으므로 판단 할 수 없다. –

답변

5

부팅 할 때 서비스를 시작할 수 있습니다. 당신의 요소에서

1) : 당신은 당신의 AndroidManifest.xml 파일에 다음 필요 당신의 요소에서

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

2) (대한 완전한 [또는 상대] 클래스 이름을 사용하십시오 당신의 브로드 캐스트 리시버) : MyBroadcastReceiver.java에서

<receiver android:name="com.example.MyBroadcastReceiver"> 
<intent-filter> 
    <action android:name="android.intent.action.BOOT_COMPLETED" /> 
</intent-filter> 

:

package com.example; 

    public class MyBroadcastreceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Intent startServiceIntent = new Intent(context, MyService.class); 
     context.startService(startServiceIntent); 
    } 
    } 
1

예 가능합니다.

이렇게 다른 방법을 읽을 수 있습니다 here.

관련 문제