/**
* Process가 실행중인지 여부 확인.
* @param context, packageName
* @return true/false
*/
public static boolean isRunningProcess(Context context, String packageName) {
boolean isRunning = false;
ActivityManager actMng = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> list = actMng.getRunningAppProcesses();
for(RunningAppProcessInfo rap : list)
{
if(rap.processName.equals(packageName))
{
isRunning = true;
break;
}
}
return isRunning;
}
BLOG ARTICLE 프로그래밍/Java | 69 ARTICLE FOUND
- 2020.03.06 안드로이드에서 Process 실행 여부 확인 함수 1
- 2020.03.06 현재날짜에서 Add day 구하는 함수
- 2020.03.05 유로 포함 환율 가져오는 함수
- 2020.03.05 HTTP 통신 자바 클래스
- 2020.03.05 [iBatis/myBatis] #와 $의 차이점
/*
현재날짜에서 Add day 구하는 함수
*/
public static String getAddDt(int day){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentDateandTime = sdf.format(new Date());
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, day);
String strDate = sdf.format(cal.getTime());
return strDate;
}
private String getExchageRate() throws Exception {
String rtnVal = "";
Communicator comm = new Communicator();
String url = "https://quotation-api-cdn.dunamu.com/v1/forex/recent?codes=FRX.KRWUSD";
String recv = comm.getHttpFromURL(url);
JSONArray jsonA = new JSONArray(recv);
JSONObject json = jsonA.getJSONObject(0);
rtnVal = String.valueOf(json.getDouble("basePrice"));
return rtnVal;
}
private String getExchageRateEURUSD() throws Exception {
String rtnVal = "";
Communicator comm = new Communicator();
String url = "https://quotation-api-cdn.dunamu.com/v1/forex/recent?codes=FRX.EURUSD";
String recv = comm.getHttpFromURL(url);
JSONArray jsonA = new JSONArray(recv);
JSONObject json = jsonA.getJSONObject(0);
rtnVal = String.valueOf(json.getDouble("basePrice"));
return rtnVal;
}
private String getExchageRateEURKRW() throws Exception {
String rtnVal = "";
Communicator comm = new Communicator();
String url = "https://quotation-api-cdn.dunamu.com/v1/forex/recent?codes=FRX.KRWEUR";
String recv = comm.getHttpFromURL(url);
JSONArray jsonA = new JSONArray(recv);
JSONObject json = jsonA.getJSONObject(0);
rtnVal = String.valueOf(1 / json.getDouble("basePrice"));
return rtnVal;
}
private String getExchageRateKRWEUR() throws Exception {
String rtnVal = "";
Communicator comm = new Communicator();
String url = "https://quotation-api-cdn.dunamu.com/v1/forex/recent?codes=FRX.KRWEUR";
String recv = comm.getHttpFromURL(url);
JSONArray jsonA = new JSONArray(recv);
JSONObject json = jsonA.getJSONObject(0);
rtnVal = String.valueOf(json.getDouble("basePrice"));
return rtnVal;
}
유로 포함 환율 가져오는 함수
HTTP 통신 자바클래스 입니다 (다양한 형태 함수 인터페이즈 제공)
사용법은 소스를 분석해서 사용하시기 바랍니다.
1. #는 쿼리가 수행될 때, 다음과 같이 된다
SELECT * FROM USER WHERE col = ?
parameter : [값] |
?에 bind된 값이 들어가게 된다.
이 쿼리의 컴파일 된 내용을 재사용 할 수 있고, 파라미터에 따라 대입해주므로 효율적이다.
내부적으로 preparedStatement 객체에서 ? 에 들어갈 파라미터의 값을 set 해줌으로써 사용이 된다.
* preparedStatement는 한번 수행한 쿼리를 캐싱하는 객체
사용 용도 >>
#일 경우, 값에 사용한다.
myBatis : 컬럼명 = #{값}
iBatis : 컬럼명 = #값#
* 쿼리에 작은 따옴표가 붙게 된다.
2. $는 쿼리가 수행될 때, 다음과 같이 된다
SELECT * FROM USER
WHERE col = 값 |
값이 넣어진 쿼리 자체로 수행이 된다.(상수)
즉, 문장 전체가 preparedStatement가 된다.
사용 용도 >>
$일 경우는 컬럼명이 동적으로 바뀌어야 할 때 사용한다. 또는 테이블명.
myBatis : ${컬럼명} = #{값}
iBatis : $컬럼명$ = #{값}
* 쿼리에 작은따옴표가 붙지 않는다.
값에 $를 사용하면 스트링의 경우 작은따옴표로 감싸지지 않기 때문에 에러 발생한다.
이렇게 사용하지 않으면 unknown column 이나 There is no readable property named 등등의 에러가 뜨게 된다