2013년 1월 18일 금요일

AppWidget에서의 onEnabled() 재정의

스케쥴러가 메모리 부족 시 제거할 프로세스 선택할 때 선택되지 않도록 지정하는 용도로도 사용된다.
@Override
public void onEnabled(Context context) {
    PackageManager pm = context.getPackageManager();
    pm.setComponentEnabledSetting(
        new ComponentName("패키지명", ".클래스명"),
           PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
           PackageManager.DONT_KILL_APP
    );
}

2013년 1월 3일 목요일

Google Charts API를 이용한 QRCode 생성

private Bitmap makeQRCode(){
  String input = "http://m.naver.com";
  URL url;

  try{
    url = new URL("http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl=" 
    +  URLEncoder.encode(input, "UTF-8"));
    URLConnection conn = url.openConnection();
    conn.connect();
    InputStream is = conn.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);
    Bitmap bmp = BitmapFactory.decodeStream(bis);
    bis.close();
    is.close();
  
    return bmp;
  }catch(Exception e){
    e.printStackTrace();
    return null;
  }
}
[Google chart api]

cht=qr
chs=<size>
chl=<text to encode>
choe=<output encoding>