Very simple stuff, and it fires off the Email client, from an "Import from Email" button in my app.
My application is also registered with an <intent-filter> to open PDF files. So, if I use the above Intent to open up the Email client, find an email with a PDF attachment, download it, launch it, select my application from the chooser... then everything loads great.
Now if I hit my "Import from Email" button again, the intent runs, but the Email client is never brought into the foreground.
Am I missing something when using startActivity() to (re)launch the correct app? I have tried checking if the intent is OK by following this http://developer.android.com/training/basics/intents/sending.html#Verify but it always returns true (and that makes sense, as it can find the Application, but it's just not bringing it to the foreground).
I have also tried using startActivityForResult(), but as explained in the Android docs, this fires off a "cancel" immediately, because the Activity is not Explicit, but Implicit (thought I'd try it, just in case).
I feel like I'm missing something, a step, a call to something... or have I hit upon some strange loop that works in one case, but cannot keep looping? Any help/pointers would be greatly appreciated!
> Very simple stuff, and it fires off the Email client, from an "Import from
> Email" button in my app.
> My application is also registered with an <intent-filter> to open PDF
> files.
> So, if I use the above Intent to open up the Email client, find an email
> with a PDF attachment, download it, launch it, select my application from
> the chooser... then everything loads great.
> Now if I hit my "Import from Email" button again, the intent runs, but the
> Email client is never brought into the foreground.
> Am I missing something when using startActivity() to (re)launch the
> correct app?
> I have tried checking if the intent is OK by following this
> http://developer.android.com/training/basics/intents/sending.html#Ver... it always returns true (and that makes sense, as it can find the
> Application, but it's just not bringing it to the foreground).
> I have also tried using startActivityForResult(), but as explained in the
> Android docs, this fires off a "cancel" immediately, because the Activity
> is not Explicit, but Implicit (thought I'd try it, just in case).
> I feel like I'm missing something, a step, a call to something... or have
> I hit upon some strange loop that works in one case, but cannot keep
> looping? Any help/pointers would be greatly appreciated!
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
First, "com.android.email" is not an API. That is the internal identifier
for the current e-mail application that is part of AOSP; there is *no*
guarantee that such a thing will ever exist on the device.
Second, more specific to your issue here, getLaunchIntentForPackage()
returns a *launch* intent, for use in semantics like an app launcher. What
you are asking for is not an app launcher; you want to run flow as part of
your own task, not launch something different. In particular, what this
Intent will do is bring the current e-mail app to the foreground *in
whatever state it was last in*. The user may have been in the middle of
composing a message, viewing something, etc. It isn't saying to bring them
to the list of e-mail messages for them to import something.
One other thing, when you say startActivityForResult() is not working, this
is not because of an explicit vs. implicit Intent; this is because part of
what getLaunchIntentForPackage() does is set FLAG_ACTIVITY_NEW_TASK, which
says to launch the Intent as a separate task from yours (bringing an
existing task to the foreground etc), which is central to the semantics of
this being for app launchers not in-task UI flow.
> Very simple stuff, and it fires off the Email client, from an "Import from
> Email" button in my app.
> My application is also registered with an <intent-filter> to open PDF
> files.
> So, if I use the above Intent to open up the Email client, find an email
> with a PDF attachment, download it, launch it, select my application from
> the chooser... then everything loads great.
> Now if I hit my "Import from Email" button again, the intent runs, but the
> Email client is never brought into the foreground.
> Am I missing something when using startActivity() to (re)launch the
> correct app?
> I have tried checking if the intent is OK by following this
> http://developer.android.com/training/basics/intents/sending.html#Ver... it always returns true (and that makes sense, as it can find the
> Application, but it's just not bringing it to the foreground).
> I have also tried using startActivityForResult(), but as explained in the
> Android docs, this fires off a "cancel" immediately, because the Activity
> is not Explicit, but Implicit (thought I'd try it, just in case).
> I feel like I'm missing something, a step, a call to something... or have
> I hit upon some strange loop that works in one case, but cannot keep
> looping? Any help/pointers would be greatly appreciated!
> --
> 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+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails. All such
questions should be posted on public forums, where I and others can see and
answer them.
I think this may well do the trick! Just when you think you've scoured the docs looking for the right answer, someone else goes and finds it for you :-)
And the specific email app is what our client wants. Mind you, a chooser would be a better approach and are used elsewhere. Will see about convincing them of this, instead.
I knew I was missing something... turns out it's not just *one* thing I was missing, but a whole host of them.
As I said in the other post, this was the decision made by the client, but would look to (and rather!) invoke a chooser for mail applications.
With regards to the launching Intent, I'm clearly missing something as to the best approach for this, or at least, missing an understanding of the mechanisms Android employs in order to launch this. We only wanted to launch the Email client, be able to browse/check this, download some files and launch our application again. Is there actually a better approach? From what you're saying, I'm almost certainly doing it wrong - but am a little stumped as to the *right* way.
> First, "com.android.email" is not an API. That is the internal identifier > for the current e-mail application that is part of AOSP; there is *no* > guarantee that such a thing will ever exist on the device.
> Second, more specific to your issue here, getLaunchIntentForPackage() > returns a *launch* intent, for use in semantics like an app launcher. What > you are asking for is not an app launcher; you want to run flow as part of > your own task, not launch something different. In particular, what this > Intent will do is bring the current e-mail app to the foreground *in > whatever state it was last in*. The user may have been in the middle of > composing a message, viewing something, etc. It isn't saying to bring them > to the list of e-mail messages for them to import something.
> One other thing, when you say startActivityForResult() is not working, > this is not because of an explicit vs. implicit Intent; this is because > part of what getLaunchIntentForPackage() does is set > FLAG_ACTIVITY_NEW_TASK, which says to launch the Intent as a separate task > from yours (bringing an existing task to the foreground etc), which is > central to the semantics of this being for app launchers not in-task UI > flow.
> On Thu, Aug 23, 2012 at 7:16 AM, Mark Jawdoszak <evil...@gmail.com<javascript:> > > wrote:
>> I have an intent that starts the default Android mail client:
>> Very simple stuff, and it fires off the Email client, from an "Import >> from Email" button in my app.
>> My application is also registered with an <intent-filter> to open PDF >> files. >> So, if I use the above Intent to open up the Email client, find an email >> with a PDF attachment, download it, launch it, select my application from >> the chooser... then everything loads great.
>> Now if I hit my "Import from Email" button again, the intent runs, but >> the Email client is never brought into the foreground.
>> Am I missing something when using startActivity() to (re)launch the >> correct app? >> I have tried checking if the intent is OK by following this >> http://developer.android.com/training/basics/intents/sending.html#Ver... it always returns true (and that makes sense, as it can find the >> Application, but it's just not bringing it to the foreground).
>> I have also tried using startActivityForResult(), but as explained in the >> Android docs, this fires off a "cancel" immediately, because the Activity >> is not Explicit, but Implicit (thought I'd try it, just in case).
>> I feel like I'm missing something, a step, a call to something... or have >> I hit upon some strange loop that works in one case, but cannot keep >> looping? Any help/pointers would be greatly appreciated!
> Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them.