Merhablar,
Android Studio ile çekilen resmin SD Kart içine kaydedilmesini
istiyor ve dosya lokasyonunuve ismini belirlemek istiyorum. Bu
anlamda da aşağıdaki kodu buldum. Her ne kadar kodun başında SD kart
lokasyonunu bulacağı söylense de
"file:///storage/emulated/0/CSI/CSI0103-0015.jpg" şekliden bir yola
yazıyor. Bunu çözemedim. Bu diğer bir konu ama asıl önemlisi Android
5.1 tablette çalışan aşağıdaki fonksiyon Android 8 telefonda hata
vererek program kendini sonlandırıyor.
Hata mesajı da aşağıda.
private File getFile() {
String extStorageDirectory =
Environment.getExternalStorageDirectory().getAbsolutePath();
//Toast.makeText(getApplicationContext(),extStorageDirectory,
Toast.LENGTH_SHORT).show(); File folder =new File(extStorageDirectory+"/CSI");
if(!folder.exists())
{
folder.mkdir();
}
barkod = (EditText)findViewById(R.id.editTextPaketNo);
File resimDosyasi =new File(folder,barkod.getText().toString()+".jpg");
return resimDosyasi;
}
Hata mesajı:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.csisevkiyat, PID: 5676
java.lang.IllegalStateException: Could not execute method for
android:onClick
at
android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:6935)
at android.widget.TextView.performClick(TextView.java:12742)
at android.view.View$PerformClick.run(View.java:26211)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at
android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:6935)
at android.widget.TextView.performClick(TextView.java:12742)
at android.view.View$PerformClick.run(View.java:26211)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: android.os.FileUriExposedException:
file:///storage/emulated/0/CSI/CSI0103-0015.jpg exposed beyond app
through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1960)
at android.net.Uri.checkFileUriExposed(Uri.java:2356)
at
android.content.ClipData.prepareToLeaveProcess(ClipData.java:945)
at
android.content.Intent.prepareToLeaveProcess(Intent.java:10604)
at
android.content.Intent.prepareToLeaveProcess(Intent.java:10589)
at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1618)
at
android.app.Activity.startActivityForResult(Activity.java:4621)
at
android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at
android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at
android.app.Activity.startActivityForResult(Activity.java:4579)
at
android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at
com.example.csisevkiyat.MainActivity.resimCek(MainActivity.java:179)
at java.lang.reflect.Method.invoke(Native Method)
at
android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:6935)
at android.widget.TextView.performClick(TextView.java:12742)
at android.view.View$PerformClick.run(View.java:26211)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
V/MediaPlayer-JNI: native_finalize
release
Application terminated.
--
Kolay gelsin,
Mucip:)