Kivy's Python for Android and SL4A's Python for Android are not
related in any way. They are entirely different projects, but with the
same name (unfortunately).
I also started with SL4A, so I have some idea where you're coming from. Kivy doesn't have an 'android' module like Py4A. We have just started work on the 'plyers' project which will serve a similar purpose. For now, you have to access the Java API manually via pyjnius.
I spent some time trying to get Toast to work via pyjnius, but have not been successful yet. Your best bet for now is to use a Kivy pop-up inside of your Kivy app.
--
...Kivy doesn't have an 'android' module like Py4A. ..
I think it is possible - the Qpython Android IDE seems to have done it - but no one has made a solution publicly available. Also, Kivy is focusing on a consistent platform abstraction layer (the plyers project) so the same interface can be used on any OS.
Anyone who would like to have the Py4A 'android' interface on Kivy is welcome to take a crack at it. I personally would use it until plyers is mature, but I lack the time and knowledge to port it right now.
I see Qpython plus supports both SL4A and kivy libraries import.
You can write own log handler and start subprocess that opens log for you ...What do you think?
If it's possible to add button and popup to your app it can solve all problems. Just read log to popup content. I think it's the easiest way and saves scren for more usefull tasks. Use try blocks and multiprocessing to protect from situations were your app will not start or FC. Also you can add status bar but it will need some more coding depending on type of output of your task. Good luck! Give us updates of your solution.
--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/QkmdLmdY-bI/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
'''MODULE: loggers.py
This module is special logger handler for sending emails and SMS on logger event. For use on android. needs testing. Please edit Usage: handler=maillog.Notifier()'''
import loggingimport timeimport logging.handlers as handlersfrom threading import Threadfrom logging.handlers import TimedRotatingFileHandlerimport multiprocessing as mp
email = 'yo...@gmail.com'topic = '[TOPIC]'phonenumber= '+38063000000'
class SizedTimedRotatingFileHandler(handlers.TimedRotatingFileHandler): """ Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size, or at certain timed intervals """ def __init__(self, filename, mode='a', maxBytes=1000000, backupCount=0, encoding=None, delay=0, when='h', interval=1, utc=False): # If rotation/rollover is wanted, it doesn't make sense to use another # mode. If for example 'w' were specified, then if there were multiple # runs of the calling application, the logs from previous runs would be # lost if the 'w' is respected, because the log file would be truncated # on each run. if maxBytes > 0: mode = 'a' handlers.TimedRotatingFileHandler.__init__( self, filename, when, interval, backupCount, encoding, delay, utc) self.maxBytes = maxBytes
def shouldRollover(self, record): """ Determine if rollover should occur.
Basically, see if the supplied record would cause the file to exceed the size limit we have. """ if self.stream is None: # delay was set... self.stream = self._open() if self.maxBytes > 0: # are we rolling over? msg = "%s\n" % self.format(record) self.stream.seek(0, 2) #due to non-posix-compliant Windows feature if self.stream.tell() + len(msg) >= self.maxBytes: return 1 t = int(time.time()) if t >= self.rolloverAt: return 1 return 0
def sendmail(record): try: import android droid = android.Android() droid.sendEmail(email, topic+str(record)[0:30], record)#sending first 30 chars of message in topic except Exception as err: logging.exception(err) def sendsms(record): try: import android droid = android.Android() droid.smsSend(phonenumber ,record) except Exception as err: logging.exception(err)
class Notifier(logging.Handler): def emit(self, record): try:
'''PUT HERE YOUR CODE TO WRITE LOG AND THEN OPEN LOG IN FILE OR TO SHOW POPUP USING KIVY OR P4A FACADE.
IF USING MULTIPROCESSING IT'S MUCH HARDER TO KILL YOUR PROGRAM BY UNHANDLED ERROR IF ERROR IS
NOT IN MAIN THREAD.'''
thread = Thread(target=sendmail, args=(record)) thread.start() thread = Thread(target=sendsms, args=(record)) thread.start() except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record) class loopchekerFilter(logging.Filter): '''prevents from logoverflow on continuous error log''' oldrecord = None i = None
def filter(self, record): if self.i > 10: return False
if self.i == 10: # I use another optional handler here to record message (you can put your own action)
you need to create "critical" handler before using next line:
critical.error('Entered logger continuous loop..aborting logging') self.i+=1 return False if str(record) == str(self.oldrecord): self.i+=1 self.oldrecord = record return True if str(record) != str(self.oldrecord): self.i=0 self.oldrecord = record return True
logger = mp.log_to_stderr(logging.DEBUG)hdlr1 = SizedTimedRotatingFileHandler('logs/program.log', when='d', backupCount=7, maxBytes=1000000)#filename, interval = each day, delete 7 days old filesformat1 = logging.Formatter('%(asctime)s--- %(processName)-12s %(levelname)-8s>> %(message)s')hdlr1.setFormatter(format1)logger.addHandler(hdlr1)logger.addFilter(loopchekerFilter())
'''PUT HERE YOUR CODE TO WRITE LOG AND THEN OPEN LOG IN FILE OR TO SHOW POPUP USING KIVY OR P4A FACADE.
IF USING MULTIPROCESSING ITS MUCH HARDER TO KILL YOUR PROGRAM BY UNHANDLED ERROR IF ERROR IS
NOT IN MAIN THREAD.'''
thread = Thread(target=sendmail, args=(record))