Run python Script in android application - android

I want to get list of installed software on remote computer.For that I want to use python script in my android application.Now,I have a python script which is getting the list of installed software on remote computer.But,I don't know how to make it supported in android.
For this, I found SL4A android Scripting here . So, I tried to run my python script in android device using SL4A.But,It's not working and giving me error because some packages like win32.client is missing.I don't know more about SL4A so I don't know how to convert my python script in Android supported form.So,anyone have any idea or code please suggest me.....
Also If anyone have another way to get installed software list from remote Pc then please suggest...
Below is my python script
import wmi
from winreg import (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, QueryValueEx)
c = wmi.WMI(computer="PC02",user="admin",password="a#1",namespace="root/default").StdRegProv
result, names = c.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall")
print('These subkeys are found under "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"\n\n')
separator = "*" * 80
keyPath = r"Software\Microsoft\Windows\CurrentVersion\Uninstall"
count = 0
while count < len(names):
try:
print(separator+'\n')
path = keyPath + "\\" + names[count]
key = OpenKey(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS)
temp = QueryValueEx(key, 'DisplayName')
display = str(temp[0])
print (" Name: "+display+'\n',"key:",names[count])
count += 1
except:
print ("Key:",names[count])
count += 1
continue

Run the script on your remote computer, and expose the list of installed software on HTTP, a good way to write this simple web app is to use flask and its development server to serve the list of installed software, then write a python script which uses the native android web interface to fetch the list and display it.

You are having problems with missing libraries because you are importing windows specific ones. At any rate, this isn't the correct script to be running. This script seems to be for a computer, not an android phone.

You're trying to use a Python script that uses Windows Management Instrumentation (WMI), on a device that doesn't have that library.
Sadly, WMI on Python requires the win32 library, which is only available on Windows. I don't think you're going to have much success on checking the installed programs on remote Windows computer from an Android device in this way.

Since WMI is based on WBEM, you may be able to use wbem to access it; you might want to try using pywbem, a pure python wbem library.

Running python scripts is now achievable in gradle system using Tasks
task pythonFile(type:Exec) {
workingDir 'src_path'
commandLine 'python', 'my_script.py'
}

Related

Kivy application does not work on Android

I want write simple application in Python for Android using kivy. Sadly when I start example code I see only splash screen and few second later application finish work. There is a huge problem with debugging because adb on Linux Mint does not detect my device.
Can someone look at my code and tell my why?
To build application I use buildozer. You can also see create_env script to check all dependencies are there.
Best regards.
Draqun
EDIT:
I started debugging my application. Conclusion:
buildozer + python3 + kivy is a bad idea
if I use kivy.uix.button.Button when text attribute is str than I got exception "AttributeError: 'str' object has no attribute 'decode'"
if I use kivy.uix.button.Button when text attribute is bytes than I got exception "ValueError: Button.text accept only str"
It looks like loop with no solution. Some idea when I should report it?
Exception is in .buildozer/android/platform/build/build/python-installs/pad/android/init.py" file so it does not look like kivy and/or buildozer exception.
I've used python-for android tool and faced with the same errors. But in my case, app didn't run at all - crashed from splash screen. Finally, I've found a solution. You can try the same way.
So my pipeline was python3 + python-for-android (p4a tool, python-for-android, from master branch) + kivy (1.10.1)
There is a file "_android.pyx" for android building recipe (full list of avaliable p4a recipes you can see by command p4a recipes). This file is, possibly, used by Buildozer, and exactly used by P4A during APK building procedure. You need to fix it.
You may find it's location in Ubuntu (for example) via:
sudo updatedb
locate _android.pyx
It's path should be something like:
~/.local/lib/python3.6/site-packages/pythonforandroid/recipes/android/src/android/_android.pyx
There should be a string:
python_act = autoclass(JAVA_NAMESPACE.decode('utf-8') + u'.PythonActivity')
so you should change it - something like this:
python_act = autoclass(str(JAVA_NAMESPACE) + u'.PythonActivity'),
or just use some hardcode:
python_act = autoclass("org/kivy/android/PythonActivity")
Or there might be the other decode() usage in sources.
The reason: differences between Python2 and Python3 - the decode() method is usable on the equivalent binary data type in either Python 2 or 3, but it can’t be used by the textual data type consistently between Python 2 and 3 because str in Python 3 doesn’t have the method decode function has different realisation in Python3. More details are here:
pyporting features
issues p4a's github
Hope, it will help you somehow.

Rtf string parse Android JAVA possible?

Use WebService and get RFT string format. I can't show editable textview or webview.
This is possible in java?
RTF String convert or parse is possible ?
String RTFString = "{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf250
{\fonttbl\f0\fnil\fcharset0 LucidaGrande;\f1\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;}
\deftab720
\pard\pardeftab720\sl264\slmult1\sb260\ql\qnatural
\f0\fs26 \cf0 You will need to relaunch Xcode after this install to make it load the plugin.\
This package installs both version 2.x and 1.x of DMD, but you can customize the install to get only one or the other.\
With the two versions installed, D for Xcode uses DMD\'a02.x by default. You can override this setting in your Xcode project on a per-target basis by creating a custom build rule in each target\'92s settings. Alternatively, you can change the system default by typing this command from the terminal:\
\pard\pardeftab720\li560\sl264\slmult1\sb260\ql\qnatural
\f1\fs22 \cf0 sudo setdmd 1
\f0\fs26 \
\pard\pardeftab720\sl264\slmult1\sb260\ql\qnatural
\cf0 This will change the symlinks to make the
\f1\fs22 dmd
\f0\fs26 command point to
\f1\fs22 dmd1
\f0\fs26 .}";
Best Regards.

