I am trying to copy SD card image file from my pc using InputStream, OutputStream, FileInputStream and FileOutputStream. But the error comes at FileOutputStream as the values we are passing to this is desktop folder. The code is
File file = new File(path); \\ where 'path' is the sd card image file path
File destFolder = new File("D:\\images\\"); \\ I know this path is not correct. IP address of PC is missing here
InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFolder);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
When we can copy files from one system to another system, which are on same network, why can't we do that from mobile to pc when they are also on the same network connected through wifi.
If with the above method is not possible then What is the method to do this.
error is:
05-25 20:06:20.836 2576-2576/com.example.user.storeimage E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.storeimage, PID: 2576
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:4452)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.io.FileNotFoundException: D:\images\: open failed: EROFS (Read-only file system)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
at com.example.user.storeimage.copyimagetopc.onClickSaveBtn(copyimagetopc.java:52)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
at com.example.user.storeimage. copyimagetopc.onClickSaveBtn(copyimagetopc.java:52)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
File works for filesystem paths, for the local filesystem. In the case of Android, the local filesystem is the Android device. There is no D:\\images\\ on an Android device. Android does not support mapping of SMB servers to filesystem paths.
If with the above method is not possible then What is the method to do this.
Either work with SMB directly (e.g., jCIFS) or find some app that exposes SMB servers through some sort of API (e.g., a ContentProvider).
As the following error and CommonsWare's answer, I think that you need to know that your mobile phone and your computer OS are in different hosts. So D:\\images\\ is pointting to the same host address. You need to point to your LAN address and use a protocol like samba or the same windows sharer to share a folder and giving permissions or you can use a Webserver like XAMPP and send the file as a encoded base 64 String and decode then in the xampp server with php and save it to a folder.
Related
I try to read/write a file data_quizz.xml situated in /data/data/com.my.package.app/files/data_quizz.xml. Using other topic I used adb to make /data and all subfolders in the data_quizz.xml path 777.
But when it comes to this line :
FileInputStream is = new FileInputStream("/data/data/com.my.package.app/files/data_quizz.xml");
I still get an error, this is the stacktrace :
java.io.FileNotFoundException: /data/data/com.my.package.app/files/data_quizz.xml (Permission denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:99)
at com.dautry.a16126734.quizzapp.XmlManager.<init>(XmlManager.java:43)
at com.dautry.a16126734.quizzapp.ChooseTopic.onCreate(ChooseTopic.java:27)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Edit : Correction of the initial path which were wrong
Thanks
Realm.init(this);
Realm.setDefaultConfiguration(new RealmConfiguration.Builder()
.name("default.realm")
.modules(Realm.getDefaultModule(), new RealmCoreModule())
.schemaVersion(10)
.migration(new SampleRealmMigration())
.build());
Fatal Exception: java.lang.RuntimeException: Unable to create application com.zappos.android.ZapposApplication: io.realm.internal.IOException: failed to create temporary directory: /data/user/0/com.zappos.android/files/.realm.temp
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4800)
at android.app.ActivityThread.access$1600(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by io.realm.internal.IOException: failed to create temporary directory: /data/user/0/com.sample.android/files/.realm.temp
at io.realm.internal.SharedRealm.initialize(SharedRealm.java:48)
at io.realm.Realm.init(Realm.java:191)
at com.sample.android.SampleApplication.onCreate(SampleApplication.java:223)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4797)
at android.app.ActivityThread.access$1600(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1417)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
I've noticed that this fails sometimes and more regularly on LG devices on Android 6.
Disk space was not an issue and neither was RAM. From a little more research it says /data/user/0 is something that gets returned during multiple user profiles on the phone. I haven't had luck trying to replicate it.
An issue at the project repo has been created github.com/realm/realm-java/issues/4430
I get the following error when I try to luanch my Angular app in my android app.
06-15 13:49:15.037 9055-9055/? E/AppInfoBase: Exception when retrieving package:com.myPackage
android.content.pm.PackageManager$NameNotFoundException: com.myPackage
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:137)
at com.android.settings.applications.AppInfoBase.retrieveAppEntry(AppInfoBase.java:123)
at com.android.settings.applications.InstalledAppDetails.refreshUi(InstalledAppDetails.java:466)
at com.android.settings.applications.InstalledAppDetails.onActivityResult(InstalledAppDetails.java:435)
at android.app.Activity.dispatchActivityResult(Activity.java:6452)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-15 13:49:15.110 1900-1900/? E/NetworkScheduler.SchedulerReceiver: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
What is the issue? Unable to debug and trace :( I see the Android manifets file, its proper!
I have followed the directions here OpenCV in Android Studio the one that has 94 votes. I get this error when I dod System.loadlibrary("opencv-java")
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/com.krikorherlopian.opencvsample-
1/base.apk"],nativeLibraryDirectories=
[/data/app/com.krikorherlopian.opencvsample-1/lib/arm,
/data/app/com.krikorherlopian.opencvsample-1/base.apk!/lib/armeabi-
v7a, /vendor/lib, /system/lib]]] couldn't find "libopencv_java.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.krikorherlopian.opencvsample.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
EDIT: I still get the error , and I have the ndk added . Krikors-MacBook-Air:~ KrikorHerlopian$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/KrikorHerlopian/Downloads/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle
Whats the problem?
Edit2: Now I got problem of Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: /Users/KrikorHerlopian/Downloads/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle//jni/Android.mk when i try running my app from the terminal using /Users/KrikorHerlopian/Downloads/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle/ndk-build
I've been trying to display a PDF using the PDFView Library.
The PDF is first downloaded and saved into internal memory
My Logcat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.amfstudios.echomagazine/com.amfstudios.PDFViewer}: com.joanzapata.pdfview.exception.FileNotFoundException: /data/data/com.amfstudios.echomagazine/app_magPDF/PDF_1.pdf does not exist.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2314)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2388)
at android.app.ActivityThread.access$800(ActivityThread.java:148)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
Caused by: com.joanzapata.pdfview.exception.FileNotFoundException: /data/data/com.amfstudios.echomagazine/app_magPDF/PDF_1.pdf does not exist.
at com.joanzapata.pdfview.PDFView.fromAsset(PDFView.java:905)
at com.amfstudios.PDFViewer.onCreate(PDFViewer.java:79)
at android.app.Activity.performCreate(Activity.java:5953)
Although using Log I was able to see that the downloaded file was saved with the same path as the one shown in the FileNotFoundException
The save is within a fragment, and read from an activity.