로그인

검색

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 4272 추천 수 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를 반드시 설정해야 한다.

?

  1. Programming 게시판 관련

    Date2014.11.01 CategoryTool/etc ByMoA Views15458
    read more
  2. 어셈블리어 컴파일 - 기초

    Date2012.08.02 CategoryTool/etc ByNaya Views3495
    Read More
  3. Essential C 링크

    Date2011.08.31 CategoryC/C++ By너울 Views3489
    Read More
  4. printf Type Field Characters

    Date2012.02.23 CategoryC/C++ By너울 Views3483
    Read More
  5. PHP: 잘못된 디자인의 프랙탈

    Date2016.07.10 CategorySite ByMoA Views3474
    Read More
  6. __cdecl , __pascal, __stdcall

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3469
    Read More
  7. [액션게임 만들기] 7. 캐릭터 출력

    Date2014.05.07 CategoryPython ByMoA Views3453
    Read More
  8. CFormView

    Date2012.01.09 CategoryAPI/MFC By너울 Views3450
    Read More
  9. [GUI] wxPython 기본 프로그램

    Date2013.11.30 CategoryPython ByMoA Views3450
    Read More
  10. 프로세스 - 생성과 종료 그리고 이것 저것

    Date2011.10.12 CategoryAPI/MFC By너울 Views3449
    Read More
  11. 자바스크립트 물리엔진 ㄷㄷ

    Date2014.03.10 CategoryTool/etc ByMoA Views3448
    Read More
  12. 고양이 움직이기

    Date2013.11.08 CategoryPython ByMoA Views3447
    Read More
  13. CreateThread, ExitThread, GetExitCodeThread ...

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3442
    Read More
  14. 고양이 밖으로 못나가게 하기

    Date2013.11.10 CategoryPython ByMoA Views3426
    Read More
  15. [농장게임 만들기] 8. HUD에 텍스트를 표시하자

    Date2014.05.01 CategoryPython ByMoA Views3425
    Read More
  16. Machine Learning for Video Games

    Date2015.07.27 CategoryTool/etc ByMoA Views3422
    Read More
  17. [농장게임 만들기] 2. Nubcake Farms 클래스 분석

    Date2014.04.26 CategoryPython ByOBG Views3420
    Read More
  18. C++11 A cheat sheet

    Date2013.08.21 CategoryC/C++ ByMoA Views3414
    Read More
  19. 에디트 플러스, VS 2008 컴파일 환경 설정

    Date2013.07.28 CategoryTool/etc ByMoA Views3411
    Read More
  20. UI Guidelines

    Date2014.03.11 CategoryTool/etc ByMoA Views3401
    Read More
  21. Data Conversions

    Date2013.07.28 CategoryC/C++ ByMoA Views3398
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15