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.
Related
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
I started to create an android application. At first, I planned it will be 5 pages and I wrote Xml and java codes for the first page and the others. Now I realized I made a mistake. The first page can not be a first page. Means; there should be a new page before the first page. I wrote codes for that new page but I can't see it when I run the project. What should I do? Thanks already.
You have to add the activity to the AndroidManifest.xml
There you can specify which Activity should be the Launch-Activity by setting the intent-filter like:
<activity android:name="LaunchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Be sure only your Launchy Activity has that intent signature though.
No offense, but that's pretty basic knowledge, maybe you should read a few tutorials before jumping into development?
I'm running into a problem starting other activities from mine. I know this must be being done elsewhere as there are so many launcher apps out there which much use package manager to start specific activities...
I can get an Acitivity name I would like to start from the package manager, but how can I somehow parse this and turn it into an intent? Baring in mind I can't access the class... Also I would like to start that specific activity and not launch the MAIN intent from the package...
I'm sure someone must be doing this somewhere... It's kind of the point in activities isn't it?
Assuming you have following in your AndroidManifest.xml
<!-- The askUser dialog activity -->
<activity android:theme="#android:style/Theme.Dialog"
android:name="my.app.AskUserActivity"
android:excludeFromRecents="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="my.app.intents.AskUserConfirmConnect"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Then you can call this Activity by name, like this:
Intent dlgIntent = null;
dlgIntent = new Intent("my.app.intents.AskUserConfirmConnect");
dlgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
dlgIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(dlgIntent);
You can use setClassName(String, String) on the Intent to avoid needing the other class.
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.
I defined an application which is only used from my other application. So I would like to hide the icon of this application, so that the user can't see it on the desktop of his phone (or how do you call the thing where all apps are listed?). My manifest file looks the following way:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.games.pacman.controller"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".PacmanGame"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="pacman.intent.action.Launch" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="xyz.games.pacman.network.MessageListener">
<intent-filter>
<action android:name="xyz.games.pacman.controller.BROADCAST" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
I already read this question:
How to hide an application icon in Android emulator?
but if i just remove the line
<category android:name="android.intent.category.DEFAULT" />
in my manifest, the activity isn't working at all (ActivityNotFoundException in the calling activity).
Any hints how to solve this problem? I already tried android.intent.category.EMBEDDED but this doesn't work too.
In the Internet I found CommonsWare answer http://osdir.com/ml/Android-Developers/2010-06/msg03617.html that it can be done using PackageManager. Unfortunately, it isn't explained how exactly and I couldn't find a solution by browsing the PackageManager API.
You need to create a custom intent filter and then create an intent which uses that filter.
For example, in my Funky Expenses application external apps can add transactions. This is achieved by the manifest for Funky Expenses containing
<activity android:name="com.funkyandroid.banking.android.ExternalEntryActivity">
<intent-filter>
<action android:name="com.funkyandroid.action.NEW_TRANSACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
and then external application can access my activity in the following way;
Intent launchIntent = new Intent();
launchIntent.setAction("com.funkyandroid.action.NEW_TRANSACTION");
... code to set parameters to be passed to activity ...
startActivity(launchIntent);
Pay special attention to the setAction call which sets the correct intent.
why would you write an actual (executable) second application that merely exists to do something when it receives sth from another app?
i'd suggest, you implement this "app" as a service (remote or local). this service would then run in the background and do stuff for you and there won't be any icons to be displayed on the screen for it...
if neccessary, you can implement this service to be remote, meaning it runs in a totally different process then the first app. and: you actually can communicate via broadcast intents as you seem to do by now so you won't need to change your first app...
Try removing the intent-filter and instead of trying to launch the 2nd activity with the filter lounch directly the activity:
Intent second = new Intent(context, xyz.games.pacman.controller.PacmanGame.class);
startActivity(second);
You must remove the whole <intent-filter>, not just the <category>