now i am learning intent filters..I got some some example like view contacts,make call.But all in those examples they used default in android.manifestfile..
< intent-filter >
<action android:name="android.intent.action.MAIN" >
<category android:name="android.intent.category.LAUNCHER" >
< /intent-filter>
this is ok for single .java file application.If i am using implicit intent in my second activity, then how will be the of my second activity manifest file?..just take the examplw of view contact....
Intent contact=new Intent(Intent.ACTION_VIEW,ContactsContract.Contacts.CONTENT_URI);
my class name is ViewContacts.java and package name is com.phone.contact...
The intent filter is specified within the Activity tag and you can specify multiple filters per activity.
<activity android:name=".activities.WaypointMap" android:launchMode="singleTop" android:theme="#style/Theme.NoBackground">
<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.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable" />
</activity>
<activity android:name=".activities.WaypointList" android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="#xml/searchable" />
</activity>
Related
I have created a custom launcher and its perfectly working fine.Now i want to add an activity to it which shall be launched like any other app from launcher.
Here is my Manifest file.
<activity
android:name="com.sample.launcher2.Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:resumeWhilePausing="true"
android:theme="#style/Theme"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
<activity
android:name="com.sample.launcher2.MainActivity"
android:label="#string/application_name"
android:icon="#mipmap/ic_launcher_home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I am not able to launch activity from launcher.How can i achieve it ?
Make following changes hope it will work
<activity
android:name="com.sample.launcher2.Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:resumeWhilePausing="true"
android:theme="#style/Theme"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="com.sample.launcher2.Launcher" />//Here the change
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
<activity
android:name="com.sample.launcher2.MainActivity"
android:label="#string/application_name"
android:icon="#mipmap/ic_launcher_home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</activity>
Changing that activity's launch mode to singleTask may help!
I use the following code to open a new UI:
String name="com.hellocw.exportmsg.mysettings";
Intent intent1 = new Intent(name);
startActivity(intent1);
It works well in Case Two, but failed in Case One. Why? Thanks!
Case One
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainPreferenceActivity"
android:label="Settings">
<intent-filter>
<action android:name="com.hellocw.exportmsg.mysettings" />
<category android:name="android.intent.category.PREFERENCE" />
</intent-filter>
</activity>
Case Two
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainPreferenceActivity"
android:label="Settings">
<intent-filter>
<action android:name="com.hellocw.exportmsg.mysettings" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
That's because you are not adding CATEGORY_PREFERENCE in your Intent, quote from the docs:
The categories, if supplied, must all be listed by the activity as categories it handles. That is, if you include the categories CATEGORY_LAUNCHER and CATEGORY_ALTERNATIVE, then you will only resolve to components with an intent that lists both of those categories. Activities will very often need to support the CATEGORY_DEFAULT so that they can be found by Context.startActivity().
So, in order for your activity to be resolved for CATEGORY_PREFERENCE you have to explicitly list it. For example,
Intent intent = new Intent("com.hellocw.exportmsg.mysettings");
intent.addCategory(Intent.CATEGORY_PREFERENCE);
startActivity(intent);
I'm working on an Android app using Eclipse and just started noticing a weird glitch.
When I deploy the app to my phone for some reason multiple app icons appear in my "Apps" folder area. Each icon brings me to a different class page within my app when tapped. Has anyone else experienced this as well?
Here's a screenshot of the issue when running the app from the emulator on my laptop.
Since the issue is appearing in the emulator I know that it isn't my phone that's causing the error.
Each of the icons you see in that screenshot represents a different activity in my manifest file.
Here's how the activity is set up in my manifest.
<activity android:name=".MainJava">
<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.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AppClass">
<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.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Would you say that this error being caused because of the way that I am setting up the activities? If so, how would you suggest that I edit the activities to fix this problem?
I've never seen this in any of the apps I've built before this one.
Only MainActivity(Launcher Activity) have intent filter with action as Main and category as Launcher,
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
And Remove this Two line For other Activity.
Change from:
<activity android:name=".MainJava">
<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.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AppClass">
<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.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
To:
<activity android:name=".MainJava">
<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.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AppClass">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
There should be only one MAIN and one LAUNCHER
In my app I have the main activity defined in the manifest.xml file like this:
<activity
android:name=".MainActivity"
android:label="#string/guide_activity" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
when I run the project from eclipse connected to a real device or an emulator I receive the following message in the console:
No Launcher activity found
what can be the reason of this ?
Split the intent-filter into two seperate ones. If you mix them like this, android won't determine that one of the two is the launcher filter.
<activity
android:name=".MainActivity"
android:label="#string/guide_activity" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
I would like my main activity to be searchable also but when I change the manifest.xml to
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- declare the default searchable Activity for the whole app -->
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
it cant find the main activity and the application doesn't run.
any idea?
is it not best practice to use the same activity as searchable also?
Thanks,
Alisa
You need to add a new intent-filter with the action.SEARCH
<activity
android:name=".activities.YourActivity">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
You need add new action in manifest file and link to search metadata, smth like that:
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>