로그인

검색

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 4224 추천 수 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 Views15452
    read more
  2. 큰 수 구하기 알고리즘

    Date2012.08.02 CategoryAlgorithm ByNaya Views3302
    Read More
  3. Simple Add-On Wait Dialog in MFC

    Date2013.11.21 CategoryAPI/MFC ByMoA Views3305
    Read More
  4. [농장게임 만들기] 4. 펜스를 그리자

    Date2014.04.30 CategoryPython ByMoA Views3305
    Read More
  5. 구글 검색 알고리즘의 원리

    Date2012.08.02 CategoryAlgorithm ByNaya Views3308
    Read More
  6. [액션게임 만들기] 6. 게임 화면 출력

    Date2014.05.07 CategoryPython ByMoA Views3308
    Read More
  7. extern "C" 에 관하여

    Date2013.07.28 CategoryC/C++ ByMoA Views3315
    Read More
  8. [액션게임 만들기] 5. 장면 전환

    Date2014.05.07 CategoryPython ByMoA Views3321
    Read More
  9. Simplified Logger Class

    Date2013.07.28 CategoryC/C++ ByMoA Views3325
    Read More
  10. Redmine 설치

    Date2013.07.28 CategoryTool/etc ByMoA Views3329
    Read More
  11. MFC에서 생성,사용되는 파일 확장자

    Date2013.08.30 CategoryAPI/MFC ByMoA Views3335
    Read More
  12. GetLastInputInfo 함수

    Date2013.12.06 CategoryAPI/MFC ByMoA Views3337
    Read More
  13. Which Font is the default for MFC Dialog Controls

    Date2013.06.12 CategoryAPI/MFC ByMoA Views3345
    Read More
  14. 에디트 플러스, VS 2008 컴파일 환경 설정

    Date2013.07.28 CategoryTool/etc ByMoA Views3355
    Read More
  15. [액션게임 만들기] 10. 캐릭터 기술 구현

    Date2014.05.07 CategoryPython ByMoA Views3362
    Read More
  16. What does set -e mean in a bash script?

    Date2021.04.29 CategoryTool/etc ByOBG Views3365
    Read More
  17. 스레드 강좌 + CreateThread() 와 _beginthreadex() 함수의 차이

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3378
    Read More
  18. Windows 10 앱 개발(UWP)

    Date2015.10.13 CategoryAPI/MFC ByMoA Views3381
    Read More
  19. CString class

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3382
    Read More
  20. Start Something! - Windows 8 개발 공식 사이트

    Date2012.08.02 CategorySite ByNaya Views3390
    Read More
  21. fopen 함수가 Multi Thread 에서 안전한가?

    Date2013.07.28 CategoryC/C++ ByMoA Views3391
    Read More
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 15 Next
/ 15