0

Is there any Broadcast intent / message sent when we upload documents/images on our android devices.I am looking for something similar to the DownloadManager.ACTION_DOWNLOAD_COMPLETE that is sent when Download is complete. The requirement of my app is to monitor all uploads that are done on the phone and hence I am looking for any Broadcast message / intent that I can listen to

sim
  • 249
  • 7
  • 17
  • How are you uploading something to Android? – class stacker Apr 15 '13 at 13:48
  • 1
    After some 'googling' I recommend you to try to do something with "TrafficStats", like, determining that a transaction is finished if there is no new packets transmitted during some time. Also, some StackOverflow answers point about using NTP and working in low-level. Goog Luck! – Ger Soto Apr 15 '13 at 14:22
  • @GerSoto , I tried using the TrafficStats.getTotalTxPackets to track the bytes transmitted in order to track any upload data. My requirements is to stop upload of any file through an app. Unfortunately using the TrafficStats API's lets me monitor the number of bytes and is not specific to uploading a file. Any idea how to detect uploading of a file programatically in Android ? – sim May 07 '13 at 15:11
  • I think that you can't block as you want, so selective. Every App is a user in Android, and from one user you can't block another user, although you are root. Have you tried to find any app which convert your device into kiosk mode? To use it, you have to be root, of course. – Ger Soto May 13 '13 at 13:25

2 Answers2

1

Use AsyncTask

private class LongOperation extends AsyncTask {

      @Override
      protected String doInBackground(String... params) {
           // upload file code
      }      

      @Override
      protected void onPostExecute(String result) {
            // start new intent
      }

      @Override
      protected void onPreExecute() {
      }

      @Override
      protected void onProgressUpdate(Void... values) {
      }
}   

Demo

Community
  • 1
  • 1
Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54
  • Quoting the very reference page you link to: _AsyncTasks should ideally be used for short operations (a few seconds at the most.)_ – class stacker Apr 15 '13 at 13:50
0

Just use an AsyncTask.

From some time to now, I'm realizing that "Services" and "Broadcast Messages" functionalities were improved by the AsyncTask's capabilities.

Ger Soto
  • 328
  • 2
  • 12
  • My app needs to handle any upload that happens on the phone (its not only limited to uploading of files through my app)..Will an Aysnc task help in this scenario ? – sim Apr 15 '13 at 13:49
  • Quoting the [AsyncTask reference](http://developer.android.com/reference/android/os/AsyncTask.html): _AsyncTasks should ideally be used for short operations (a few seconds at the most.)_. – class stacker Apr 15 '13 at 13:51
  • No, AsyncTask doesn't cover it. Please, clarify this at your question, to avoid misunderstandings. I can't answer you at this moment without some reading, but I think that "App-user" politics, is difficult to know something about other apps status if it doesn't intent it to you (with direct intents or Broadcast Messages). – Ger Soto Apr 15 '13 at 13:54