[android-developers] Re: Straight-forward BroadcastReceiver to open/read file

2009-04-17 Thread Mark Murphy

 I am not faulting the few knowledgable folks who volunteer their time
 on these forums.  I think it's great.  I'm just reiterating basically
 what you said above, that the question to answer ratio is low
 (regardless of the reason, which is a very good reason).  Just makes
 things stressful.

If you don't get answers here, try other forums first. *Then* get stressed
if you still don't get answers.

 :-)  It's not just the one post.  It's the overall pattern of
 genuinely trying to figure something one responsibly on my own,
 reading a lot of different sources for a long time, eventually giving
 up and actually asking for help, and then getting what was in effect a
 brush-off answer that really didn't help me.

I can certainly understand the frustration at that specific reply.

 Where do you teach your class?

Wherever anyone wants one! ;-)

I sometimes hold public classes through Big Nerd Ranch, though none are
scheduled at present. Much of my training is on-site for specific firms
looking to bring a team up to speed on Android development quickly. Making
some screencasts of my training is on my list of things to do -- that list
is really really long, though. :-(

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-17 Thread Keith Wiley

Just to wrap up this thread for posterity so anyone in the future  who
trips across it in a search will actually find something final and
applicable, here's how I got it working (Mark's reply wasn't quite the
ticket apparently).

First, Mark pointed out that the desired behavior is in fact
demonstrated in the NotePad example, a sibling of the API Demos
example.  Thank you Mark!  However, at least with respect to Linda
File Manager, the solution doesn't have anything to do with
android.intent.category.ALTERNATIVE or
android.intent.category.SELECTED_ALTERNATIVE, and as described below,
I'm unsure of the relevance of the mime type entry.

The relevant code from NotePad's manifest is the following activity
entry:

activity android:name=NotesList android:label=@string/
title_notes_list
intent-filter
action android:name=android.intent.action.MAIN /
category
android:name=android.intent.category.LAUNCHER /
/intent-filter
intent-filter
action android:name=android.intent.action.VIEW /
action android:name=android.intent.action.EDIT /
action android:name=android.intent.action.PICK /
category
android:name=android.intent.category.DEFAULT /
data android:mimeType=vnd.android.cursor.dir/
vnd.google.note /
/intent-filter
intent-filter
action
android:name=android.intent.action.GET_CONTENT /
category
android:name=android.intent.category.DEFAULT /
data android:mimeType=vnd.android.cursor.item/
vnd.google.note /
/intent-filter
/activity

In particular, the second intent-filter is the golden ticket, i.e.,
when a user taps a file in Linda File Manager and gets a list of apps,
is that second intent-filter which makes NotePad appear in the list of
options.  Note, however, that I believe some of the other intent-
filters in NotePad's manifest add other activities of NotePad to that
same list as well, including perhaps the third intent-filter above,
I'm not sure yet.  Incidentally, I discovered that w.r.t. Linda File
Manager, the exact action which is being triggered is VIEW (note that
it isn't ACTION_VIEW, it's VIEW, which makes sense given that it is
prefixed with android.intent.action.).  Also, as far as I can tell,
the right way to access the actual file once your app has been fired
up in onCreate() is to access the activity's intent's data string as a
file URI, thus:

public void onCreate(Bundle savedInstanceState) {
String uriStr = getIntent().getDataString();
}

Now you can parse the URI, get a path, and presumably open a file.
Maybe it isn't the right way to do it, but it's certainly *A* way to
do it.

Also, the value of mimeType, although presumably important as a
filter, doesn't play any role in this process as far as I can tell.
For example, NotePad uses vnd.android.cursor.dir/vnd.google.note.  I
tried vnd.android.cursor.dir/vnd.myapp, text/plain, and even a/b
just for kicks.  It worked exactly the same way for all four mime
types in Linda File Manager (even text/plain worked on apk and mp3
files, which I hoped it would filter out).  It is crucial to
actually *have* a mimetype entry in the intent-filter.  If it is
removed, your app no longer appears as a launch option.  It just
doesn't make any difference what the mime type actually is.  Such is
the observed behavior based on my experiments.

The important thing is to have an intent filter with the VIEW action
and any mimeType (use something sensible though).  That's it as far as
I can tell.  That might be specific to Linda File Manager or it might
be generally applicable, I simply don't know yet, and trying to figure
t out by trial and error is not a very good way to nail down the
details, but I just can't figure out where this is documented.

Anyway, there it is, now anyone else can do it too, assuming they find
this thread.  Go tell you friends.

--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-17 Thread Mark Murphy

 Just to wrap up this thread for posterity so anyone in the future  who
 trips across it in a search will actually find something final and
 applicable, here's how I got it working (Mark's reply wasn't quite the
 ticket apparently).

There are a few ways of achieving this sort of integration. I took a
guess, since I've never heard of Linda File Manager, let alone used it.

 The relevant code from NotePad's manifest is the following activity
 entry:

 activity android:name=NotesList android:label=@string/
 title_notes_list
 intent-filter
 action android:name=android.intent.action.MAIN /
 category
 android:name=android.intent.category.LAUNCHER /
 /intent-filter
 intent-filter
 action android:name=android.intent.action.VIEW /
 action android:name=android.intent.action.EDIT /
 action android:name=android.intent.action.PICK /
 category
 android:name=android.intent.category.DEFAULT /
 data android:mimeType=vnd.android.cursor.dir/
 vnd.google.note /
 /intent-filter
 intent-filter
 action
 android:name=android.intent.action.GET_CONTENT /
 category
 android:name=android.intent.category.DEFAULT /
 data android:mimeType=vnd.android.cursor.item/
 vnd.google.note /
 /intent-filter
 /activity

 In particular, the second intent-filter is the golden ticket, i.e.,
 when a user taps a file in Linda File Manager and gets a list of apps,
 is that second intent-filter which makes NotePad appear in the list of
 options.

I fail to see the value in having, say, Notepad show up if the tapped-upon
file is, say, an MP3 file. But, again, I have not used Linda File Manager
and so may be misunderstanding it.

Regardless, they may be using queryIntentActivityOptions() on
PackageManager to find applications, which does not rely upon the
ALTERNATIVE or SELECTED_ALTERNATIVE categories. My apologies for being
incorrect in my original guess.

 Incidentally, I discovered that w.r.t. Linda File
 Manager, the exact action which is being triggered is VIEW (note that
 it isn't ACTION_VIEW, it's VIEW, which makes sense given that it is
 prefixed with android.intent.action.).

ACTION_VIEW is the constant declared by the Intent class in Java. ACTION_
gets converted to android.intent.action. when declaring the action in an
intent-filter clause.

 Also, as far as I can tell,
 the right way to access the actual file once your app has been fired
 up in onCreate() is to access the activity's intent's data string as a
 file URI, thus:

   public void onCreate(Bundle savedInstanceState) {
   String uriStr = getIntent().getDataString();
   }

 Now you can parse the URI, get a path, and presumably open a file.
 Maybe it isn't the right way to do it, but it's certainly *A* way to
 do it.

No, that should be pretty much correct.

 Also, the value of mimeType, although presumably important as a
 filter, doesn't play any role in this process as far as I can tell.

I would consider that a flaw in Linda File Manager, but, again, I have not
used it.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-16 Thread Dianne Hackborn
You need to publish and implement an activity, not a receiver.

On Thu, Apr 16, 2009 at 1:26 PM, Keith Wiley kbwi...@gmail.com wrote:


 I would like my app to pop up in the list of options for opening
 certain file types in the various file manager, email, and web browser
 apps.  I'm having trouble figuring out how to begin.  I haven't found
 any examples of this sort of thing yet.

 Don't I need to know what kind of action the other app is trying to
 invoke on a selected file?  How can I possibly know that?  Or should I
 simply assume that all file manager, email, and browser apps will
 always use ACTION_VIEW or perhaps ACTION_EDIT when trying to send a
 file to another app?  Must I simply assume this and hope I'm right?
 There are so many possible apps to try to get this to work with, how
 do I make it receive a open-file command from any arbitrary app?

 Is the code below correct so far?  I have the following in the
 manifest:

