2014-03-04 5 views
-1

내가 원하는 것은 사용자 개입없이 기능을 수행 할 수있는 응용 프로그램을 만드는 것입니다. 장치의 응용 프로그램 페이지에 appicon이 없어야합니다. 설치 후 사용자는 장치에서 실행중인 응용 프로그램을 인식하지 않아도됩니다. 데모 애플리케이션에서 런처 없음 활동을 시도했지만 애플리케이션 코드가 실행되지 않고 있으며 이는 명백합니다. 이 작업을 수행 할 수있는 방법이 있습니까? 이해가 되니?은 백그라운드에서 응용 프로그램을 모니터링하고 사용자가 보이지 않는 응용 프로그램을 모니터링하는 방법입니다.

답변

5

네, 가능하고 많은 의미가 있습니다. 그러나 예를 들어, 할 일이 많이 필요합니다.

1). 사용자가 모바일 또는 장치를 다시 시작할 때마다 앱이 자동으로 시작되도록 부팅 시작 방법을 의미해야합니다.

<application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <receiver android:name=".OnBootReceiver" > 
      <intent-filter 
       android:enabled="true" 
       android:exported="false" > 
       <action android:name="android.intent.action.USER_PRESENT" /> 
      </intent-filter> 
     </receiver> 
     <receiver android:name=".OnGPSReceiver" > 
     </receiver> 

2). 분명히 첫 번째 활동 인 런처 모드가없는 앱을 만든 다음 두 번째 활동을 활동이 아닌 서비스로 호출해야합니다.

기본적으로 이와 같은 것을 만들어야합니다.

public class AppService extends WakefulIntentService{ 
     // your stuff goes here 
} 

그리고 mainActivity에서 호출하는 서비스는 다음과 같이 정의합니다.

Intent intent = new Intent(MainActivity.this, AppService.class); 
startService(intent); 
hideApp(getApplicationContext().getPackageName()); 

hideApp는 // mainActivity 외부를 사용합니다.

private void hideApp(String appPackage) { 
     ComponentName componentName = new ComponentName(appPackage, appPackage 
       + ".MainActivity"); 
     getPackageManager().setComponentEnabledSetting(componentName, 
       PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 
       PackageManager.DONT_KILL_APP); 
    } 

3). 그런 다음 매니페스트에서 아래와 같이이 서비스를 정의하십시오.

<service android:name=".AppService" > 
     </service> 

편집

WakefulIntentService는 새로운 추상 클래스입니다. 아래에서 확인하십시오. 그래서 새로운 자바 파일을 만들고 그것에 beloe 코드를 붙여 넣으십시오.

abstract public class WakefulIntentService extends IntentService { 
    abstract void doWakefulWork(Intent intent); 

    public static final String LOCK_NAME_STATIC = "test.AppService.Static"; 
    private static PowerManager.WakeLock lockStatic = null; 

    public static void acquireStaticLock(Context context) { 
     getLock(context).acquire(); 
    } 

    synchronized private static PowerManager.WakeLock getLock(Context context) { 
     if (lockStatic == null) { 
      PowerManager mgr = (PowerManager) context 
        .getSystemService(Context.POWER_SERVICE); 
      lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
        LOCK_NAME_STATIC); 
      lockStatic.setReferenceCounted(true); 
     } 
     return (lockStatic); 
    } 

    public WakefulIntentService(String name) { 
     super(name); 
    } 

    @Override 
    final protected void onHandleIntent(Intent intent) { 
     doWakefulWork(intent); 
     //getLock(this).release(); 
    } 
} 
+0

내 데모 앱에서 'WakefulIntentService'가 해결되지 않았습니다. 그것을 참조하는 방법을 정의 해 주시겠습니까? –

+0

@SureshSharma, 내 편집을 확인하십시오. – InnocentKiller

+0

hideApp도 MainActivity에서 해결되지 않고 MainActivity에 대해 manifest에서 어떻게 선언 될지 모릅니다. –