[android-developers] Re: Unit testing a class that uses android.os.Handler

2010-10-12 Thread Jeremy Wadsack
I think AsyncTask is designed to provide a way to run things off the
main thread and take care of starting and ending the thread as needed,
but it's not intended to be re-used. It does it's thing in the
background and then it's done.

As for the test case, what you say makes sense. And I suppose that
it's just clarifying what I really already know about this. That it's
blocking the main thread when executing the test.

The AndroidTestCase class runs tests on the main thread.
ActivityInstrumentationTestCase2 does not, rather using
activity.runOnUIThread to execute tasks that must be done on the UI
thread. However, the latter class only allows testing Activities, not
generic classes that happen to use Handlers.

So... it seems that by design, Android doesn't expect to have Handlers
used in any classes except Activities. Is that right? Clearly Handlers
are designed for two different purposes (scheduling to do something at
a time and doing something on a different thread). Seems that they
should be able to work independently of the Activity.

Now, I'm confused, though. Clearly running a periodic, asynchronous
task is a common pattern for mobile apps. If it were completely
decoupled from the Activity, I'd use a Service. But in this case I
want to start updates when the Activity is active and stop them when
the Activity ends (not onPause, but onDestroy, although there are
generic use cases for both types). What's the recommended approach
here, still use a Service and pause it's activity when there are no
registered Listeners? Create an AsyncTask that does the work and just
launch it regularly from the Handler in the Activity?


--
Jeremy Wadsack

On Oct 8, 6:55 pm, DanH  wrote:
> Re starting a thread, on most JVMs it's a relatively expensive
> process, and it would be better to keep a thread "warm", with a
> Handler waiting, than to start new ones for every operation.
>
> But of course that depends on how frequently you need the thread.
> (Would be kinda nice if Android had an implicit async thread you could
> throw stuff to, and Android started and ended the thread based on
> usage and memory pressure, just like all the other components they
> manage.)
>
> Re your test case, it doesn't work because you misunderstand how the
> event loop works.  Sending a Message to a Handler just queues the
> message, and it doesn't get handled until the thread returns from
> whatever work it's doing to the event loop.
>
> Presumably something in the event loop triggers a call to
> testHandlerShouldReceiveMessagesPostedToIt.  While that method is
> running the event loop doesn't.  While you're waiting in sleep,
> nothing's happening -- sleep does not run the event loop.  The event
> loop will not run (and process your message) until you return from
> testHandlerShouldReceiveMessagesPostedToIt.
>
> What this means is that any sort of sequential programming where you
> "wait" for something must be broken into separate segments and
> threaded together via Messages and Intents and whatnot -- waiting in
> any form is verboten (at least in the UI thread, or any thread that
> uses an event loop).  Takes a whole new mindset to design an activity
> that must, eg, handle a communication protocol or handshake with an
> asynchronous activity.
>
> On Oct 8, 6:47 pm, Jeremy Wadsack  wrote:
>
>
>
> > Actually, having thought about this more, I recall my original intent
> > was to only spawn the thread for the time needed to do the task. That
> > means I don't have to worry about shutting down or closing the thread
> > when the application closes. (The task responds to the application
> > through one or more listeners that are Runnables, but it checks if
> > they are null before calling them.)
>
> > This approach assumes that the gc in Dalvik won't mind spinning up
> > objects and threads and destroying them regularly. I don't know if
> > that's better practice for the jvm, but this seems less likely to
> > produce leaks, right?
>
> > I changed the code to use a handler on the main thread. The handler,
> > when it receives a message, starts a new thread with the long-running
> > task. Unfortunately the handleMessage method is never called when the
> > object is built from my test code.
>
> > So let's take the threading out of it for a moment. Why does this
> > basic test case fail?
>
> > import android.os.Handler;
> > import android.os.Message;
>
> > public class TaskManagerExample {
>
> >           // Test field for inspection
> >           public boolean messageHandled = false;
>
> >           private Handler handler = new Handler() {
> > 

[android-developers] Re: Unit testing a class that uses android.os.Handler

2010-10-08 Thread Jeremy Wadsack
Actually, having thought about this more, I recall my original intent
was to only spawn the thread for the time needed to do the task. That
means I don't have to worry about shutting down or closing the thread
when the application closes. (The task responds to the application
through one or more listeners that are Runnables, but it checks if
they are null before calling them.)

This approach assumes that the gc in Dalvik won't mind spinning up
objects and threads and destroying them regularly. I don't know if
that's better practice for the jvm, but this seems less likely to
produce leaks, right?

I changed the code to use a handler on the main thread. The handler,
when it receives a message, starts a new thread with the long-running
task. Unfortunately the handleMessage method is never called when the
object is built from my test code.

So let's take the threading out of it for a moment. Why does this
basic test case fail?


import android.os.Handler;
import android.os.Message;

public class TaskManagerExample {

  // Test field for inspection
  public boolean messageHandled = false;

  private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
messageHandled = true;
}
  };

  public void start() {
  handler.sendEmptyMessage(0);
  }

}


