如果接收器和过滤器未在清单中设置,为什么广播接收器不会接收意图?
如果接收器和过滤器未在清单中设置,为什么广播接收器不会收到意图?
工作 1:
locationNotific = new Intent(PROXIMITY_STRING);
lPendingIntent = PendingIntent.getBroadcast(this, 0, locationNotific, PendingIntent.FLAG_CANCEL_CURRENT);
filter = new IntentFilter(PROXIMITY_STRING);
contextOnCreate.registerReceiver(new ProximityIntentReceiver(), filter);
lm.addProximityAlert(LatitudeE6ForPeox1,LongitudeE6ForPeox1,POINT_RADIUS,-1,lPendingIntent);
在清单 1 中:
<receiver android:name=".ProximityIntentReceiver">
<intent-filter>
<action android:name="SendProximityIntent">
</action>
</intent-filter>
</receiver>
工作 2:
filter = new IntentFilter(PROXIMITY_STRING);
contextOnCreate.registerReceiver(new ProximityIntentReceiver(), filter);
sendBroadcast(locationNotific);//working becouse of that (dosent work just with proximity)
Dosent 工作:
identif=Long.toString(id);
locationNotific = new Intent(PROXIMITY_STRING + identif);
lPendingIntent = PendingIntent.getBroadcast(this, 0, locationNotific, PendingIntent.FLAG_CANCEL_CURRENT);
filter = new IntentFilter(PROXIMITY_STRING + identif);
contextOnCreate.registerReceiver(new ProximityIntentReceiver(), filter);
lm.addProximityAlert(LatitudeE6ForPeox1,LongitudeE6ForPeox1,POINT_RADIUS,-1,lPendingIntent);
Why the Broadcastreceiver dosen't receive the intents if the receiver and the filter dosen't set in the manifest?
Working 1:
locationNotific = new Intent(PROXIMITY_STRING);
lPendingIntent = PendingIntent.getBroadcast(this, 0, locationNotific, PendingIntent.FLAG_CANCEL_CURRENT);
filter = new IntentFilter(PROXIMITY_STRING);
contextOnCreate.registerReceiver(new ProximityIntentReceiver(), filter);
lm.addProximityAlert(LatitudeE6ForPeox1,LongitudeE6ForPeox1,POINT_RADIUS,-1,lPendingIntent);
In the manifest 1:
<receiver android:name=".ProximityIntentReceiver">
<intent-filter>
<action android:name="SendProximityIntent">
</action>
</intent-filter>
</receiver>
Working 2:
filter = new IntentFilter(PROXIMITY_STRING);
contextOnCreate.registerReceiver(new ProximityIntentReceiver(), filter);
sendBroadcast(locationNotific);//working becouse of that (dosent work just with proximity)
Dosent Working:
identif=Long.toString(id);
locationNotific = new Intent(PROXIMITY_STRING + identif);
lPendingIntent = PendingIntent.getBroadcast(this, 0, locationNotific, PendingIntent.FLAG_CANCEL_CURRENT);
filter = new IntentFilter(PROXIMITY_STRING + identif);
contextOnCreate.registerReceiver(new ProximityIntentReceiver(), filter);
lm.addProximityAlert(LatitudeE6ForPeox1,LongitudeE6ForPeox1,POINT_RADIUS,-1,lPendingIntent);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论