'ACTION_PACKAGE_ADDED'에 해당되는 글 1건

  1. 2011.12.13 BroadcastReceiver
Programming/Android2011.12.13 09:30
BroadcastReceiver 예제입니다.

앱이 추가되고 삭제될때 receive 하는 예제입니다.
package com.yhg.sample;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class PackageReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent itt) {
		String packageName = itt.getData().getSchemeSpecificPart();
		String action = itt.getAction();
		
		if(action.equals(Intent.ACTION_PACKAGE_ADDED)){
			Log.d("ADDED",packageName);
		}
		else if(action.equals(Intent.ACTION_PACKAGE_REMOVED)){
			Log.d("REMOVED",packageName);
		}
	}

}

package com.yhg.sample;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class SampleActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        this.registerReceiver(new PackageReceiver(), new IntentFilter(Intent.ACTION_PACKAGE_ADDED));
    }
}




    

    
        
            
                

                
            
        
        
        
            
                
                
                
            
        
    




 
 
신고
Posted by 초프(초보 프로그래머)