import android.app.Application;
import android.test.ApplicationTestCase;

public class TaskManagerExampleTest extends
ApplicationTestCase {

public TaskManagerExampleTest() {
super(Application.class);
}

public void testHandlerShouldReceiveMessagesPostedToIt() {
TaskManagerExample example = new TaskManagerExample();
example.start();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
assertTrue(example.messageHandled);
}

}


I put the sleep in there, just in case messages sent to the queue take
some time to get processed. Seems half a second should be plenty of
time (and keeps the test responsive). I tried it with five seconds and
it still fails.

What base *TestCase class should I be using the get Handlers, Loopers
and the MessageQueue to run under test?

--
Jeremy Wadsack

On Oct 8, 8:41 am, Lance Nanek  wrote:
> Handler has multiple constructors. The ones that take a Looper
> argument can take the Looper for a Thread other than the current one.
> That way you don't need to create the Handler on that Thread and it is
> easier to ensure it is not null on the Thread using it. There's also
> an android.os.HandlerThread utility class that is pretty much just a
> Thread with a Looper. It has a getLooper method that's easy to feed
> into the Handler constructor and that avoids the issue with prepare()
> taking a while sometimes and leaving you with a null longer than you'd
> expect.
>
> On Oct 7, 8:04 pm, DanH  wrote:
>
>
>
> > Come to think of it, how would one create a Handler for another
> > thread?  You'd have to dispatch the thread and have it create the
> > Handler and pass the pointer back to you (we won't worry about how),
> > but then that thread needs to go into a message receive loop.
>
> >  Apparently this is done via Looper.  I'm guessing the code would be
> > like this:
>
> >   class LooperThread extends Thread {
> >       public Handler mHandler;
>
> >       public void run() {
> >           Looper.prepare();
>
> >           mHandler = new Handler();
>
> >           Looper.loop();
> >       }
> >   }
>
> > You'd start this thread and then use your pointer to it to access
> > mHandler (though you'd have to guard somehow against getting a null
> > before the reference was set).  Then dispatch Runnables or Messages
> > via that handler.
>
> > (Gotta wonder where Looper stashes the instance it creates of itself
> > to attach to the Thread.  I suppose it uses ThreadLocal.)
>
> > On Oct 7, 4:38 pm, DanH  wrote:
>
> > > But I don't see anywhere in the Handler spec where it says the thread
> > > will be dispatched.  It appears to me that when the thread is posted,
> > > Handler will just run its "run" method, without starting the thread.
> > > If you wanted to run on a separate thread it appears to me that you'd
> > > have to start the thread, have that thread create a Handler and pass
> > > it back to you somehow, and then post via THAT Handler.
>
> > > At least that's how I'd interpret this:  "Each Handler instance is
> > > associated with a single thread 

[android-developers] Re: Unit testing a class that uses android.os.Handler

2010-10-07 Thread Jeremy Wadsack
Right. A Thread is a Runnable but treating it like a Runnable may not
launch it on a separate Thread. I'll re-organize this around a single
Thread.

Thanks for the code review and suggestions. Once again proving that
automated testing and code review leads to better quality code.

--
Jeremy Wadsack

On Oct 7, 2:38 pm, DanH  wrote:
> But I don't see anywhere in the Handler spec where it says the thread
> will be dispatched.  It appears to me that when the thread is posted,
> Handler will just run its "run" method, without starting the thread.
> If you wanted to run on a separate thread it appears to me that you'd
> have to start the thread, have that thread create a Handler and pass
> it back to you somehow, and then post via THAT Handler.
>
> At least that's how I'd interpret this:  "Each Handler instance is
> associated with a single thread and that thread's message queue. When
> you create a new Handler, it is bound to the thread / message queue of
> the thread that is creating it -- from that point on, it will deliver
> messages and runnables to that message queue and execute them as they
> come out of the message queue."
>
> On Oct 7, 4:25 pm, Jeremy Wadsack  wrote:
>
>
>
> > Fair point. The "// Do some tasks" is doing long-running (Internet-
> > connected) stuff, so I want it to run in a separate thread. As I
> > understand, posting the Runnable without a thread would run it on the
> > main thread.
>
> > I assume the gc will clean up the Threads as they expire, but I could
> > also redesign this to have a single active thread that posts Runnables
> > (or even just messages) to it's own MessageQueue at specified
> > intervals. Then I'd be managing the looper myself (that is, calling
> > Looper.loop), which would probably resolve this issue.
>
> > That doesn't answer the original question but it may be the right
> > approach if it's more "android-y".
>
> > --
> > Jeremy Wadsack
>
> > On Oct 7, 1:20 pm, DanH  wrote:
>
> > > Kind of off-topic, but why are you creating a new Thread with each
> > > post, vs simply posting the Runnable?
>
> > > On Oct 5, 5:47 pm, Jeremy Wadsack  wrote:
>
> > > > I have a class that uses a Handler for a timed, asynchronous activity.
> > > > Something like this:
>
> > > > public class SampleClass {
> > > >   private static final long DELAY = 3;
> > > >   private boolean isRunning = false;
> > > >   private Handler handler = new Handler();
>
> > > >   public start() {
> > > >     if (!isRunning) {
> > > >       isRunning = true;
> > > >       handler.post(new Thread(task));
> > > >     }
> > > >   }
>
> > > >   public stop() {
> > > >     isRunning = false;
> > > >   }
>
> > > >   private Runnable task = new Runnable() {
> > > >     public void run() {
> > > >       if (!isRunning) {
> > > >         return;
> > > >       }
>
> > > >       // Do some tasks
> > > >       handler.postDelayed(new Thread(this), DELAY);
> > > >     }
> > > >   }
>
> > > > }
>
> > > > I am trying to write a unit test (without having to implement an
> > > > activity that instantiates the class) but I can't seem to get the
> > > > items that are posted to the MessageQueue to ever be fired. Inheriting
> > > > from junit.framework.TestCase doesn't work, but then there wouldn't be
> > > > a MessageQueue for the handler, I'd expect (although, there's no
> > > > error, but the Runnable never gets called). I tried inheriting the
> > > > test class from AndroidTestCase and ApplicationTestCase
> > > > but neither of those works, even though the former is supposed to
> > > > provide a Context and the latter "all the life cycle of an
> > > > application."
>
> > > > Anyone have any pointers?
>
> > > > --
> > > > Jeremy Wadsack

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Unit testing a class that uses android.os.Handler

