Commit d8f1337b authored by Philipp Auersperg's avatar Philipp Auersperg

...

parent a031034f
# Android client for procbridge
currently we have only a python server for procbridge
## Setup
we need the following deps:
- implementation 'co.gongzh.procbridge:procbridge:2.1.0-gradle'
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.0'
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.0' //needed for Dispatchers.Main
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidrpcclient">
xmlns:tools="http://schemas.android.com/tools" package="com.example.androidrpcclient">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
......@@ -8,7 +8,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
......@@ -16,6 +16,9 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<!--<activity android:name="org.bd.MainActivity" />-->
<!--<uses-library android:name="org.bd" />-->
</application>
</manifest>
\ No newline at end of file
package com.example.androidrpcclient
import android.content.ComponentName
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.provider.Contacts
import kotlinx.android.synthetic.main.activity_main.*
import java.lang.Exception
import kotlinx.coroutines.*
import android.app.Service
class MainActivity : AppCompatActivity() {
......@@ -41,4 +45,32 @@ class MainActivity : AppCompatActivity() {
}
}
}
fun onStartServer(view: android.view.View){
println("start server clicked")
val klass="org.bd.servicetest.ServiceTestserv"
// val intent= Intent(".MainActivity")
// .also {intent.setPackage("org.bd.servicetest")}
// val intent= Intent("org.bd.action.VIEW")
// .also {it.setPackage("org.bd")}
// val intent = Intent("org.bd.action.VIEW")
val intent = Intent("org.bd.servicetest.MAIN")
// intent.component = ComponentName("org.bd.servicetest", "./PythonActivity")
// intent.component = ComponentName("org.bd", "./MainActivity")
startActivity(intent)
// val res: ComponentName = startService(intent)
val res = startActivity(intent)
println("res: $res")
// ComponentName("org.bd.servicetest", "org.bd.servicetest.ServiceTestserv")
// val intent = Intent()
}
}
......@@ -5,6 +5,7 @@ import co.gongzh.procbridge.ProcBridge
import co.gongzh.procbridge.ProcBridgeException
import com.google.gson.JsonObject
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
object ProcbridgeClient {
......@@ -28,15 +29,11 @@ object ProcbridgeClient {
}
fun request(api:String, params:String): JsonObject {
println("request before:$api")
val res = runBlocking (Dispatchers.IO){
// this must run in the IO Threadpool, otherwise a NetworkInMainThreadException pops up
pb.sendMessage(api, "{$params}")
}
println("request after:$res")
val rres=res.get()!!
println("res.get()=$rres")
return rres
return res.get()
}
}
......@@ -16,15 +16,6 @@
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
android:hint="Host" android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="@+id/txtStatus"/>
<Button
android:text="connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnConnect" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.498" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/editPort" android:background="@color/colorPrimary"/>
<TextView
android:text="disconnected"
android:layout_width="wrap_content"
......@@ -46,9 +37,10 @@
android:layout_height="0dp"
android:id="@+id/txtMessage" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/btnConnect" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/textView" android:background="#ffffff"/>
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/textView" android:background="#ffffff"
android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/linearLayout"/>
<TextView
android:text="command"
android:layout_width="wrap_content"
......@@ -94,5 +86,28 @@
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
android:layout_marginBottom="56dp" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.498"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:id="@+id/linearLayout" android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/editPort" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp">
<Button
android:text="start service"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/btnStartServer" android:layout_weight="1"
android:onClick="onStartServer"/>
<Button
android:text="connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnConnect" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintHorizontal_bias="0.348"
android:background="@color/colorPrimary" tools:layout_editor_absoluteY="255dp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
......@@ -6,3 +6,16 @@ Minimal Kivy Service example with a simple echo service
$ buildozer android debug deploy run logcat | grep -e python -e TestServ
## start app via adb
starting app via logcat works now
$ am start org.bd.servicetest/org.kivy.android.PythonActivity
but still searching how to start it from an android app
resources in the net:
- (https://groups.google.com/forum/#!topic/kivy-users/a55E-xovkds)
- (https://stackoverflow.com/questions/46867907/starting-kivy-service-on-bootup-android)
- (https://stackoverflow.com/questions/47362161/kivy-service-stops-when-app-is-closed)
......@@ -7,6 +7,18 @@ import logging
from kivy.logger import Logger
Logger.setLevel(logging.INFO)
def start_service():
print 'starting service...'
if platform == 'android':
from jnius import autoclass
service = autoclass('org.bd.servicetest.ServiceTestserv')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
argument = ''
res=service.start(mActivity, argument)
print 'service started:', res
else:
Logger.error("wrong platform:"+platform)
Builder.load_string("""
<MainWindow>:
Button:
......@@ -23,17 +35,7 @@ class MainWindow(BoxLayout):
Logger.info("pressed")
def start_service(self):
print 'starting service...'
if platform == 'android':
from jnius import autoclass
service = autoclass('org.bd.servicetest.ServiceTestserv')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
argument = ''
res=service.start(mActivity, argument)
print 'service started:', res
else:
Logger.error("wrong platform:"+platform)
start_service()
class ServiceApp(App):
......@@ -44,3 +46,4 @@ class ServiceApp(App):
if __name__ == '__main__':
ServiceApp().run()
# start_service()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment