괴도군의 블로그

[android]나의앱에서 다른 어플 설치,삭제,변경 이벤트 받기 본문

#프로그래밍/Android

[android]나의앱에서 다른 어플 설치,삭제,변경 이벤트 받기

괴도군 2015. 12. 8. 16:21
반응형

나의 앱에서 다른 앱을 설치하고 삭제하고 업데이트할때 사용하는 구조입니다.

설치, 제거코드는 목록의 다른글을 참조하시고


먼저 BroadcaseReceiver를 상속받는 클래스를 만듭니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class ApplicationBroadcast extends BroadcastReceiver {
 
    private static final String TAG = "PACKAGE_OBSERVER";
    @Override
    public void onReceive(Context context, Intent intent) {
 
        Log.v(TAG, "intent : "+intent);
        Log.v(TAG, "action : "+intent.getAction());
        Log.v(TAG, "data : "+intent.getData());
 
    }
 
}
 
 
 

cs

AndroidManifest.xml파일에서 코드를 추가합니다

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<receiver android:name=".application.ApplicationBroadcast">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED"/>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_CHANGED"/>
                <action android:name="android.intent.action.PACKAGE_REPLACED"/>
                <action android:name="android.intent.action.PACKAGE_DATA_CLEARED"/>
                <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH"/>
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
                <action android:name="android.intent.action.PACKAGE_NEEDS_VERIFICATION"/>
                <action android:name="android.intent.action.PACKAGE_RESTARTED"/>
                <action android:name="android.intent.action.PACKAGE_VERIFIED"/>
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>
 
 
 
cs

어플리케이션안에만 넣어주면됩니다.

액티비티안에다 넣지마세요..


위에 액션들을 다 넣어주실 필요는없고 밑에 써놓은 번호에 맞게 넣어주시면 됩니다.

그리고.. 설치 제거코드로 테스트해보시면.. 잘나옵니다.  폰마다 다르겠지만 몇초 걸리는것 같네요

1. 앱 설치시 이벤트

android.intent.action.PACKAGE_ADDED


2.앱 삭제시 이벤트

android.intent.action.PACKAGE_REMOVED

android.intent.action.PACKAGE_FULLY_REMOVED


3.앱 재설치 및 업데이트 이벤트

android.intent.action.PACKAGE_REMOVED

android.intent.action.PACKAGE_REPLACED

android.intent.action.PACKAGE_CHANGED (com.google.android.gms 패키지명이 뜨는걸보니 시스템쪽인듯..)



참고.. ( http://developer.android.com/intl/ko/reference/android/content/Intent.html )

StringACTION_PACKAGE_ADDEDBroadcast Action: A new application package has been installed on the device.
StringACTION_PACKAGE_CHANGEDBroadcast Action: An existing application package has been changed (e.g.
StringACTION_PACKAGE_DATA_CLEAREDBroadcast Action: The user has cleared the data of a package.
StringACTION_PACKAGE_FIRST_LAUNCHBroadcast Action: Sent to the installer package of an application when that application is first launched (that is the first time it is moved out of the stopped state).
StringACTION_PACKAGE_FULLY_REMOVEDBroadcast Action: An existing application package has been completely removed from the device.
StringACTION_PACKAGE_INSTALLThis constant was deprecated in API level 14. This constant has never been used.
StringACTION_PACKAGE_NEEDS_VERIFICATIONBroadcast Action: Sent to the system package verifier when a package needs to be verified.
StringACTION_PACKAGE_REMOVEDBroadcast Action: An existing application package has been removed from the device.
StringACTION_PACKAGE_REPLACEDBroadcast Action: A new version of an application package has been installed, replacing an existing version that was previously installed.
StringACTION_PACKAGE_RESTARTEDBroadcast Action: The user has restarted a package, and all of its processes have been killed.
StringACTION_PACKAGE_VERIFIEDBroadcast Action: Sent to the system package verifier when a package is verified.



반응형
Comments