2010-10-07 Thread Jeremy Wadsack
Fair point. The "// Do some tasks" is doing long-running (Internet-
connected) stuff, so I want it to run in a separate thread. As I
understand, posting the Runnable without a thread would run it on the
main thread.

I assume the gc will clean up the Threads as they expire, but I could
also redesign this to have a single active thread that posts Runnables
(or even just messages) to it's own MessageQueue at specified
intervals. Then I'd be managing the looper myself (that is, calling
Looper.loop), which would probably resolve this issue.

That doesn't answer the original question but it may be the right
approach if it's more "android-y".

--
Jeremy Wadsack

On Oct 7, 1:20 pm, DanH  wrote:
> Kind of off-topic, but why are you creating a new Thread with each
> post, vs simply posting the Runnable?
>
> On Oct 5, 5:47 pm, Jeremy Wadsack  wrote:
>
>
>
> > I have a class that uses a Handler for a timed, asynchronous activity.
> > Something like this:
>
> > public class SampleClass {
> >   private static final long DELAY = 3;
> >   private boolean isRunning = false;
> >   private Handler handler = new Handler();
>
> >   public start() {
> >     if (!isRunning) {
> >       isRunning = true;
> >       handler.post(new Thread(task));
> >     }
> >   }
>
> >   public stop() {
> >     isRunning = false;
> >   }
>
> >   private Runnable task = new Runnable() {
> >     public void run() {
> >       if (!isRunning) {
> >         return;
> >       }
>
> >       // Do some tasks
> >       handler.postDelayed(new Thread(this), DELAY);
> >     }
> >   }
>
> > }
>
> > I am trying to write a unit test (without having to implement an
> > activity that instantiates the class) but I can't seem to get the
> > items that are posted to the MessageQueue to ever be fired. Inheriting
> > from junit.framework.TestCase doesn't work, but then there wouldn't be
> > a MessageQueue for the handler, I'd expect (although, there's no
> > error, but the Runnable never gets called). I tried inheriting the
> > test class from AndroidTestCase and ApplicationTestCase
> > but neither of those works, even though the former is supposed to
> > provide a Context and the latter "all the life cycle of an
> > application."
>
> > Anyone have any pointers?
>
> > --
> > Jeremy Wadsack

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Unit testing a class that uses android.os.Handler

2010-10-07 Thread Jeremy Wadsack
Digging deeper into the Android source code, it looks like this must
have an active MessageQueue or it would throw an exception. In fact,
adding some logging, shows that the Looper is running and the messages
are being posted to the queue:

