问题
Every One
Can i Get BroadcastReceiver for This Intent when i press home Key :
Starting activity: Intent { act=android.intent.action.MAIN cat= [android.intent.category.HOME] flg=0x10200000 cmp=com.htc.launcher/.Launcher }
I don't want to Consider com.htc.luncher as it will we different for Other Android Device .
Here i my Simple Class For BroadcastReceiver :
public class HomeBrodcast extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
}
}
In Manifest :
<receiver android:name="xxx.yyy.zzz.sss.HomeBrodcast">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<categary android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
For Register BroadcastReceiver in My Activity :
mHomeBrodcast=new HomeBrodcast();
IntentFilter mHomeFilter=new IntentFilter("android.intent.action.MAIN");
mHomeFilter.addCategory("android.intent.category.HOME");
registerReceiver(mHomeBrodcast, mHomeFilter);
Now Problem is When After Start My Application i press Home Button Press and My Log Show Me this Intent :
12-27 14:01:11.230: I/ActivityManager(123): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.htc.launcher/.Launcher }
So My Goal is to get Receiver for This Intent But When i Debug i am not Getting Any Thing Some Thing Must me Wrong .What should be Problem in Getting This Intent BroadCast .
回答1:
spelling category right in the manifest should help :)
回答2:
I do not think you can get that functionality, see https://groups.google.com/forum/#!topic/android-developers/fNTysSA8mWQ
回答3:
Android internally calls startActivity
for starting the ACTION_MAIN registered component to start the launcher. Since you are registered with the receiver, It wont be get called unless it calls with sendBroadast
. Hope it helps
来源:https://stackoverflow.com/questions/8642964/how-to-get-broadcastreceiver-for-action-android-intent-action-main-and-android