메뉴 건너뛰기

OBG

Programming

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 591 추천 수 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 Views1714
    read more
  2. [S/W 공학] 월-인원(man-month), LOC

    Date2013.09.23 CategoryTool/etc ByMoA Views521
    Read More
  3. [농장게임 만들기] 7. 농부 행동 추가

    Date2014.05.01 CategoryPython ByMoA Views528
    Read More
  4. [농장게임 만들기] 5. 플레이어를 추가하자

    Date2014.04.30 CategoryPython ByMoA Views532
    Read More
  5. Legacy MFC 어플리케이션을 MFC feature pack으로 포팅

    Date2013.07.30 CategoryAPI/MFC ByMoA Views539
    Read More
  6. 리스트 컨트롤 클릭 이벤트

    Date2013.06.12 CategoryAPI/MFC ByMoA Views540
    Read More
  7. 2048게임 높은 점수 얻기 위한 알고리즘

    Date2014.03.29 CategoryAlgorithm ByMoA Views547
    Read More
  8. 정적 배열과 STL vector 속도 비교

    Date2013.07.28 CategorySTL/Boost ByMoA Views558
    Read More
  9. MFC TIP

    Date2013.07.28 CategoryAPI/MFC ByMoA Views559
    Read More
  10. 특정 자료형의 데이터를 binary(hex값, 2진수값)으로 변환

    Date2012.11.15 CategorySite ByNaya Views562
    Read More
  11. R language 사이트

    Date2012.02.08 CategoryTool/etc By너울 Views571
    Read More
  12. 정신나간 정렬 알고리즘

    Date2015.10.13 CategoryC/C++ ByMoA Views573
    Read More
  13. fopen 함수가 Multi Thread 에서 안전한가?

    Date2013.07.28 CategoryC/C++ ByMoA Views585
    Read More
  14. ChartFX 7.0 MFC에서 사용하기

    Date2013.07.28 CategoryLibrary ByMoA Views588
    Read More
  15. PackageBroadcastReceiver 구현

    Date2013.05.22 CategoryJAVA/Android ByMoA Views591
    Read More
  16. Thread Programming

    Date2012.08.02 CategoryAPI/MFC ByNaya Views596
    Read More
  17. __FILE__ __LINE__ __FUNCTION__ 등 매크로

    Date2014.01.02 CategoryC/C++ ByMoA Views601
    Read More
  18. [농장게임 만들기] 4. 펜스를 그리자

    Date2014.04.30 CategoryPython ByMoA Views603
    Read More
  19. 자바스크립트 물리엔진 ㄷㄷ

    Date2014.03.10 CategoryTool/etc ByMoA Views613
    Read More
  20. 스레드(CreateThread), EVENT 동기화

    Date2013.07.28 CategoryAPI/MFC ByMoA Views614
    Read More
  21. Data Conversions

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