10-07 10:51:27.809: VERBOSE/Sample(940): Looper{437942d0}
10-07 10:51:27.809: VERBOSE/Sample(940): mRun=true
10-07 10:51:27.809: VERBOSE/Sample(940): mThread=Thread[Instr:
android.test.InstrumentationTestRunner,5,main]
10-07 10:51:27.809: VERBOSE/Sample(940):
mqueue=android.os.messagequ...@437942f0
10-07 10:51:27.820: VERBOSE/Sample(940):   Message 0: { what=0
when=159828381 }
10-07 10:51:27.820: VERBOSE/Sample(940):   Message 1: { what=0
when=159833447 }
10-07 10:51:27.820: VERBOSE/Sample(940):   Message 2: { what=0
when=159838517 }
10-07 10:51:27.820: VERBOSE/Sample(940):   Message 3: { what=0
when=159843689 }
10-07 10:51:27.820: VERBOSE/Sample(940):   Message 4: { what=0
when=159848756 }
10-07 10:51:27.820: VERBOSE/Sample(940): (Total messages: 5)

This is after running five unit tests. All of them get posted, but are
never run.

Therefore, the system is clearly preparing the Looper, assigning the
MessageQueue and posting the messages (Runnables) from the thread.
However, it is never calling loop on the Looper.

Any ideas what I need to do to get this to work? Note that the system
works under an application, it just doesn't work under test.


--
Jeremy Wadsack

On Oct 5, 3:47 pm, Jeremy Wadsack  wrote:
> I have a class that uses a Handler for a timed, asynchronous activity.
> Something like this:
>
> public class SampleClass {
>   private static final long DELAY = 3;
>   private boolean isRunning = false;
>   private Handler handler = new Handler();
>
>   public start() {
>     if (!isRunning) {
>       isRunning = true;
>       handler.post(new Thread(task));
>     }
>   }
>
>   public stop() {
>     isRunning = false;
>   }
>
>   private Runnable task = new Runnable() {
>     public void run() {
>       if (!isRunning) {
>         return;
>       }
>
>       // Do some tasks
>       handler.postDelayed(new Thread(this), DELAY);
>     }
>   }
>
> }
>
> I am trying to write a unit test (without having to implement an
> activity that instantiates the class) but I can't seem to get the
> items that are posted to the MessageQueue to ever be fired. Inheriting
> from junit.framework.TestCase doesn't work, but then there wouldn't be
> a MessageQueue for the handler, I'd expect (although, there's no
> error, but the Runnable never gets called). I tried inheriting the
> test class from AndroidTestCase and ApplicationTestCase
> but neither of those works, even though the former is supposed to
> provide a Context and the latter "all the life cycle of an
> application."
>
> Anyone have any pointers?
>
> --
> Jeremy Wadsack

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Unit testing a class that uses android.os.Handler

2010-10-05 Thread Jeremy Wadsack
I have a class that uses a Handler for a timed, asynchronous activity.
Something like this:

public class SampleClass {
  private static final long DELAY = 3;
  private boolean isRunning = false;
  private Handler handler = new Handler();

  public start() {
if (!isRunning) {
  isRunning = true;
  handler.post(new Thread(task));
}
  }

  public stop() {
isRunning = false;
  }

  private Runnable task = new Runnable() {
public void run() {
  if (!isRunning) {
return;
  }

  // Do some tasks
  handler.postDelayed(new Thread(this), DELAY);
}
  }
}


I am trying to write a unit test (without having to implement an
activity that instantiates the class) but I can't seem to get the
items that are posted to the MessageQueue to ever be fired. Inheriting
from junit.framework.TestCase doesn't work, but then there wouldn't be
a MessageQueue for the handler, I'd expect (although, there's no
error, but the Runnable never gets called). I tried inheriting the
test class from AndroidTestCase and ApplicationTestCase
but neither of those works, even though the former is supposed to
provide a Context and the latter "all the life cycle of an
application."

Anyone have any pointers?

--
Jeremy Wadsack

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Android media player not reading ID3 tags

2010-10-04 Thread Jeremy Wadsack
On Oct 3, 3:51 pm, DraganA  wrote:
> I wonder if anyone knows whether the built in media player uses some
> kind of caching of mp3 files ID3 tag information, because after I
> change the tag of a file it doesn't show the updated data. Only after
> the phone restart, I guess after /sdcard remount, does it show correct
> tag info.

Android has the MediaScanner that looks at the media on the device
(internal and external storage) and builds a database of the tags for
MP3 (and other files). This runs one start-up and can be triggered by
sdcard mount/unmount. There is an open API to the MediaScanner that
you can use to tell it to re-scan a single file.

See scanFile in the MedisScannerConnection class.
http://developer.android.com/reference/android/media/MediaScannerConnection.html#scanFile(android.content.Context,
java.lang.String[], java.lang.String[],
android.media.MediaScannerConnection.OnScanCompletedListener)

