我有一个客户需要一个自定义启动器来使他的设备像一个信息亭,只是因为他需要设备对有限应用程序的访问权限有限。到目前为止一切都还可以。
他想要的最重要的功能之一是可以增加/减少可以在他的设备中启动的应用程序。我写了GCM接收器,它还没问题。
我的问题是:我想从GCM服务向我的主要活动(家庭活动)发送自定义广播。我认为代码没问题,但主要活动中从未收到广播。有什么想法吗?
我的清单:
<activity
android:name="jv.android.atmlauncher.activity.HomeScreen"
android:excludeFromRecents="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="jv.antroid.atmlauncher.apklistchanged" /> <!-- This is my custom broadcast -->
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我的服务:
@Override
public void onHandleIntent(Intent intent) {
...
Intent intent = new Intent("jv.antroid.atmlauncher.apklistchanged");
sendBroadcast(intent);
}
我的家庭活动:
private BroadcastReceiver listapkReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homescreen);
registerReceiver(listapkReceiver, new IntentFilter("jv.antroid.atmlauncher.apklistchanged"));
listapkReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
... Do something.
}
};
}
@Override
protected void onDestroy() {
unregisterReceiver(listpkReceiver);
super.onDestroy();
}