2012-10-11 4 views
2

안녕하세요, 저는 응용 프로그램을 분석 할 수 있도록 응용 프로그램을 설치하려고합니다. 그리고이 예제를 사용하여 현재 응용 프로그램에서 패키지 설치를 수신 대기하는 stackoverflow에서 찾았지만 아무 것도 일어나지 않습니다. logcat.의도 PACKAGE_ADDED가 등록되지 않았습니다

void registerReceiver() { 
    IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); 
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED); 
    filter.addAction(Intent.ACTION_PACKAGE_CHANGED); 
    filter.addDataScheme("package"); 

} 

public void onReceive(Context context, Intent intent) { 
    String actionStr = intent.getAction(); 
    if (Intent.ACTION_PACKAGE_ADDED.equals(actionStr)) { 
     Uri data = intent.getData(); 
     String pkgName = data.getEncodedSchemeSpecificPart(); 
     //handle package adding... 
     Log.i("Logging Service", pkgName); 

    } 

} 

<receiver android:name="RealTimeActivity"> 
    <intent-filter> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <action android:name="android.intent.action.PACKAGE_ADDED" /> 
    <action android:name="android.intent.action.PACKAGE_CHANGED" /> 
    <action android:name="android.intent.action.PACKAGE_INSTALL" /> 
    <action android:name="android.intent.action.PACKAGE_REMOVED" /> 
    <action android:name="android.intent.action.PACKAGE_REPLACED" /> 
    </intent-filter> 
</receiver> 


<uses-permission android:name="android.permission.BROADCAST_PACKAGE_ADDED" /> 
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_CHANGED" /> 
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" /> 
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_INSTALL" /> 
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" /> 
+0

(일부 응용 프로그램은 특정 방송을 수신 할 수 있도록, 살아 응용 프로그램 프로세스를 유지하기 위해 더미 끈적 서비스를 실행) : 동일한/현재 응용 프로그램 패키지에있는 경우 name = ". RealTimeActivity"> 또는 다른 위치에있는 경우

답변

2

Android 3.1 이후의 브로드 캐스트 동작 변경으로 인해 앱 설치/제거 의도를 받기 전에 앱을 시작해야합니다. 가부코의 대답 in this thread을 참조하십시오.

다음 수신기는 Android 4.0 기기에서 나에게 적합합니다 (앱에서 활동이 있고 처음으로 활동을 시작합니다. 즉, 앱도 시작되고 수신자는 브로드 캐스트를 수신 할 수 있음).

<receiver android:name=".MyReceiver"> 
    <intent-filter> 
     <action android:name="android.intent.action.PACKAGE_ADDED" /> 
     <action android:name="android.intent.action.PACKAGE_CHANGED" /> 
     <action android:name="android.intent.action.PACKAGE_REMOVED" /> 
     <data android:scheme="package" /> 
    </intent-filter> 
</receiver> 

난 당신이 <수신기 안드로이드와 같은 매니페스트 파일에 수신기의 경로를 제공하기 위해 그리워 생각

+0

그래서 더미 서비스는 내부에 아무것도없는 서비스 일뿐입니다. – rexer

관련 문제