how to copy files from android to windows share using python?

Im trying to copy some files to and from a windows share. I am using python 2.7 and the pysmb library. This works fine with win7, but not with android. I build my connection over VPN with SMBConnection. listShares and listPath is working. Under win7 there is no problem using also os.path.isdir or shutil.copyfile. But that does not work with android. This is my code:
server_name = '192.168.168.12'
conn = SMBConnection(username=username, password=password, my_name='waldi2'
remote_name=server_name, domain=domain, use_ntlm_v2=True,
sign_options=SMBConnection.SIGN_WHEN_SUPPORTED, is_direct_tcp=True)
connected = conn.connect(server_name, 445)
# obtain a list of shares:
Response = conn.listShares(timeout=30) # !!!working, shows e.g.(' Share[', 20, '] =', u'JBW_in')
os.path.isdir('//192.168.168.12/JBW_in/') # is False with android, True with win7 !??
shutil.copyfile('/sdcard/waldi2_0/data/stop.txt', '//192.168.168.12/JBW_in/stop.txt')
This is no prob with win7, but with android it throws:
[Errno 2] No such file or directory: '//192.168.168.12/JBW_in/stop.txt'
Any clues? would be very very welcome ....
Or maybe alternative approaches to manage some python-based file-exchange between android and windows-server.
If I understund you correctly you are trying to connect to an android device via SMB. By my knowledge android doesnt have support for SMB server natively, but you could install a third-party app with a SMB server.

Python error when running SL4A script from Tasker (AttributeError: type object 'Android' has no attribute 'getIntent')

I'm trying to call a Python script from Tasker using SL4A on my Android (4.4) phone. I'm using the Run SL4A Script task for this. As a test exercise, I want to pass a string from Tasker and use it (for now just print it) in Python.
According to the link below, this can be done by setting the 'Pass Variables' field in the Run SL4A Script task and picking it up with the Android getIntent method in Python. (https://groups.google.com/forum/#!topic/taskerpro/mQIv1PBu3PU)
Here's my Python script:
import android
droid = android.Android
params = droid.getIntent().result[u'extras']
print params[0]
However when I run the task I get the following error in SL4A:
AttributeError: type object 'Android' has no attribute 'getIntent'
Anyone know why I get this and how to solve it? I can't find any reference to it elsewhere.
I don't know about calling from Tasker, but the Python script runs fine stand-alone on SL4A Release 6 and Python interpreter Py4A Release 5.
If you don't have everything installed yet, here are some some slides I recently presented at an Android developers meetup.
I think you are simply missing the parentheses in your Android imports.
I use:
import android
droid = android.Android()
you can also try:
from android import Android
droid = Android()
this makes Android an object in python properly and you should be able to call the getIntent and other functions properly.
and to save time testing if the android module is functional I also add:
def toast(x):
x = str(x)
droid.makeToast(x)
then you can pass variables to the newly defined toast(x) function.
Hope I've helped!

Unity command line arguments for android and iOS

Please pardon my ignorance, relatively new to working with Unity3D. I am working on automating Unity3d builds from the command line.
I am looking for command line arguments to build apk & xcode project.
Unity's documentation does mention arguments to build a standalone Mac OSX player (-buildOSXPlayer) and a standalone Windows player (-buildWindowsPlayer) but not for android and iOS.
Any help would be really appreciated. Thanks.
Start with Unity's own documentation for command line builds for iOS and android.
For example, put this script in your Assets/Editor folder:
// C# example
using UnityEditor;
class Autobuilder
{
[MenuItem ("File/AutoBuilder/iOS")]
static void PerformBuild ()
{
string[] scenes = { "Assets/MyScene.unity" };
string buildPath = "../../../Build/iOS";
// Create build folder if not yet exists
Directory.CreateDirectory(buildPath);
BuildPipeline.BuildPlayer(scenes, buildPath, BuildTarget.iOS, BuildOptions.Development);
}
}
You can actually run this script in the Unity application by going to File -> Autobuilder -> iOS
To run on command line, it looks something like this:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod Autobuilder.PerformBuild -email me#email.com -password myPassword
Of course, you're going to want to check the debug log for any errors:
Mac OS X ~/Library/Logs/Unity/Editor.log
Windows XP C:\Documents and Settings\username\Local Settings\Application Data_\Unity\Editor\Editor.log
Windows Vista/7 C:\Users\username\AppData\Local\Unity\Editor\Editor.log
The -executeMethod command line parameter is a very simple option to invoke any function in any of your scripts - which you can then use to do pretty much anything, including firing off an Android build.

Categories

Resources