QPython - Reading a file - android

I have installed QPython in my Android mobile.
I written a statement in the QEdit to read a text file from the below path
/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt
I used the below statement
fob=open('/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt','r')
fob.read()
If I run the statement, it is throwing error as:
IOError:[Errno 2] No such file or directory: '/storage/emulated/0/com.hipipal.qpyplus/script3/File1.txt'
1|uo_a116#cancro:/ $
Is the above statement correct?

fob=open('File1.txt','r')
Is not working in version 1.0.4.
fout=open('File2.txt','w')
Was working on version 0.9.6, but is not working in 1.0.4.
The "error" is Read only file system.
It looks like restrictions in the (new 1.0.4) file system library. I post a mail to the editor, but no answer at this time.

For testing, try to write absolute path to your files pointing, for example, to sdcard (/sdcard/out.txt).
I had problems on this versions (>=1.0.4) because launch process of script changes and execution directory is not the same as script directory.
I had to change my scripts to point to absolute paths.
It was tested with qpython developer.
Check this link:
https://github.com/qpython-android/qpython.org/issues/48

You can also try as simple as:
fob=open('File1.txt','r')
fob.read()
Just if the script is in the same folder of the file.

You can change the current working directory to path with script before read file:
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

Related

How to read from file using Chaquopy?

I want to read a file using Chaquopy. After some errors like "PermissionError" I wrote the same code in Python Idle and Chaquopy:
This code in Idle writes 'True' in output.
import xlrd, os
filename = 'F:/q1.xlsx'
print(os.path.isfile(filename))
And this one in Chaquopy outputs 'False':
import xlrd, os
filename = 'F:/q1.xlsx'
self.findViewById(R.id.label).setText(str(os.path.isfile(filename)))
I tried all the described combinations of '\' and '/'. It also cannot open a file in the same folder with Python activity if I write only its relative path. How to make Chaquopy work with files correctly?
You can access files either using pkgutil or by using the extractPackages setting. See the documentation for details.

Cannot copying file from Android to Linuxmint 17.3 Desktop "libmtp error: Could not get file from device"

I am trying to copy image file to backup it on my desktop which is linux mint (17.3 or Rosa) installed. I am using Infinix X510 phone with the newest version of android 6. At the beginning it was OK. But, at the end i get the message
“libmtp error: Could not get file from device”
I tried the solution as found by Googling here https://askubuntu.com/questions/879029/libmtp-error-could-not-get-file-from-device-on-attempting-to-transfer-files
But, it wasn't working for me. Is there a way to solve this matter? I need file to support my company job which supplying cosmetics.
Try compressing the file to a compressed format(tar,zip).Copy the file and then decompress it.
Changing the filename was the solution for me e.g: file.mkv to file.zip
Try to rename file, make sure file name not contain (-) (:) etc. Just rename it to alphabet

Cocos2d-x Sample HelloCpp not running on Android

