Android Notepad application's NoteList activity intent resolution - android

Could someone please explain, when will the NoteList activity be spawned with intent actions ACTION_VIEW, ACTION_EDIT, ACTION_GET_CONTENT.
I tried commenting out the code for the particular intents below from NoteList activity, and the application worked just fine
<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>
Also inside NoteList activity, i did not find any handling for the below intent actions. So why even define them??
Say some startActivityFoorResult() calls this intent, how will this intent even be resolved inside NoteList when it does not have any handler inside NoteList activity.
Also who can and calls in the example the intent actions?
Links for android NotePad example is below.
http://developer.android.com/guide/topics/intents/intents-filters.html
http://developer.android.com/resources/samples/NotePad/index.html
Thanks in advance

If you notice the last line inside the intent filter, you'll see that it specifies a mime type. This associates the app with that mime type. That means that when you open a file/url with that mime type, it will try to open it with this app. The fact that you removed the intent filter doesn't necessarily mean that the app will stop working, it will simply no longer handle this mime type.
Inside NotesList.java you will see several references to Intent.ACTION_EDIT, Intent.ACTION_PICK, etc. which are constants for "android.intent.action.EDIT" etc.
Update:
If you look at the manifest file you'll see that the min SDK version is set to 11. This is apparently a HoneyComb manifest file. I glanced at the code and it doesn't seem like the code linked directly on the website uses fragments, but I strongly suspect that the manifest was for a version that uses fragments. I know for sure there's a version out there with fragments as I've played with it at some point. Google used it for their recent Android Developer Labs. This would match up with the intent filter that you saw, as it would allow for editing/viewing/picking a note from the list which would open up the fragment to view/edit/etc. In short, I think the code and manifest are probably a little out of sync.

Related

How to make app appear as an option application?

What needs to be done to make your app appear as an option app.
For eg, when I select an image file, android shows me a list of applications to open the file with, like Gallery,Photos etc.
I want that android also shows my app in this list.
How to achieve this? I am unable to understand which android classes to use for it? Or do I need to modify manifest file to add some specific intents?
By defining intent filter you can achieve this. You can register your Android components via intent filters for certain events.If a component does not define one, it can only be called by explicit intents. The key for this registration is that your component registers for the correct action, mime-type and specifies the correct meta-data.
Eg.
<activity android:name=".BrowserActivitiy"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
</intent-filter>
</activity>
Above code will register an Activity for the Intent which is triggered when someone wants to open a webpage.
Source: http://www.vogella.com/tutorials/AndroidIntent/article.html

Why does one package declare another's activity in its own manifest?

As indicated by the tags, this is homework/classwork. (Note that it's really just an in class thing that my instructor can't seem to explain, so I'm turning to the interwebs).
We have an example made up of two apps: Sample1 and Sample2. The point of the example is to show calling into Sample2 from Sample1 using an intent. Sample 2 uses an intent filter to be launched by a certain intent. Here is a snipped from the manifest.
<activity
android:name=".Sample2"
android:label="#string/title_activity_Sample02" >
<intent-filter>
<action android:name="Sample02.intent.action.Thinger" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Sample01 invokes this using an intent:
Intent intent = new Intent("Sample02.intent.action.Thinger");
startActivity(intent);
This works fine, assuming that Sample02 is installed on the target device.
What confuses me is this bit in Sample01's manifest file:
<activity
android:name="com.example.Sample02.Sample02"
>
</activity>
I don't understand what this is for. It exists in addition to the declaration for Sample01 in the same file. Near as I can tell, I can remove it and everything works the same. Anyone know what this about? Thanks.
This is acknowledgment of simple02 app in simple01 app manifest. it is showing that we want to use simple02 method and function in simple01 app.

Implicit intent within same application

How do I build an intent and the Manifest so that I can invoke an activity with my application as an implicit intent.
The idea is that I am writing some general code that I wish to use in a number of applications.
This code is held in an Android library and is linked to the using application.
This general code opens an activity and does some work.
Once it is done (user clicks a button) it needs to transfer to an activity that is specific to this application.
As per my understanding on your questions,
You can declare your activity with specified implicit intent in your application's manifest file..
For example: If you want to make a application for view Image with your application and you have to use that application on your device which can allow other activity to view image using implicit intent action.VIEW so ,just
<activity android:label="#string/app_name" android:name=".MyImageViewerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.LAUNCHER">
</category></action></intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW">
<category android:name="android.intent.category.DEFAULT">
<data android:mimetype="image/*">
</data></category></action></intent-filter>
</activity>
In the above code we can see that intent-filter has following properties.
a. action: type for which this activity will respond for.Like this activity will respond for view action.
b. category: implicit intents are divided in categories.Like this activity is in default category.
c. data: Specify more information about intent-filter. Like this activity will handle file of mimeType “image/*”.
And when you install this application in your device and click on any image file, you will see a choice dialog that offer you to select between default application and your application. Just select your application to see the image.
For more info with example look at this What is intent filter in android?
Tutorial: Registering via Intentfilter
I think you can use intent-filters. I didn't use it for such things, but I hope that will help you.
Idea is that you can call your activity not by name, but by it's action (that is setted in intent-filter in your Manifest)

Can you define an Android intent-filter using a string resource?

I wanted to define the string name of my intent in the strings.xml file, and then bind that string to an intent filter, as so:
<intent-filter >
<action android:name="#string/app_intent" >
</action>
<category android:name="android.intent.category.DEFAULT" >
</category>
</intent-filter>
When i tried this however, i get various errors about the system could find no activity to handle my intent. I was trying to keep values (ie, the intent names) centralized instead of hard-coded in the manifest as well as in code. As it is, at least this lets me centralize it out of the application code, but i still have it hard-coded in the manifest.
Is this really impossible to do or is there some way to make it work?
Its not the issue with intent-filter, the issue is with android:name. android:name attribute is not taking string resource for activity name also. example <activity android:name="#string/app" android:label="#string/app_name"> is not valid in android.
Not directly answering the OP's question, but what drove me to this question was that I wanted to be able to define different actions in different situations (including defining an action triggering a component in android library in the application using this library). I eventually found about manifest placeholders, which were actually what I needed. Hopefully, this will be useful for someone else too.
PS: Yes, defining a placeholder in the app still allows you to use it in a library, because of the manifest merging happening at build time.

How can I create a "Launcher" Activity programmatically?

Instead of declaring a pre-determined launcher activity in my manifest using an intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Could I, instead, be given programmatic control over the activity which gets run when the application launches?
I'm not able to find anywhere in the documentation which says I must use the intent filter approach... but I also don't see any discussion of the alternative(s).
http://developer.android.com/guide/topics/fundamentals/activities.html
http://developer.android.com/guide/topics/intents/intents-filters.html
Thanks.
As far as I know, it's not possible. Android creates or sets up the hard link of the App icons to their respective activities by looking at the manifest. If you don't set it, you will not find any icons/shortcuts for your app after you install it.

Categories

Resources