--
Jeremy Wadsack

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: How to make screen shoots with an android device?

2010-09-09 Thread Jeremy Wadsack
I find it surprising that the Android system can't do this natively. It's
built into the iPhone (although it's not intuitive or discoverable and
possibly not programmable). That said, the solution Renas provides in that
thread is straightforward and easy. I'll keep that as a snippet.

Following on your point in that thread, doing direct screen-shot comparison
between "expected" and "actual" will rarely match in any environment. For
this case it will absolutely *not* match because (1) the compression is JPEG
and (2) Android adapts display layout for the device (and I'm not sure this
is determinate). For testing you need to have some tolerance of difference
between the screen shots. In my experience, I've found this is the kind of
thing that humans are much better at than computers. We can easily see if
the screen is "right" and whether it "makes sense". Computers, at best, can
tell us that there is some amount of "difference".


--
Jeremy Wadsack


On Thu, Sep 9, 2010 at 8:24 AM, Fabrizio Giudici <
fabrizio.giud...@tidalwave.it> wrote:

>
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 9/9/10 16:20 , Lidia G wrote:
> > Thank you
> >
> Have a look at this thread:
>
>
> http://groups.google.com/group/robotium-developers/browse_thread/thread/c5cf28ef88918d7d/38a80fd483c114df?hl=en&lnk=gst&q=Need+help+to+take+screen+shot#38a80fd483c114df
>
> - --
> Fabrizio Giudici - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> java.net/blog/fabriziogiudici - www.tidalwave.it/people
> fabrizio.giud...@tidalwave.it
> -BEGIN PGP SIGNATURE-
> Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkyI/DUACgkQeDweFqgUGxc3fwCeKYHbPO3l7clkKwzF64XT0AOz
> ldsAn0s9XYs0VGptQ6og30scPUv4bWUi
> =+rLV
> -END PGP SIGNATURE-
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Android Radio streamer Class

2010-09-04 Thread Jeremy Wadsack
npr-android-app.googlecode.com

But I think you could have found that with a little effort. ;)

- Jeremy

On Sep 3, 2010 1:59 PM, "Ahmed Shoeib" 
wrote:
> do you have alink for this app
>
> On Sep 3, 10:29 pm, Jeremy Wadsack  wrote:
>> The NPR android app on Google code is open source. It streams mp3 and any
>> other natively supported stream. I doubt it supports WAV.
>>
>> - Jeremy
>>
>> On Sep 3, 2010 12:43 PM, "Ahmed Shoeib" 
>> wrote:
>>
>> > Hi all ,
>>
>> > i have some question about android streamer class
>>
>> > 1 - is there is an open-source streamer class for android ( streamer
>> > class include [ mp3 , WM , AAC ] and include meta data about the
>> > file ?
>>
>> > and if there is an streamer class for android can you support a link
>> > for it ?
>>
>> > Thanks ,
>>
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Android Developers" group.
>> > To post to this group, send email to
android-developers@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > android-developers+unsubscr...@googlegroups.com

>
>> > For more options, visit this group at
>> >http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Android Radio streamer Class

2010-09-03 Thread Jeremy Wadsack
The NPR android app on Google code is open source. It streams mp3 and any
other natively supported stream. I doubt it supports WAV.

- Jeremy

On Sep 3, 2010 12:43 PM, "Ahmed Shoeib" 
wrote:
> Hi all ,
>
> i have some question about android streamer class
>
> 1 - is there is an open-source streamer class for android ( streamer
> class include [ mp3 , WM , AAC ] and include meta data about the
> file ?
>
>
> and if there is an streamer class for android can you support a link
> for it ?
>
>
> Thanks ,
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Split Path to get filename and extension

2010-09-03 Thread Jeremy Wadsack
This is basic java. It's not Android specific.


String filename = "something.ext";
String extension = null;
int lastDotPosition = filename.lastIndexOf('.');
if( lastDotPosition > 0 ) {
  extension = filename.substring(lastDotPosition + 1);
}


--
Jeremy Wadsack


On Fri, Sep 3, 2010 at 11:57 AM, Pedro Teixeira
wrote:

> And how is that done?
> I found examples in javascript using the lastindexof ...but cant find
> anything for android java..
>
>
> On Sep 3, 2010, at 6:52 PM, Filip Havlicek wrote:
>
> Just select extension as string from . to the end and filename as string
> from last / to last .
>
> Best regards,
> Filip Havlicek
>
> 2010/9/3 Maps.Huge.Info (Maps API Guru) 
>
>> Have you looked at File?
>>
>> -John Coryat
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
>
> Pedro Teixeira
>
> www.pedroteixeira.org
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] client Server

2010-09-01 Thread Jeremy Wadsack
>
> > is it possible that if I maintain a server at one laptop and
> connect 2 or 3 laptops through LAN and then   responding to
> their requests sent by the emulators of individual laptop.
>

This should be possible as it's standard networking, but you'll need to do a
couple things. First, make sure that the emulators, if they are hosting
servers, have mapped ports that are visible to the laptop. See about port
forwarding with
adb<http://developer.android.com/guide/developing/tools/adb.html#forwardports>.
Second, make sure that the firewalls on the server laptops are disabled or,
better, that the ports are opened in the firewalls. (Of course, for
security, if you disable the firewalls, make sure the laptops are off the
Internet.)


> 2)Can this be done using blue tooth.
>

I don't have any experience with bluetooth in emulators, but Android
Bluetooth<http://developer.android.com/guide/topics/wireless/bluetooth.html>certainly
has support for client-server connections.


> Can we build an application for mobiles such that while downloading
> anything through mobile it would ask to the user whether to save it
> on mobile or laptop.Thus downloaded content can be saved on laptops
> through mobiles.
>

Seems plausible. If the application itself initiates the download it can
choose to store in it's data folder, on the sdcard or you could create a
DataProvider that wrote the data off to some server hosted on a laptop
somewhere.


--
Jeremy Wadsack

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Android streamer Class

2010-09-01 Thread Jeremy Wadsack
MediaPlayer will stream MP3 (shoutcast) streams on FroYo. It will only
support 3GP before that (unless you run through a proxy and remove the ICY
header or download the file first). I don't know about other formats but
suspect you'll need to include your own codec decoders and that probably is
best done in C++ with the Native Toolkit.

--
Jeremy Wadsack


On Wed, Sep 1, 2010 at 1:45 PM, Ahmed Shoeib
wrote:

> Hi all ,
> i want a class implements radio streamer
> the application should streams radio from url
> the streamer should include ( MP3 , WM , AAC ) ..
>
> can anyone help me ???
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Using socket in a service communicating with more activities...

2010-09-01 Thread Jeremy Wadsack
Probably the best path to take would be to move your thread into a
Service<http://developer.android.com/reference/android/app/Service.html>.
Then use 
Intents<http://developer.android.com/guide/topics/intents/intents-filters.html>or
binding to connect activities to the service. Similarly you can have
the
service broadcast intents and use a
BroadcastReceiver<http://developer.android.com/reference/android/content/BroadcastReceiver.html>with
an
IntenetFilter<http://developer.android.com/guide/topics/intents/intents-filters.html>to
listen for those messages from the service.

Have a look at the Application
Fundamentals<http://developer.android.com/guide/topics/fundamentals.html>in
the Dev Guide and the sample code that ships with the SDK for examples
of
how to do this.

--
Jeremy Wadsack


On Sun, Aug 29, 2010 at 12:16 PM, kukukk  wrote:

> Hy!
>
> I want to create an application to remote control my PC. For example:
> Volume (get actual volume level, increase/decrease/mute volume),
> TVtime (start/quit tvtime, get actual channel, toggle fulscreen,
> channel up/down, toggle input source, toggle aspect ratio), Amarok
> (start/quit amarok, get current song, prev/next song, play/stop/
> pause), etc.
> The application for the PC is done (in python).
> The communication protocol used is very simple. For example:
> "volume:get_level", "volume:up", "volume:mute", etc.
> Now I'm working on the android application. What I have implemented
> till now is to create an activity, with:
> - an edittext to enter host:port
> - a button to connect/disconnect to/from server
> - the onCreate method creates a new thread for socket communication to
> send/receive messages to/from PC.
> - a textview to display information received from PC (eg. volume
> level)
> - a button to send command to PC
> I'm using handler to communicate between the tcpclient thread and the
> main activity. It is working...
> But I want to use more than 1 activity. I want to use different
> activity for every program controlled. Searching for a solution to
> transfer the thread's handler to a new activity I have found that it
> is not possible, and I have to use a service.
> So, my question is: how to send message from different activities to
> the same service, how to send message from service to the actual
> activity and how can I check in the service which is the actual
> activity?
>
> Because the service is running in the same thread as the activities I
> suppose that I still have to create a new thread for socket
> communication. How can I send the data received by the socket to the
> service?
>
> Thanks in advance,
> kukukk
>
> PS. I hope you understand my question and sorry if it is not the right
> forum for it
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] What is the class name of media scanner service?

2010-09-01 Thread Jeremy Wadsack
http://www.netmite.com/android/mydroid/external/opencore/android/mediascanner.cpp

--
Jeremy Wadsack


On Tue, Aug 31, 2010 at 9:19 PM, Agus  wrote:

> What is the class name of media scanner service?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Help with simple Bitmap issue

2010-08-31 Thread Jeremy Wadsack
What's the error message?

--
Jeremy Wadsack


On Tue, Aug 31, 2010 at 11:16 AM, Pedro Teixeira
wrote:

> Any clue about this? anyone?
>
>
> On Aug 31, 2010, at 4:26 PM, Pedro Teixeira wrote:
>
>  Hi there...
>> I'm having an issue with a Bitmap which is giving me an error but any
>> kind of report so I can understand it..
>> The code is simpley this this:
>>
>> - I get a image path from a bundle:
>>   Bundle w = getIntent().getExtras();
>>final String thenPicPath= w.getString("oldpicpath");
>>
>> - And I set it on a ImageView called returnpic:
>>   Bitmap oldPicture = BitmapFactory.decodeFile(thenPicPath);
>>   returnpic.setImageBitmap(oldPicture);
>>
>>
>> In the debugger the String thenPicPath reads : /sdcard/download/
>> 7122gato.jpg
>> And the oldPicture Bitmap reads: android.graphics.bit...@437700c0
>>
>> Everything looks fine but I get and error when setting the
>> imagebitmap.. any clue?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
> Pedro Teixeira
>
> www.pedroteixeira.org
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] using javascripts v3 api in android - help required urgently

2010-08-31 Thread Jeremy Wadsack
You could build your own WebView container activity and run your JS there.
Or you could use some off-the-shelf package that does this like Phonegap or
Appcelerator.

If you want to run native JS without the web view, then I think you'll need
to bundle your own interpreter or use a cross-compiler. Unless V8 is exposed
to the app framework somehow, but I don't off hand see any mention of that.

--
Jeremy Wadsack


On Tue, Aug 31, 2010 at 7:51 AM, anushree wrote:

> hello all,
> i am trying to develop a google maps application for android using
> javascripts v3 api. but the main problem is that i haven't worked with
> javascripts for android application development..
> i have only used java code to develop an application
> so i don't know where to start..
> has anyone used javascripts for development in android??
> if so,
> please can you help me by providing the code of your application so
> that i can learn how to develop using javascripts in android..
> thanks-
> anushree
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] How to you think about the future of PhoneGap

