로그인

검색

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 4835 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 게시글 수정 내역 댓글로 가기 인쇄

 private class PackageBroadcastReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {

   if (intent != null) {
    String packageName = intent.getData().getSchemeSpecificPart();
    Log.w(TAG, "onReceive() packageName : " + packageName);

    if (Intent.ACTION_PACKAGE_ADDED.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_ADDED");
    } else if (Intent.ACTION_PACKAGE_CHANGED.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_CHANGED");
    } else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_DATA_CLEARED");
    } else if (Intent.ACTION_PACKAGE_INSTALL.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_INSTALL");
    } else if (Intent.ACTION_PACKAGE_REMOVED.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_REMOVED");
    } else if (Intent.ACTION_PACKAGE_REPLACED.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_REPLACED");
    } else if (Intent.ACTION_PACKAGE_RESTARTED.equalsIgnoreCase(intent.getAction())) {
     Log.w(TAG, "onReceive() ACTION_PACKAGE_RESTARTED");
    }
   }
  }
 }

 

registerReceiver

 

  mPackageBroadcastReceiver = new PackageBroadcastReceiver();
  IntentFilter intentFilter = new IntentFilter();
  intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
  intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
  intentFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
  intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
  intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
  intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
  intentFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
  intentFilter.addDataScheme("package");
  registerReceiver(mPackageBroadcastReceiver, intentFilter);

 

unregisterReceiver

 

  if (mPackageBroadcastReceiver != null) {
   try {
    unregisterReceiver(mPackageBroadcastReceiver);
    mPackageBroadcastReceiver = null;
   } catch (Exception e) {
    e.printStackTrace();
   }
  }

manifest 등록

 

        <receiver android:name=".PackageBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.ACTION_PACKAGE_ADDED" />
                <action android:name="android.intent.action.ACTION_PACKAGE_CHANGED" />
                <action android:name="android.intent.action.ACTION_PACKAGE_DATA_CLEARED" />
                <action android:name="android.intent.action.ACTION_PACKAGE_INSTALL" />
                <action android:name="android.intent.action.ACTION_PACKAGE_REMOVED" />
                <action android:name="android.intent.action.ACTION_PACKAGE_REPLACED" />
                <action android:name="android.intent.action.ACTION_PACKAGE_RESTARTED" />
                <data android:scheme="package"/>
            </intent-filter>
        </receiver> 

주의 : data scheme를 반드시 설정해야 한다.

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 Tool/etc Programming 게시판 관련 2 MoA 2014.11.01 18015
101 Web [Javascript] 비동기, Promise, async, await 확실하게 이해하기 OBG 2022.05.27 2941
100 Web How to send dynamic charts with a Slack bot OBG 2022.05.31 2717
99 서버 Building Pitaya, Wildlife’s own scalable game server framework OBG 2022.06.07 2956
98 Database What's the difference between comma separated joins and join on syntax in MySQL? OBG 2022.06.09 2997
97 서버 Golang Tutorial for Node.js Developers, Part I.: Getting started OBG 2022.06.16 2546
96 Tool/etc "Node.js를 떠나며" - express를 만든 TJ의 글 OBG 2022.06.23 3067
95 Deeplearning 파이썬 머신러닝 무료 강의 (7시간) OBG 2022.07.06 3735
94 Deeplearning 직접 보고 추천하는 머신러닝 & 딥러닝 & 수학 총정리(2022) OBG 2022.07.24 7809
93 Deeplearning 강화학습 학습 관련 정리 OBG 2022.08.10 3122
92 Deeplearning Keras를 활용한 주식 가격 예측 OBG 2022.09.02 2779
91 Tool/etc AWS 망 분리하기 OBG 2022.09.06 3140
90 Deeplearning RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED ... OBG 2022.09.06 3584
89 Web Creating A Fixed-Length Queue In JavaScript Using Arrays OBG 2022.09.14 2533
88 Deeplearning Play Super Mario Bros with a Double Deep Q-Network OBG 2022.09.15 2915
87 Python 2048 Game in Python OBG 2022.09.22 3274
86 Deeplearning Stable Diffusion OBG 2022.09.27 3619
85 Deeplearning The State of AI & Art 2022 1 OBG 2022.10.06 3024
84 Tool/etc AWS VPC 피어링 OBG 2022.11.03 3393
83 Deeplearning 시계열 데이터 예측 모델 OBG 2022.11.08 2921
82 Web 카카오톡 웹버전 만들기 OBG 2022.11.09 3057
Board Pagination Prev 1 ... 7 8 9 10 11 12 13 14 15 16 17 Next
/ 17