로그인

검색

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 619 추천 수 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 2472
147 Python [첫게임 만들기] 8. Win or Lose file MoA 2013.11.21 480
146 C/C++ RAND_MAX 2 MoA 2014.01.19 478
145 JAVA/Android 시스템 분석을 위한 쉘 명령어 MoA 2013.05.28 475
144 API/MFC GetLastInputInfo 함수 MoA 2013.12.06 475
143 Python [액션게임 만들기] 9. 캐릭터 액션 구현 2 MoA 2014.05.07 475
142 Library Google의 C++ 라이브러리 Naya 2012.08.02 470
141 API/MFC 태스크 대화상자 (Task Dialog) MoA 2013.10.22 469
140 Site Great summary cheat sheet (OpenCV) MoA 2013.01.04 467
139 API/MFC WaitForSingleObject와의 삽질.. MoA 2013.07.28 466
138 API/MFC Simple Add-On Wait Dialog in MFC MoA 2013.11.21 465
137 API/MFC CFormView 너울 2012.01.09 459
136 API/MFC 후킹 링크 MoA 2013.07.28 458
135 Python Embedding Python in C/C++ MoA 2013.12.23 457
134 Python [첫게임 만들기] 5. 적을 생성하자 file MoA 2013.11.21 454
133 Tool/etc Visual Studio Debug Tips MoA 2013.02.19 452
132 C/C++ C Runtime 환경의 메모리 릭 잡는 방법 (Memory leak) Naya 2012.08.02 450
131 API/MFC 비주얼 스튜디오 2005 단축키 MoA 2013.07.28 449
130 API/MFC 스레드 강좌 + CreateThread() 와 _beginthreadex() 함수의 차이 MoA 2013.07.28 444
129 Tool/etc Redmine 설치 MoA 2013.07.28 444
128 Tool/etc Quake 3 source code and review MoA 2014.01.15 435
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 15 Next
/ 15