I have a Receiver like so in my Manifest:
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I saw here on StackOPancakes one like so:
<receiver android:name=".BootupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
What is the purpose/advantage of the "HOME" category assignment?
Actually, from the documentation we can read that categories like "android.intent.category.HOME" and "android.intent.category.LAUNCHER" are used to group activities into some sets. For instance, "android.intent.category.LAUNCHER" is used by Launcher application to select applications that can be launch. Similarly, for an intent-filter for an activity with category "android.intent.category.HOME" is used to find a home screen.
But with BroadcastReceivers I think this category is used as additional category test.
Related
I know I can set <action android:name...> in AndroidManifest.xml.
I think that <action android:name...> can only assigned one time.
But from the following project, I find <action android:name="android.intent.action.VIEW"/> is added into AndroidManifest.xml when there is a <action android:name="android.intent.action.MAIN"/>, why?
https://github.com/sanogueralorenzo/Android-Kotlin-Clean-Architecture
https://github.com/igorwojda/android-showcase
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sanogueralorenzo.namingishard">
<application
android:name=".App"
...
android:theme="#style/AppTheme">
<activity
android:name=".SplashActivity"
android:theme="#style/AppTheme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
But from the following project, I find is added into AndroidManifest.xml when there is a , why?
From the documentation that explains this.
You can create a filter that includes more than one instance of <action>, <data>, or <category>. If you do, you need to be certain that the component can handle any and all combinations of those filter elements.
In other words, this is a shortcut to indicate that the app handles an intent that either has the MAIN action or the VIEW action, with the LAUNCHER category.
In other other words, this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Is equivalent to this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
The documentation also provides an example.
To enable Google to crawl your app content and allow users to enter
your app from search results, you must add intent filters for the
relevant activities in your app manifest. These intent filters allow
deep linking to the content in any of your activities. For example,
the user might click on a deep link to view a page within a shopping
app that describes a product offering that the user is searching for.
this is the first reason and the second one is
ACTION_VIEW
Use this action in an intent with startActivity() when you have some information that an activity can show to the user, such as a
photo to view in a gallery app, or an address to view in a map app.
while
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent data.
so activity can have both
Doc says https://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN is an entry point.
Example code:
<activity android:name="org.A.A"
android:theme="#style/NoTitle"
android:screenOrientation="behind"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name="org.A.C"
android:theme="#style/NoTitle"
android:launchMode="singleTop"
android:screenOrientation="behind">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name="org.A.B"
android:theme="#style/NoTitle"
android:launchMode="singleTop"
android:screenOrientation="behind">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
1) So using android.intent.action.ACTION_MAIN acts as an entry point to the parent component (parent component I mean the activity or receiver or service)?
2) If yes, Entry point from where, as there is no CATEGORY mentioned.
Android apps are composed of different components. e.g. Activity, Service, BroadcastReceiver, and ContentProvider and each component can act as an entry point of the app.
Let's take activity as an example, you have defined an activity in your application with following action
<intent-filter>
<action android:name="com.yourapp.SOME_ACTION" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
and I start an activity in my app with following intent.
Intent intent = new Intent("com.yourapp.SOME_ACTION"); // same action
startActivity(intent);
Now what will happen? System will search for activities with com.yourapp.SOME_ACTION action and if it finds one (in current scenario, it will be activity you have created with com.yourapp.SOME_ACTION in your app), it will start your app (if it is not already started) and will open the activity in your app.
See, now I can enter into your app by using Activity with com.yourapp.SOME_ACTION. Same thing happens in case of other components.
Activity with MAIN action will be entry point of application.If you have one its well and good if more than one then you can have multiple activities through which you can enter into application.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
But if you have provided CATEGORY for activity it will create launcher for that entry point.
<category android:name="android.intent.category.LAUNCHER" />
Suppose two activities is having both MAIN action and CATEGORY as launcher two app icon will be created one will have one activity as entry point second will have another one as entry point.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
i don't know if this is okay having two broadcast receivers in my android app. I separated them cause the one receiver with the boot_completed, it will do a different task and the other receiver with also do different task when they receive a broadcast.
<receiver android:name=".Autostart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".AlarmManagerBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
That is perfectly valid you should always try to seperate your concerns which part of a good architecture/good design principles.
I found several answers on this issue, but it's not working for me. If you click a phone number in an email or on a website, a default dialer popup comes up to select the dialer/skype etc.
I'm trying to get my app in that list - so I don't want to handle the actual call, but open the activity and show the number the user clicked on.
I've tried this:
<receiver android:name=".MyOutgoingCallHandler">
<intent-filter>
<action android:name="android.intent.action.ACTION_DIAL" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
But it's not showing in the list. What intent should I filter for?
If you want to add an Activity to the list of Activitys that will be shown to the user as possible phone dialers, you need to have an Activity and the <activity> definition must contain this intent-filter> in the manifest:
<activity ...>
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
What you've got is a BroadcastReceiver that will receive the outgoing call Intent. That's something different.
The official Android Developers blog has covered this process. You can read all about it there.
Your intent filter looks like it has the correct action, so it may be that you have not requested the correct Android permission.
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
Here is how the Android Developers blog suggest you declare the broadcast receiver.
<manifest>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<application>
...
<receiver android:name=MyOutgoingCallHandler">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
...
</application>
</manifest>
I am trying to solve a start on boot related problem and I noticed many examples of the AndroidManifest.xml which has android.intent.action.BOOT_COMPLETED and some that also have the category of android.intent.category.HOME in there. Does anyone know what the difference (if any) between the two are?
ie.
<receiver android:name=".MartiniBootBroadCastReciever"
android:enabled="true" android:exported="false"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
versus
<receiver android:name=".MartiniBootBroadCastReciever"
android:enabled="true" android:exported="false"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
AFAIK, your first one is wrong. The BOOT_COMPLETED broadcast should not have that category, AFAIK.