简体   繁体   English

当我使用“ adb shell am广播”时得到回应

[英]Get a response when I use “adb shell am broadcast”

I have an Android app with a receiver that listens for 2 intents, 1 that spawns a thread to write to a file and 1 that spawns a thread to upload the same file to a server. 我有一个带有接收器的Android应用程序,该接收器侦听2个意图,其中1个产生一个线程来写入文件,另一个1个产生一个线程来将同一文件上载到服务器。

I have a script on my host machine that needs to manually send intents to the receiver via "adb shell am broadcast". 我的主机上有一个脚本,需要通过“ adb shell am广播”将意图手动发送到接收者。 I want to send an intent to write to a file and then send another intent to upload it. 我想发送一个写入文件的意图,然后发送另一个上传它的意图。 However, both creating and uploading the file can take an unknown amount of time and I need to wait for the file to finish being written before uploading it. 但是,创建和上传文件都可能花费未知的时间,在上传之前,我需要等待文件写入完成。

Is there a way for my Android app to somehow signal to my host script that writing is done? 我的Android应用程序是否可以通过某种方式向主机脚本发出已完成编写的信号? Or is there a way I can poll the app with my script and the app returns the status of the file? 还是有一种方法可以使用脚本轮询应用程序,并且该应用程序返回文件的状态?

The only thing I can think of is creating a temp file when the real file is complete. 我唯一能想到的就是在真实文件完成后创建一个临时文件。 The script polls for the existence of this temp file and uses it as an indicator that the real file is ready to upload. 该脚本会轮询此临时文件的存在并将其用作指示实际文件已准备好上载的指示符。

Your app can make some request to some address and in the parameters of the request it can send the status 您的应用可以向某个地址提出一些请求,并且可以在请求的参数中发送状态

for example 例如

void somemethod(){
//do stuff
//sendfrlagforfinish on you host adress
//or in case of error send flag for error
}

on your host you need to have a listener (service) running that will receive these requests 在主机上,您需要运行一个侦听器(服务)以接收这些请求

I have done something similar and my request to my server looked like this 我做了类似的事情,我对服务器的请求看起来像这样

www.myserverhostip.com?flag=success

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM