로그인

검색

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 1077 추천 수 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 Views5340
    read more
  2. 안드로이드 초간단 리스트뷰 사용법

    Date2013.04.10 CategoryJAVA/Android ByMoA Views714
    Read More
  3. PackageBroadcastReceiver 구현

    Date2013.05.22 CategoryJAVA/Android ByMoA Views1077
    Read More
  4. 리스트뷰에 체크박스 추가 예제

    Date2013.05.24 CategoryJAVA/Android ByMoA Views1421
    Read More
  5. logcat 사용법

    Date2013.05.28 CategoryJAVA/Android ByMoA Views4054
    Read More
  6. 시스템 분석을 위한 쉘 명령어

    Date2013.05.28 CategoryJAVA/Android ByMoA Views1076
    Read More
  7. Which Font is the default for MFC Dialog Controls

    Date2013.06.12 CategoryAPI/MFC ByMoA Views833
    Read More
  8. 리스트 컨트롤 클릭 이벤트

    Date2013.06.12 CategoryAPI/MFC ByMoA Views1173
    Read More
  9. CPaneDialog의 context menu 안뜨게 하기

    Date2013.06.12 CategoryAPI/MFC ByMoA Views1232
    Read More
  10. What to use instead of “addPreferencesFromResource” in a PreferenceActivity?

    Date2013.06.13 CategoryJAVA/Android ByMoA Views1152
    Read More
  11. CDockablePane 배경화면 회색으로 변경

    Date2013.07.11 CategoryAPI/MFC ByMoA Views1465
    Read More
  12. CDockablePane 버튼 비활성화 문제

    Date2013.07.17 CategoryAPI/MFC ByMoA Views2055
    Read More
  13. CPaneDialog 초기화 (OnInitDialog)

    Date2013.07.18 CategoryAPI/MFC ByMoA Views1530
    Read More
  14. Property Sheet의 버튼 속성 변경하기

    Date2013.07.25 CategoryAPI/MFC ByMoA Views1127
    Read More
  15. 다이얼로그 resize 시 child control의 그래픽 깨짐 해결

    Date2013.07.25 CategoryAPI/MFC ByMoA Views1912
    Read More
  16. UpdateWindow 함수에 대하여..

    Date2013.07.25 CategoryAPI/MFC ByMoA Views1040
    Read More
  17. InvalidateRect 함수, flag성 메세지

    Date2013.07.25 CategoryAPI/MFC ByMoA Views954
    Read More
  18. UpdateData(TRUE) or UpdateData(FALSE) 구분

    Date2013.07.28 CategoryAPI/MFC ByMoA Views1037
    Read More
  19. extern "C" 에 관하여

    Date2013.07.28 CategoryC/C++ ByMoA Views1188
    Read More
  20. DLL 이란

    Date2013.07.28 CategoryAPI/MFC ByMoA Views1420
    Read More
  21. High-speed Charting Control

    Date2013.07.28 CategoryLibrary ByMoA Views1002
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15