메뉴 건너뛰기

OBG

Programming

JAVA/Android
2013.05.22 19:24

PackageBroadcastReceiver 구현

MoA
조회 수 593 추천 수 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 Views1748
    read more
  2. Deploying a Visual C++ Application (배포 방법)

    Date2012.08.02 CategoryAPI/MFC ByNaya Views635
    Read More
  3. 슬라이더 컨트롤에 툴팁 삽입 (동적 툴팁)

    Date2013.10.28 CategoryAPI/MFC ByMoA Views633
    Read More
  4. VC++6.0 에서 VC++ 2005로 변환할 경우 형변환 경고 대응방법

    Date2013.07.28 CategoryAPI/MFC ByMoA Views628
    Read More
  5. C++에서 base64로 인코딩

    Date2012.11.15 CategoryC/C++ ByNaya Views624
    Read More
  6. Data Conversions

    Date2013.07.28 CategoryC/C++ ByMoA Views623
    Read More
  7. fwrite(), fread()

    Date2013.07.28 CategoryC/C++ ByMoA Views622
    Read More
  8. 스레드(CreateThread), EVENT 동기화

    Date2013.07.28 CategoryAPI/MFC ByMoA Views617
    Read More
  9. SciPy and NumPy

    Date2013.12.23 CategoryPython ByMoA Views616
    Read More
  10. 자바스크립트 물리엔진 ㄷㄷ

    Date2014.03.10 CategoryTool/etc ByMoA Views614
    Read More
  11. [농장게임 만들기] 4. 펜스를 그리자

    Date2014.04.30 CategoryPython ByMoA Views605
    Read More
  12. __FILE__ __LINE__ __FUNCTION__ 등 매크로

    Date2014.01.02 CategoryC/C++ ByMoA Views602
    Read More
  13. Thread Programming

    Date2012.08.02 CategoryAPI/MFC ByNaya Views597
    Read More
  14. ChartFX 7.0 MFC에서 사용하기

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

    Date2013.05.22 CategoryJAVA/Android ByMoA Views593
    Read More
  16. fopen 함수가 Multi Thread 에서 안전한가?

    Date2013.07.28 CategoryC/C++ ByMoA Views588
    Read More
  17. 정신나간 정렬 알고리즘

    Date2015.10.13 CategoryC/C++ ByMoA Views579
    Read More
  18. R language 사이트

    Date2012.02.08 CategoryTool/etc By너울 Views571
    Read More
  19. 특정 자료형의 데이터를 binary(hex값, 2진수값)으로 변환

    Date2012.11.15 CategorySite ByNaya Views565
    Read More
  20. MFC TIP

    Date2013.07.28 CategoryAPI/MFC ByMoA Views562
    Read More
  21. 정적 배열과 STL vector 속도 비교

    Date2013.07.28 CategorySTL/Boost ByMoA Views559
    Read More
Board Pagination Prev 1 ... 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15
위로