public class mReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { Log.d("tag", "boot ok"); Intent i = new Intent(context, sampleActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } }Need Uses Permission : android.permission.RECEIVE_BOOT_COMPLETED
Jun 28, 2012
Start Activity When Boot Completed
Jun 7, 2012
edittext 특수문자 제한, 한글만 입력
// 영문 + 숫자 public InputFilter filterAlphaNum = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { Pattern ps = Pattern.compile("^[a-zA-Z0-9]*$"); if (!ps.matcher(source).matches()) { return ""; } return null; } }; // 한글 public InputFilter filterKor = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { Pattern ps = Pattern.compile("^[ㄱ-ㅣ가-힣]*$"); if (!ps.matcher(source).matches()) { return ""; } return null; } }; editText.setFilters(new InputFilter[]{filterAlphaNum});
패키지 정보 가져오기
ArrayList<PackageInfo> packages = new ArrayList<PackageInfo>(); PackageManager pm; void getPackeges() { pm = (PackageManager) this.getPackageManager(); List<PackageInfo> allPackages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS); for (int i = 0; i < allPackages.size(); i++) if (!isSystemApplication(allPackages.get(i))) packages.add(allPackages.get(i)); } boolean isSystemApplication(PackageInfo packinfo) { return (packinfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? true : false; }
Install, Uninstall 소스
Uri uri = Uri.fromParts("package", packageName, null); Intent i = new Intent(Intent.ACTION_DELETE, uri); startActivity(i);
Uri uri= Uri.fromParts("package", packageName , null); Intent i = new Intent(Intent.ACTION_PACKAGE_ADDED, uri); startActivity(i);
터치 좌표, 터치 다운 이벤트
button.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_UP: } return pressed; } });
Jun 5, 2012
screen capture
public void screenshot(View view) throws Exception { view.setDrawingCacheEnabled(true); Bitmap screenshot = Bitmap.createBitmap(view.getDrawingCache()); view.setDrawingCacheEnabled(false); if (screenshot == null) { Log.e("screencast", "error : could not get drawing cache..."); return; } File dir = Environment.getExternalStorageDirectory(); String baseName = "screencast"; String extention = ".jpg"; String filename = baseName + extention; try { File f = new File(dir, filename); f.createNewFile(); OutputStream outStream = new FileOutputStream(f); screenshot.compress(Bitmap.CompressFormat.JPEG, 80, outStream); outStream.flush(); outStream.close(); Log.d("screencast", "captured to " + f.getPath() + "(" + f.length() + "byte)"); } catch (IOException e) { e.printStackTrace(); } }
StartActivity, StartService
Intent i = new Intent(currentActivity.this, targetActivity.class); startActivity(i); Intent i = new Intent(currentActivity.this, targetService.class); startService(i);
Button setOnclickListener
button.setOnClickListener(new OnClickListener() { public void onClick(View v) {
} });
Jun 4, 2012
getLocalIPAddressList
private ArrayList<String> getLocalIPAddressList() { ArrayList<String> mAddress = new ArrayList<String>(); try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && (inetAddress instanceof Inet4Address)) { mAddress.add(inetAddress.getHostAddress().toString()); } } } } catch (SocketException e) { Log.e(TAG, "Fail to get IP Address : " + e); } return mAddress; }
Subscribe to:
Posts (Atom)