2010-08-30 Thread Jeremy Wadsack
PhoneGap is documented (http://www.phonegap.com/docs,
http://phonegap.pbworks.com/) and active (http://www.phonegap.com/community,
http://groups.google.com/group/phonegap?pli=1).


--
Jeremy Wadsack


On Mon, Aug 30, 2010 at 2:45 AM, pyleaf  wrote:

> Hi, guys!
> Today, I discover PhoneGap.Unluckily, there is no enough docement about it.
> How to you think about the future of PhoneGap?
> Thank you!
>
> --
> Believing is Everything.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Media Player

2010-08-30 Thread Jeremy Wadsack
If the URL is an mp3 stream (shoutcast streaming server), then my
understanding (and experience) is that this was not supported before
2.2. In 2.2 the new Stagefright player now supports reading from
shoutcast streams. [http://developer.android.com/sdk/android-2.2-
highlights.htm]

For support on older platforms, you can create a local proxy that
changes the response protocol from ICY (shoutcast) to HTTP, which the
mediaplayer will support.

See an example in the NPR Android App source code:
http://code.google.com/p/npr-android-app/source/browse/trunk/Npr/src/org/npr/android/news/StreamProxy.java

--
Jeremy Wadsack

On Aug 25, 4:46 am, veer  wrote:
> Hi all,
> I'm really stuck up with this.
>
> Our team recently bought an android 1.6 device.
> I know android 1.6 media player had some issues,
> But i need to make it work for 1.6, as thats the only device i have
> for demos.
>
> My code is as below
>
> MediaPlayer mp = new MediaPlayer();
> mp.setDataSource(URL);
> mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
> mp.prepare();
> mp.start();
>
> this code always fails at mp.prepare();
>
> This is a problem only with Android 1.6
> Android 2.2 it works fine..
>
> ERROR:
>
> D/PlayerDriver( 30): buffering (3)
> D/PlayerDriver( 30): buffering (12)
> D/PlayerDriver( 30): buffering (15)
> D/PlayerDriver( 30): buffering (18)
> D/PlayerDriver( 30): buffering (21)
> D/PlayerDriver( 30): buffering (25)
> D/PlayerDriver( 30): buffering (28)
> D/PlayerDriver( 30): buffering (31)
> D/PlayerDriver( 30): buffering (35)
> E/PlayerDriver( 30): Command PLAYER_INIT completed with an error or
> info PVMFFailure
> E/MediaPlayer( 200): error (1, -1)
> W/System.err( 200): java.io.IOException: Prepare failed.: status=0x1
> W/System.err( 200): at android.media.MediaPlayer.prepare(Native
> Method)
> W/System.err( 200): at
> com.tcs.channels.mobile.ChannelsHome.playAudio(ChannelsHome.java:608)
>
> I NEED THIS WORKING ON 1.6
> HAS ANYONE BEEN SUCSESSFULL
> ANY HELP WUD BE HIGHLY APPRECIATED.
>
> I have tried setting content type to audio/mpeg,
> tried writing the file to SD card first then playing it..
> Everythin works on 2.2 but not on 1.6..

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: String being truncated when its long

2010-08-30 Thread Jeremy Wadsack
Explicitly stating the buffer size to use (8000) is recommended by the
BufferedReader API. If you don't do this it will throw warnings in the log
suggesting that you do. Of course you could use a different size buffer
(e.g. if you know your content is much less than that size).

For very large content (in MB or more) and streams (or other unknown content
sizes), web servers will chunk the
content<http://en.wikipedia.org/wiki/Chunked_transfer_encoding>,
and you'll need to detect this and gather the parts.You can check the
headers returned in the response to detect for this. However, I doubt this
is happening in your case.

I have built android apps that pull MB of data over HTTP, so I don't think
there's an inherent limit in the android framework here. You could directly
using Stream.read instead of using a reader if you want to test this without
the middle layers (removes the question of readLine failing for other
reasons, if that's possible).

InputStream proxyStream = http.getContent();
 try {
int readBytesProxy = -1;
byte[] buffProxy = new byte[1024 * 50];
 while ((readBytesProxy = proxyStream.read(buffProxy)) != -1) {
// Do something with your data
}
} catch (Exception ex) {
Log.e(TAG, "Error streaming file content", ex);
} finally {
if (proxyStream != null) {
proxyStream.close();
}
}


Also, check your server too. Try pulling the source with curl or wget and
see if you get more than the 5k that you get with the app.

--
Jeremy Wadsack


On Fri, Aug 27, 2010 at 9:32 AM, DanH  wrote:

> I certainly hope that available Android memory is more than 3000
> characters.
>
> On Aug 27, 5:14 am, Droid  wrote:
> > I think you are hitting a capacity limit of the android and should
> > chunk it somehow at say 3000 chars and store the chars somewhere not
> > in memory.
> > Droid
> >
> > On Aug 27, 12:13 am, Achanta  wrote:
> >
> > > I Tested your suggestions by setting UTF-8 and I also tried the same
> > > by removing the length 8000. But it still does the same thing.
> > > Thank you for the response though.
> >
> > > This thing is driving me nuts.
> >
> > > On Aug 26, 4:58 pm, Jake Radzikowski 
> > > wrote:> reader = new BufferedReader(new InputStreamReader(inputStream),
> 8000); I'm
> > > > gunna guess that 8000 has something to do with it :). I usually use
> the
> > > > following:
> >
> > > > reader = new BufferedReader(new InputStreamReader(inputStream,
> "UTF-8"));
> >
> > > > On Thu, Aug 26, 2010 at 3:40 PM, Achanta 
> wrote:
> >
> > > > > I am trying to get a JSON response from our server and the response
> > > > > string seems is always being truncated when the string length
> reaches
> > > > > to around 5525 characters.
> >
> > > > > HttpClient httpClient = new DefaultHttpClient();
> > > > > HttpPost post = new HttpPost(URL);
> > > > > ResponseHandler responseHandler= new
> BasicResponseHandler();
> > > > > String testResponse = httpClient.execute(post, responseHandler);
> >
> > > > > I also tried this by using HttpEntity and reading the response
> stream.
> > > > > But that also truncates the string at approximately that length.
> >
> > > > >HttpClient httpClient = new DefaultHttpClient();
> > > > >HttpPost post = new HttpPost(URL);
> > > > > //  HttpGet get = new HttpGet(URL);
> >
> > > > >HttpResponse response = null;
> > > > >HttpEntity entity = null;
> > > > >InputStream inputStream = null;
> > > > >BufferedReader reader = null;
> > > > >String result = "";
> > > > >try {
> > > > >response = (HttpResponse)httpClient.execute(post);
> > > > >entity = response.getEntity();
> > > > >if(entity != null){
> > > > >inputStream = entity.getContent();
> > > > >}
> > > > >reader = new BufferedReader(new
> > > > > InputStreamReader(inputStream), 8000);
> > > > >StringBuffer builder = new StringBuffer("");
> > > > >String line = reader.readLine();
> > > > >while(line != null){
> > > > >Log.v(tag, "int max:
> "+Integer.MAX_VALUE);
> > > > >Log.v(tag, &q