본문 바로가기

Android125

Android 앱 캐시 및 데이터 내가 원하는것만 골라서 삭제해보자. public static void clearApplicationData(Context context) { File cache = context.getCacheDir(); File appDir = new File(cache.getParent()); if (appDir.exists()) { String[] children = appDir.list(); for (String list : children) { Log.d("캐시삭제 ", list); if(list.equals("shared_prefs")) continue; deleteDir(new File(appDir, list)); } } } private static boolean deleteDir(File dir) { if (dir != null && di.. 2021. 8. 20.
android11 intent 패키지명으로 외부 앱 실행 시 안되는 현상 try{ Intent intent = getPackageManager().getLaunchIntentForPackage(packageName); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } catch (Exception e){ e.printStackTrace(); String url = "market://details?id=" + packageName; Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); } 원래는 이렇게 하여서 패키지명으로 외부앱을 실행했습니다! 근데 안드로이드 11을 타겟팅하신다고 하시면 메니페스트에서 하나 추가해주.. 2021. 7. 22.
Android (타이머) 시간마다 실행하기 (주기별 실행) Timer timer = new Timer(); TimerTask timerTask = new TimerTask() { @Override public void run() { //5초마다 실행 } }; timer.schedule(timerTask,0,5000); ms단위로 적어주시면 됩니다. 2021. 7. 2.
Android polling(폴링) 백그라운드에서 API통신 해보기. 안드로이드에서 백그라운드딴에서 앱이 종료되도 주기적으로 서버와 통신하며 상태를 확인해보는 작업을 해볼게요. 프로젝트에서 오른쪽 클릭해서 new - Service - Service 해서 서비스를 상속받는 클래스를 만들어주세요 (안드로이드 4대 컴포넌트!!) public class MyService extends Service { public MyService() { } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. throw new UnsupportedOperationException("Not yet implemented"); } } 이게 초기상태로 작성된 서비스.. 2021. 7. 2.