I'm working on a python script which takes the output from a previous terminal window command and inputs again. Here is the code
pathCmd = './adb shell pm path com.example.deliveryupdater'
pathData = os.popen(pathCmd,"r")
for line in pathData:
path = line
print line
if line.startswith("package:"):
apkPath = line[8:]
print apkPath
pullCmd = './adb pull ' + apkPath
pullData = os.popen(pullCmd,"r")
The output is as follows:
/data/app/com.example.deliveryupdater-1.apk
' does not exist/data/app/com.example.deliveryupdater-1.apk
It says the path doesn't exist.
When I hardcoded the path as
pullCmd = './adb pull /data/app/com.example.deliveryupdater-1.apk'
pullData = os.popen(pullCmd,"r")
The .apk data gets pulled.
3886 KB/s (2565508 bytes in 0.644s)
Is there a way I can pass as the string as a variable? Am I doing anything wrong here?
Please help
The error message is telling you what's wrong: that path, /data/app/com.example.deliveryupdater-1.apk(newline), does not exist. Probably there is not a filename ending with a newline in the directory. I assume you are iterating over lines from a file or something of that sort, which would explain why you have the newline. Why not just slice [8:-1] instead of [8:], or perhaps, just .rstrip() on the line (this will work even if the line doesn't have a newline, as the last line in the file might not)?
if line.startswith("package:"):
apkPath = line[8:].rstrip()
print apkPath
pullCmd = './adb pull ' + apkPath
pullData = os.popen(pullCmd,"r")
Related
I need to merge (concatenate) two audio files in a Flutter app.
I am trying to use Flutter_ffmpeg package .
https://pub.dev/packages/flutter_ffmpeg
Ffmpeg is powerful tool for audio and video.
flutter_cache_manager package to store the files that came from https
https://pub.dev/packages/flutter_cache_manager
And path provided to deal with the paths
https://pub.dev/packages/path_provider
For the part of caching I already made some successful tests,
But, I need your help to understand how can I use ffmpeg package.
According to the readme I need to do something like
import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg();
var fileCached1 = await DefaultCacheManager().getSingleFile(url1);
var fileCached2 = await DefaultCacheManager().getSingleFile(url2);
var arguments = ["-i", "concat:fileCached1.wav|fileCached2.wav", "-c copy", "output.way"];
_flutterFFmpeg.executeWithArguments(arguments ).then((rc) => print("FFmpeg process exited with rc $rc"));
How can I have access to the output.wav to play? How can I use the path_provider?
I really need you help. :)
There is little information about flutter_ffmpeg. This question might be useful for someone else to.
Thanks in advance,
Ricardo
The path_provider package let you to access appDir & temp directory of your application, let say that you want to access the application documents directory :
Directory appDocumentDir = await getApplicationDocumentsDirectory();
String rawDocumentPath = appDocumentDir.path;
and if your output's file name is "output.wav"
String outputPath = Strings.concatAll([rawDocumentPath, "/output.wav"]);
now outputPath contain the path to output file that will be generated by FFMPEG and you can use it later when you want to play/copy/upload or whatever you want to.
but in the FFMPEG part, the command line for concat two input file is:
ffmpeg -i input1.wav -i input2.wav -filter_complex '[0:0][1:0]concat=n=2:v=0:a=1[out]' -map '[out]' output.wav
If you want to have 3 input files, use n=3 and change the other parts in command.
usage of Flutter_ffmpeg will be something like this:
import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg();
_flutterFFmpeg.execute("-i input1.wav -i input2.wav -filter_complex '[0:0][1:0]concat=n=2:v=0:a=1[out]' -map '[out]' output.wav").then((rc) => print("FFmpeg process exited with rc $rc"));
ideally we want to use outputPath here so do something like this :
String commandToExecute = Strings.concatAll(["-i input1.wav -i input2.wav -filter_complex '[0:0][1:0]concat=n=2:v=0:a=1[out]' -map '[out]' ", outputPath]);
and your final statement for executing the process will be :
_flutterFFmpeg.execute(commandToExecute).then((rc) => print("FFmpeg process exited with rc $rc"));
after execution you can check execution output. Zero represents successful execution, non-zero values represent failure :
final FlutterFFmpegConfig _flutterFFmpegConfig = new FlutterFFmpegConfig();
_flutterFFmpegConfig.getLastReturnCode().then((rc) => print("Last rc: $rc"));
_flutterFFmpegConfig.getLastCommandOutput().then((output) => print("Last command output: $output"));
so in case of failure or getting error, you can check the command output for fixing bugs
you can find more information about flutter_ffmpeg in here :
https://pub.dev/packages/flutter_ffmpeg
also for using ffmpeg and find more about filters you can check this out :
https://ffmpeg.org/ffmpeg-filters.html
First get the directory
final appDirectory = await getExternalStorageDirectory();
Then in the execute commands append the output file with directory.
_flutterFFmpeg.execute("-i $videoURL -i $audioURL -c copy ${appDirectory?.path}/output.mp4");
I am using Unity 5.6.
Until now, the Android used a way to inspect the classes.dex file inside the APK to prevent app tampering
For a typical build, I had no problem importing the classes.dex file.
However, using the 'Split Binary Build' option to use the .obb file, I could not import the classes.dex file properly.
I used to import classes.dex file in the following way
string urlScheme = #"jar:file://";
string apkPath = Application.dataPath;
string separator = #"!/";
string entry = #"classes.dex";
string url = urlScheme + apkPath + separator + entry;
If you use the Split Binay Option in Unity, the path to Application.dataPath will be 'android / data / obb /.../ myobb.obb'
s there a way to get the same result as the existing Application.dataPath using the Split Binary Build option?
I solved it.
It was impossible to solve within Unity.
You can get the same results if you use the values imported from Java in Unity.
PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.sourceDir;
Reference : Get Application Directory
How do I execute this logcat command via python?
adb logcat -d > log1.txt
I tried this but there is no file being created in the output folder.
I did do a workaround and it worked.
I have another issue: The log1.txt file is populated. I am expected to copy lines with tag "sample" from log1.txt file to another new file. I wrote a function for this but only one instance of the tag line is getting printed in the new file where as the print statement before this print 3 lines in the output. Could someone plz help.
for line in open("log1.txt",'r'):
cmd="sample"
if cmd in line:
print line
f = open('myfile','w')
f.write(line)
Try this
with open('out-file.txt', 'w') as f:
subprocess.call(['adb','logcat', '-d'], stdout=f)
I have the following Python code, it uses Android logcat via stdout to pull the logs off the phone into a wxPython Text field.
I login to my app, username jack and password Jack#123$ the logcat output stops with an error, it seems to not like the # or $ symbols:
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 76: character maps to <undefined>
Or when I try to GetValue() of the text control to save it into a .txt file that is open for writing:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 204447-204449: ordinal not in range(128)
The code for the logcat function is as follows
def logcat(self):
params = [toolsDir + "\\adb.exe", "logcat"]
p = Popen(params, stdout=subprocess.PIPE, bufsize=1)
for line in p.stdout:
#line = line.decode('Latin-1')
self.progressBox.AppendText(line)
def saveLog(self,e):
f = open(outDir + '\\' + pkgName + '\\' + pkgName + '_logcat.txt', 'w')
f.write(self.progressBox.GetValue())
f.close()
What would be the correct way of implementing decoding for these symbols using stdout.
Thanks
EDIT:
Answer is as follows, I had to decode('utf-8') from stdout into a textbox, but then encode('utf-8') when writing to a file.
for line in p.stdout:
self.progressBox.AppendText(line.decode('utf-8'))
f.write(self.progressBox.GetValue().encode('utf-8'))
it is possible to get installer file name which is stored on /sdcard/
download/ ? I want to get from app, apk file name which installed it.
There is a easy way to do it especially with non-market app?
The better way is definitely to include the version string in the manifest. This is really the only reliable (and professional) method. Android doesn't store the name of the file containing the APK anywhere, so there isn't a way that you can get it.
Theoretically you could probably build something using a FileObserver, that watched file creation in certain directories and every time a file was created with the extension .apk you could open the file, extract the manifest, find the package name of the APK and then store this along with the filename in some persistent storage. Then, when you need get the version information, you can look in the persisten storage to get the file name matching the package name you need.
Of course, this would only work if your app was installed on the device before the other APK files were downloaded/installed. This wouldn't work to find out the filename of your own application.
Hmm, I am not sure what you mean by sdcard or download folder, but you could get apk path in system /data directory:
command line:
$ adb shell pm list packages | grep mk.trelloapp
package:mk.trelloapp
$ adb shell pm path mk.trelloapp
package:/data/app/mk.trelloapp-1/base.apk
or from you android application code: (simply run process)
Process exec = Runtime.getRuntime().exec("pm path mk.trelloapp");
exec.waitFor();
InputStream inputStream = exec.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder builder = new StringBuilder();
String line = null;
while( ( line = br.readLine()) != null ) {
builder.append(line);
}
String commandOutput = builder.toString();
Code above should simply give you String containing "package:/data/app/mk.trelloapp-1/base.apk"
When you acquire path in /data directory, you might try to search for same (similar) file in other directories (assuming it was not deleted), since android package is copied to /data directory while instalation.