I have a problem with the included sample HelloCpp in cocos2d-2.0-x-2.0.4.
My environment:
Mac OSX 10.8.2
cocos2d-2.0-x-2.0.4
android-ndk-r8
The proj.ios of the sample is running fine in the xcode emulator but i have problems get the proj.android running on my Android HTC One X Device.
I am able to build the apk file with the makefile from raywenderlich and when i unzip the apk it has the assets/ipad folder included and images in it and after the installation of the apk file on the device the app loads and shows the information about frames etc. in the left lower corner of the screen. But then a notification window pops up and tells me that the program is not able to load "assets/ipad/HelloWorld.png"
The error message is thrown in cocos2dx/platform/android/CCFileUtils.ccp line 134.
Is it correct to load a png file with pData = CCFileUtils::getFileDataFromZip(s_strResourcePath.c_str(), fullPath.c_str(), pSize); ?
Because thats the line where the program is running into in cocos2dx/platform/android/CCFileUtils.ccp line 97.
the value of s_strResourcePath is /data/app/org.cocos2dx.hellocpp.apk and fullpath is assets/ipad/HelloWorld.png.
I really hope someone can help me. Or has the same problem at least.
Just check out in which folder is you all resources. In my case its in assets/Resources .. So i will setResourceDirectory as "Resources" so the path will be assets/Resources ...whereas i guess in ur case its ipad
so set it ipad
Add this lines in AppDelegate.cpp->applicationDidFinishLaunching() function. If it's already there then just change it for the android
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID )
pFileUtil->setResourceDirectory("ipad");
#endif
Try if this works
Try to add your images in "HelloCpp/Resources". Maybe you're adding image files in "HelloCpp/proj.android/assets/".
Try this:
"HelloCpp/Resources/iphone/HelloWorld.png"
"HelloCpp/Resources/ipad/HelloWorld.png"
"HelloCpp/Resources/ipadhd/HelloWorld.png"
Instead of this:
"HelloCpp/proj.android/assets/iphone/HelloWorld.png"
"HelloCpp/proj.android/assets/ipad/HelloWorld.png"
"HelloCpp/proj.android/assets/ipadhd/HelloWorld.png"

How can i open .trace file format(traceview) without DDMS?

I want to save a log of method calls.
Traceview supports that function and I can get .trace file format.
but, I need to open .trace file format without DDMS.
If I can't open .trace file without DDMS, How can I get a log of method calls?
(The best is .txt file format.)
thanks.
It is an old thread.
because I found here, so other guys may need this, too.
Try this:
traceview -r yourtrace.trace > 1.txt
and look 1.txt has any useful thing to u.
"traceview" is a command-line utility. You don't need to launch it from DDMS.
If you just want a text file with times and message names, you can use "dmtracedump -o file.trace".
Well for one, you should just use DDMS it's very simple to work with. Even if you don't have eclipse you can use the one that shipped with the SDK. However, if you already have access to the tracefile.trace then you could simply use Traceview from the SDK. Simply open your command prompt and navigate to your android SDK/tools directory as such: cd C:\Program Files\Android\android-sdk\tools. Once there simply type traceview followed by the filename (can omit .trace) as such: traceview C:\Users\Sino\Desktop\Janky_trace_file. This should open your trace file in a GUI representation with functionality to delve into your method calls.
This is simple.
Eclipse: File --> Open file --> open traveview file (xxxx.trace)
If you have a ".trace" file, just use "traceview " from the command line and you should be able to view the content of the file.
You can generate various graphs with the existing .trace file using the command line tool "dmtracedump". http://developer.android.com/tools/help/dmtracedump.html.

./droidgap:4:in `require': no such file to load

I'm trying to get PhoneGap working. I've hit a hurdle getting started.
I've downloaded version 0.9.1. I've been following the instructions at http://phonegap.pbworks.com/Getting-started-with-Android-PhoneGap-in-Eclipse
Using MacOS 10.5.8. Android SDK is already installed and working with Eclipse.
My .bash_profile file looks like this:-
$PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
export PATH=${PATH}:/Applications/android-sdk-mac_86/tools
export PATH=$PATH:/Applications/phonegap-android/bin
(and I restarted my terminal window to make it take effect)
I've tried the following command:-
cd /Applications/phonegap-android/bin
ruby ./droidgap /Applications/android-sdk-mac_86 HelloPhoneGap com.myidentity.android /Users/myidentity/Documents/workspace/HelloPhoneGap/assets/www /Users/myidentity/Desktop
...and I get the following error:-
./droidgap:4:in `require': no such file to load -- /Applications/phonegap-android/bin/lib/generate.rb (LoadError)
from ./droidgap:4
Why?
I ran into this issue as well, move droidgap up one level into the phonegap base directory.
Or, you should mention the complete path:
export PATH=$path: /Applications/phonegap-android/bin/**droidgap**
I came across such issues too. go to https://github.com/jonathanstark/phonegap-android, search the generate.rb file in the lib folder there, download it, then you are good to go.

Categories

Resources