로그인

검색

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 4227 추천 수 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 Views15453
    read more
  2. MFC 리본 사용하기 (아이콘 제작 포함)

    Date2012.02.09 CategoryAPI/MFC By너울 Views6406
    Read More
  3. MFC 클래스 멤버함수 설명서

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3729
    Read More
  4. MFC 클래스간 통신

    Date2012.08.02 CategoryAPI/MFC ByNaya Views4289
    Read More
  5. MFC, CHM파일 연동 (context help)

    Date2012.04.16 CategoryAPI/MFC By너울 Views3769
    Read More
  6. MFC기반의 CSocket 사용 방법과 예제

    Date2013.07.28 CategoryAPI/MFC ByMoA Views3753
    Read More
  7. MFC로 그림 그리기

    Date2012.08.02 CategoryAPI/MFC ByNaya Views2809
    Read More
  8. MFC에서 생성,사용되는 파일 확장자

    Date2013.08.30 CategoryAPI/MFC ByMoA Views3335
    Read More
  9. Mixture of Experts - Part 2

    Date2024.04.14 CategoryLLM ByOBG Views2141
    Read More
  10. MSCOMM32.OCX 등록

    Date2011.10.17 CategoryAPI/MFC By너울 Views3969
    Read More
  11. Numpy의 axis 변경

    Date2023.06.09 CategoryPython ByOBG Views3298
    Read More
  12. Office 스타일의 리본바 만드는 법

    Date2012.01.12 CategoryAPI/MFC By너울 Views3055
    Read More
  13. ofstream ifstream

    Date2013.07.28 CategoryC/C++ ByMoA Views3528
    Read More
  14. OpenCV 이용한 템플릿 매칭

    Date2014.01.16 CategoryPython ByMoA Views3921
    Read More
  15. OS in 1,000 Lines

    Date2025.01.14 CategoryTool/etc ByOBG Views1879
    Read More
  16. OS 개발에 관한 작은 책

    Date2025.03.24 CategoryTool/etc ByOBG Views1440
    Read More
  17. PackageBroadcastReceiver 구현

    Date2013.05.22 CategoryJAVA/Android ByMoA Views4227
    Read More
  18. PEFT: Parameter-Efficient Fine-Tuning of Billion-Scale Models on Low-Resource Hardware

    Date2024.04.15 CategoryLLM ByOBG Views1681
    Read More
  19. PHP: 잘못된 디자인의 프랙탈

    Date2016.07.10 CategorySite ByMoA Views3460
    Read More
  20. Play Super Mario Bros with a Double Deep Q-Network

    Date2022.09.15 CategoryDeeplearning ByOBG Views2581
    Read More
  21. PM2를 활용한 Node.js 무중단 서비스하기

    Date2023.03.09 Category서버 ByOBG Views2217
    Read More
Board Pagination Prev 1 ... 3 4 5 6 7 8 9 10 11 12 ... 15 Next
/ 15