어플이 마시멜로 전까지 잘 돌아가다가 이번에야 마시멜로 대응을 하기위해 코드를 수정하고 있습니다.
그래서 API 도 23으로 올리고 라이브러리 및 설정까지 마쳤는데요
제가 하려고 하는 부분은 어플에서 현재 나오는 부분을 자동캡쳐하여 갤러리에 자동 저장하는 기능입니다.
그러다 보니 갤러리에 읽기/쓰기 권한을 획득하여야 하는데 생각처럼 쉽지가 않네요ㅠㅠ
구글링에서 마시멜로 대응에 대해서 검색해보고 아래 소스내용과 같이 구성하였는데
아래 소스중에 빨강색 진한 부분이 오류가 나는거 같은데....뭐가 문제인지 잘 모르겠네요...ㅠㅠ
소스 내용입니다.
@SuppressLint("InlinedApi")
private void checkPermission() {
Toast.makeText(getBaseContext(), "캡쳐체크", Toast.LENGTH_LONG).show();
try
{
Log.i("capture_start", "1");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// Explain to the user why we need to write the permission.
Toast.makeText(this, "Read/Write external storage", Toast.LENGTH_SHORT).show();
}
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
1);
// MY_PERMISSION_REQUEST_STORAGE is an
// app-defined int constant
} else {
// 다음 부분은 항상 허용일 경우에 해당이 됩니다.
Toast.makeText(getBaseContext(), "캡쳐하기", Toast.LENGTH_LONG).show();
//capture_process();
}
}
catch(Exception ex)
{
//Toast.makeText(getBaseContext(), ex.toString(), Toast.LENGTH_LONG).show();
Log.i("capture_error", ex.toString());
}
}
오류 내용입니다.
05-23 02:50:10.668: E/AndroidRuntime(4814): FATAL EXCEPTION: main
05-23 02:50:10.668: E/AndroidRuntime(4814): Process: com.example.jangbu, PID: 4814
05-23 02:50:10.668: E/AndroidRuntime(4814): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jangbu/com.example.jangbu.DealView}: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.ActivityThread.-wrap11(ActivityThread.java)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.os.Handler.dispatchMessage(Handler.java:102)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.os.Looper.loop(Looper.java:148)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.ActivityThread.main(ActivityThread.java:5417)
05-23 02:50:10.668: E/AndroidRuntime(4814): at java.lang.reflect.Method.invoke(Native Method)
05-23 02:50:10.668: E/AndroidRuntime(4814): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
05-23 02:50:10.668: E/AndroidRuntime(4814): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-23 02:50:10.668: E/AndroidRuntime(4814): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
05-23 02:50:10.668: E/AndroidRuntime(4814): at com.example.jangbu.DealView.getData_myCompanyList(DealView.java:741)
05-23 02:50:10.668: E/AndroidRuntime(4814): at com.example.jangbu.DealView.onCreate(DealView.java:181)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.Activity.performCreate(Activity.java:6237)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
05-23 02:50:10.668: E/AndroidRuntime(4814): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
05-23 02:50:10.668: E/AndroidRuntime(4814): ... 9 more