Can't create file with Perl script on Android (using perl-android-apk)

 ̄綄美尐妖づ 提交于 2019-12-08 02:52:05

问题


I want to run a simple Perl script on Android. I am using perl-android-apk which makes it possible to include the Perl interpreter in one APK (based on SL4A). The project comes with a hello.pl script, which shows a toast. Alright, everything working so far, so I added some lines for file creation - now whole hello.pl script looks like:

use Android;
my $a = Android->new();
$a->makeToast("Hello, Android!");

open(TEXT,">newtext.txt") || $a->makeToast("I died.");
print TEXT "Check out our text file!";
close(TEXT);

$a->makeToast("Bye, Android!");

When I run the whole thing on Android both toasts are shown ("Hello.." and "Bye..") but I can't find the file newtext.txt anywhere. What am I doing wrong?


回答1:


Does your Android manifest have this?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Also, you might not be able to write to that location. Other answers here indicate that you need to get the external storage directory:

Environment.getExternalStorageDirectory();

Maybe you could call that in Java and pass it to your perl script as an argument?



来源:https://stackoverflow.com/questions/19291600/cant-create-file-with-perl-script-on-android-using-perl-android-apk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!