'안드로이드'에 해당되는 글 21건
- 2014.11.10 안드로이드 customAdapter ListView 단일선택 리스트뷰
- 2014.10.24 [안드로이드]애플리케이션을 설치하는 중에 알 수 없는 오류 코드('-505')가 발생했습니다. 7
- 2014.02.04 일반 pc용 phone screen sharing
- 2013.08.30 안드로이드] SharedPreferences 깔끔하게 사용하기
- 2013.03.21 안드로이드 소프트 키패드 화면 가림 방지 (키보드)
- 2013.03.11 안드로이드 sd 카드에 로그 저장 하기(덤프뜨기)
- 2013.02.21 안드로이드 text 그리기 text 라인
- 2011.06.28 안드로이드 에러 정리
안드로이드 5.0 롤리팝
애플리케이션을 설치하는 중에 알 수 없는 오류 코드('-505')가 발생했습니다.
해당 오류는
custom 퍼미션으로 인해 발생하므로
manifest의 해당 퍼미션을 제거 해주어야 한다.
adb 설치시 오류 메시지.
INSTALL_FAILED_DUPLICATE_PERMISSION perm=com.xx.XXXX
퍼미션 제거에도 정상적으로 되지 않을경우
adb unstall 로 해당 앱을 삭제한 후 앱을 재 설치 해본다.
자동 로그인 여부, 또는 설정에서 저장했던 값 등
앱이 종료되어도 보존되어야 하는 데이터를 저장할 때
흔히 SharedPreferences를 사용한다.
1 2 3 4 5 | SharedPreferences pref = mContext.getSharedPreferences(com.exam.pref, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putString( "key" , value); editor.commit(); |
보통 이런식으로 사용하는데 이는 키 값을 수정 할 일이 있거나
찾을 일이 있을 때 따로 키 목록을 작성해
놓은 곳이 없다면 나중에 관리가 힘들어지는 단점이 있다.
그래서 아예 Preference 클래스를 하나 만들어 두고 그 클래스에
int, String, boolean을 담고 꺼내는 getter, setter 매소드와
사용하는 키 값을 모두 선언하여
클래스에 점만 찍으면 키, 저장, 꺼내쓰기가 가능하도록 하였다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | public class RbPreference { private final String PREF_NAME = "com.rabiaband.pref" ; public final static String PREF_INTRO_USER_AGREEMENT = "PREF_USER_AGREEMENT" ; public final static String PREF_MAIN_VALUE = "PREF_MAIN_VALUE" ; private Context mContext; public RbPreference(Context c) { mContext = c.getApplicationContext(); } public void put(String key, String value) { SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putString(key, value); editor.commit(); } public void put(String key, boolean value) { SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putBoolean(key, value); editor.commit(); } public void put(String key, int value) { SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putInt(key, value); editor.commit(); } public String getValue(String key, String dftValue) { SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); try { return pref.getString(key, dftValue); } catch (Exception e) { return dftValue; } } public int getValue(String key, int dftValue) { SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); try { return pref.getInt(key, dftValue); } catch (Exception e) { return dftValue; } } public boolean getValue(String key, boolean dftValue) { SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE); try { return pref.getBoolean(key, dftValue); } catch (Exception e) { return dftValue; } } } |
위와 같이 상단에 각각 사용할 키를 선언하고 타입별로 같은 이름의 setter,getter 매소드를
만들어 놓으면 어디서든 위 클래스를 이용하여 해당키와 한가지 매소드로 원하는 작업 수행이 가능하다.
1 2 3 4 5 6 7 | RbPreference pref = new RbPreference( this ); // set pref.put(RbPreference.PREF_USER_AGREEMENT, true ); // get pref.getValue(RbPreference.PREF_USER_AGREEMENT, false ); |
이런식으로 사용된다.
출처 : http://muzesong.tistory.com/79
manifest의 activity 속성에 추가해준다
android:windowSoftInputMode="adjustResize|adjustPan"
android:windowSoftInputMode="설정값"
위의 소스를 EditText속성내에 추가 시키면 됩니다..
설정값 :
stateUnspecified : 키보드의 디폴트 설정값
stateUnchanged : 키보드의 마지막 상태로 유지
stateHidden : 사용자 액티비티 선택시 키보드 숨김
stateAlwaysHidden : 액티비티의 메인 윈도우가 입력 포커스를 가질 때 키보드는 항상 숨김
stateVisible : 사용자가 액티비티 메인 윈도우 앞으로 갈 때 키보드 보여짐
stateAlwayVisible : 사용자가 액티비티를 선택할 때 키보드를 보여줌
adjustUnspecified : 스크롤 할 수 있는 레이아웃 뷰드을 가지고 있다면 윈도우 크기 재조정, 메인윈도우의 디폴트 값
adjustResize : 스크린에 키보드 공간을 만들기 위해 메인 윈도우 크기를 재조정
adjustPan : 키보드 공간을 만들기 위해 메인 윈도우의 크기가 재조정 되지 않음
// 쓰기
FileOutputStream fos
= new FileOutputStream(Environment.getExternalStorageDirectory().toString() + "/" + "파일명.dump");
fos.write(buf); //byte[]
fos.close();
//읽기
File file = new File(Environment.getExternalStorageDirectory().toString() + "/" + "파일명.dump");
FileInputStream fis = new FileInputStream(file);
int length = (int) file.length();
byte[] readBuf = new byte[length];
fis.read(readBuf);
fis.close();
package com.example.textpaint; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.TextView; public class MainActivity extends Activity { private TextView mPaintText; private Paint textPaint, strokePaint, textPaint2, strokePaint2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); initPaint(); setContentView(new MyView(getApplicationContext())); } private void initPaint() { int textSize = 100; textPaint = new Paint(); textPaint.setAntiAlias(true); textPaint.setColor(Color.WHITE); textPaint.setTextSize(textSize); strokePaint = new Paint(); strokePaint.setAntiAlias(true); strokePaint.setTextSize(textSize); strokePaint.setColor(Color.BLACK); strokePaint.setStyle(Paint.Style.STROKE); strokePaint.setStrokeWidth(4); int textSize2 = 50; textPaint2 = new Paint(); textPaint2.setAntiAlias(true); textPaint2.setColor(Color.BLUE); textPaint2.setTextSize(textSize2); strokePaint2 = new Paint(); strokePaint2.setAntiAlias(true); strokePaint2.setTextSize(textSize2); strokePaint2.setColor(Color.BLACK); strokePaint2.setStyle(Paint.Style.STROKE); strokePaint2.setStrokeWidth(4); } class MyView extends View{ public MyView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); String text = "48.2"; canvas.drawText(text, 100, 100, strokePaint); canvas.drawText(text, 100, 100, textPaint); String text2 = "%"; canvas.drawText(text2, 320, 100, strokePaint2); canvas.drawText(text2, 320, 100, textPaint2); // canvas.drawText(text, x, y, strokePaint); // canvas.drawText(text, x, y, textPaint); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
manifest.xml에 동일한<activity>가 두개 이상 있을때 발생하는 에러
06-28 13:34:25.644: ERROR/Launcher(10360): Launcher does not have the permission to launch Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=mrsohn.CTSave/.CTMainActivity }. Make sure to create a MAIN intent-filter for the corresponding activity or use the exported attribute for this activity.
안드로이드 프로젝트 빌드중에 에러가 발생할수 있다.
해당경우는 manifest.xml에 등록된 <receiver>로 등록된 클래스의 경로가 올바르지 못할때 발생한다
경로를 잘 잡아주도록 한다
06-29 11:08:45.824: ERROR/AndroidRuntime(1898): /system/csc/customer.xml ==> cannot open file
06-29 11:08:45.824: ERROR/AndroidRuntime(1898): /system/csc/feature.xml ==> cannot open file
06-29 11:08:46.059: WARN/ActivityManager(252): No content provider found for:
06-29 11:08:46.078: WARN/ActivityManager(252): No content provider found for:
06-29 11:08:46.086: WARN/PackageParser(252): /data/app/vmdl1081128854.tmp (at Binary XML file line #29): <receiver> does not have valid android:name