如果接收器和过滤器未在清单中设置,为什么广播接收器不会接收意图?

发布于 2024-12-21 04:29:15 字数 1492 浏览 1 评论 0原文

如果接收器和过滤器未在清单中设置,为什么广播接收器不会收到意图?

工作 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文