receiver
android:enabled=true
android:exported=true
android:label=Some Label, where does this show up?
android:name=.MyBroadcastReceiver 
intent-filter
action
 android:name=android.intent.action.ACTION_EDIT /
/intent-filter
intent-filter
action
 android:name=android.intent.action.ACTION_VIEW /
/intent-filter
/receiver

 I don't see how to specify a file-type or file extension filter in the
 receiver.  How do I do this?  Likewise I have the following in the
 receiver:

 public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if
 (intent.getAction().equals(android.intent.action.ACTION_EDIT)
||
 intent.getAction().equals(android.intent.action.ACTION_VIEW))
 {
Uri uri = intent.getData();
String uriStr = intent.getDataString();
}
}
 }

 Is that how I'm supposed to do it?  Do I assume the that file manager,
 email. or browser app will send the file to my app by sending a file
 URI or URL (I'm unclear on the distinction) in the data field of the
 intent?  To be honest, I'm not sure if I'm even close to the mark on
 this?  Is this code wildly off-base?

 Any assistance is greatly appreciated.  I'm not sure where to find out
 how to do this.

 Thank you very much.

 Cheers!
 



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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.

--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-16 Thread Keith Wiley

My app is already written, I already have an activity that opens and
processes files, but it's all internal to the app.  The app presents a
file chooser from a single hard-coded directory on the sd card.  That
works okay from inside the app (assuming users know to transfer files
to that directory before launching my app), but I want other apps to
be able to invoke my app externally, like when you long-press a file
in Linda File Manager.

My plan is to run my main activity from the broadcast receiver (from
the URI somehow, although I haven't worked out the details yet), but I
just don't know if I'm anywhere near that point yet.  For example,
with the code I showed above, my app doesn't appear in the popup menu
of app options when a file is long-pressed in Linda File Manager.
Lots of other apps appear, but not mine.
--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-16 Thread Keith Wiley

Doesn't anyone know how to do this?  I've seen other apps do it.  For
example, Linda File Manager shows plenty of other apps as options for
opening files, but I can't get it to show mine.  If I'm missing some
obvious source of documentation then I apologize, but perusing the
javadocs doesn't convey the necessary information for a question of
this abstraction (that approach is better for learning what a specific
class wants or what an interface provides, but it doesn't *teach*
whole ideas, it doesn't work that way) nor do any of the documents in
the developer guide specifically address this issue (many documents
touch on this issue but the actual syntax and how the necessary pieces
of the manifest coordinate with the associated java classes is not
exemplified), and none of the API Demos address this topic either (it
really *can't* since API Demos is a single conglomerated app, which
pretty much precludes it from this particular question which is about
app-to-app communication).

I'm very frustrated right now.  From the single unbelievably curt
reply I received, I get the impression that everyone thinks this is a
stupid question.  What additional source of documentation or
educational material is everyone else using that I have completely
missed (is there an entire additional website everyone else is aware
of which I haven't found yet?).  Is this task so incredibly easy that
even asking the question, much less asking that it be answered, is
considered inappropriate use of the forum?  Is that why the question
is being ignored?

Besides the javadoccs, the articles in the dev guide, and the API
Demos code, what other resource is there?  Not that they aren't great
resources of information with their domains, but some topics are of a
style that they simply are not answered by those three sources.

I would greatly appreciate any pointers on this task.  I simply do not
know what else to read at this point.  I've read everything I can
find.  It's time to ask a question and have someone answer it.

Thank you.

--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-16 Thread Mark Murphy

 Doesn't anyone know how to do this?

If by this, you mean:

I would like my app to pop up in the list of options for opening
certain file types in the various file manager, email, and web browser
apps.

Then you need to implement one or more activities, with intent filters
that contain:

-- the actions you support on the content (e.g., ACTION_VIEW, ACTION_EDIT)
-- the MIME type you support
-- the android.intent.category.ALTERNATIVE and/or the
android.intent.category.SELECTED_ALTERNATIVE as appropriate

That should enable the other applications to find you by introspection
(e.g., addIntentOptions() for menus). This assumes, of course, that the
applications in question use this facility versus something else.

 and none of the API Demos address this topic either

http://developer.android.com/guide/samples/NotePad/AndroidManifest.html

 From the single unbelievably curt
 reply I received, I get the impression that everyone thinks this is a
 stupid question.

How does one curt reply indicate that everyone thinks this is a stupid
question?

IMHO, it's more a case that very few developers are doing what you want to
do. Heck, I had to hunt and hunt and hunt a week or two ago just to find
*anything* that supported this feature.

 Is this task so incredibly easy that
 even asking the question, much less asking that it be answered, is
 considered inappropriate use of the forum?  Is that why the question
 is being ignored?

There is a lot of traffic on these lists. There are only so many people
who answer questions. There are even fewer people in position to answer
questions on dusty corners of the API such as this one. Personally, I am
teaching an Android class this week, and so am not keeping up on many
threads.

Do not assume that any given post is guaranteed to get answers,
particularly in the six-and-a-half hours (Apr 16, 4:26 pm to Apr 16, 10:55
pm) between when you asked your question your last followup.

In other words, chill out, dude.

 Besides the javadoccs, the articles in the dev guide, and the API
 Demos code, what other resource is there?

A zillion blog posts, anddev.org, JavaRanch's Android board,
AndroidSnippets.org, a half-dozen books, some knols, ...

 It's time to ask a question and have someone answer it.

You only waited 6.5 hours for an answer. If you want guaranteed feedback
in that short of a timeframe, hire a consultant.

Otherwise, give any query 24-48 hours, then if needed repost with a
*bump*. Or, try posting in other forums (e.g., anddev.org, JavaRanch),
etc.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~-~--~~~---~--~~
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: Straight-forward BroadcastReceiver to open/read file

2009-04-16 Thread Keith Wiley

On Apr 16, 8:21 pm, Mark Murphy mmur...@commonsware.com wrote:

 -- the actions you support on the content (e.g., ACTION_VIEW, ACTION_EDIT)
 -- the MIME type you support
 -- the android.intent.category.ALTERNATIVE and/or the
 android.intent.category.SELECTED_ALTERNATIVE as appropriate

 That should enable the other applications to find you by introspection
 (e.g., addIntentOptions() for menus). This assumes, of course, that the
 applications in question use this facility versus something else.

Great.  I'll look into that.  Thank you.


  and none of the API Demos address this topic either

 http://developer.android.com/guide/samples/NotePad/AndroidManifest.html

I appreciate the pointer.  Thanks again.

 There is a lot of traffic on these lists. There are only so many people
 who answer questions. There are even fewer people in position to answer
 questions on dusty corners of the API such as this one. Personally, I am
 teaching an Android class this week, and so am not keeping up on many
 threads.

I am not faulting the few knowledgable folks who volunteer their time
on these forums.  I think it's great.  I'm just reiterating basically
what you said above, that the question to answer ratio is low
(regardless of the reason, which is a very good reason).  Just makes
things stressful.

 Do not assume that any given post is guaranteed to get answers,
 particularly in the six-and-a-half hours (Apr 16, 4:26 pm to Apr 16, 10:55
 pm) between when you asked your question your last followup.

 In other words, chill out, dude.

:-)  It's not just the one post.  It's the overall pattern of
genuinely trying to figure something one responsibly on my own,
reading a lot of different sources for a long time, eventually giving
up and actually asking for help, and then getting what was in effect a
brush-off answer that really didn't help me.  Maybe she was busy, I
don't know, but there's no denying it didn't help me, and after I had
already put in the time on the other source.  You have to consider the
fruitless searching that preceded eventually asking for help...but in
addition, I take your point.  Noted.

At any rate, thank you very much for the response.

Where do you teach your class?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---