我的广播接收器是显式的还是隐式的?
Is my broadcast receiver explicit or implicit?
在阅读了一些关于此的手册 (,2) 之后,我仍然需要帮助。我将我的应用程序定位到 android O,在 android 7.0 上它工作正常但在 8.1 上我似乎没有收到任何广播。那么,如果在清单中以 android O 和 7.0 中的 运行 为目标并使用隐式广播,它是否仍然有效?
你能帮我确定我的广播是显式的还是隐式的?
我正在使用 Awareness API...
清单:
<receiver android:name=".DetectionBroadcastReceiver" >
<intent-filter>
<action android:name="childincar.com.michlindevelopment.DETECTIONFENCE" />
</intent-filter>
</receiver>
检测广播接收器
public class DetectionBroadcastReceiver extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("DTAG", "onReceive");
this.context = context;
if (!TextUtils.equals(Constans.FENCE_RECEIVER_ACTION, intent.getAction())) {
return;
}
//Some Code
}
}
康斯坦斯
public class Constans {
public static final String FENCE_RECEIVER_ACTION = BuildConfig.APPLICATION_ID + ".DETECTIONFENCE";
}
正在注册
public static void registerFences(final Context context) {
Intent intent = new Intent(Constans.FENCE_RECEIVER_ACTION);
PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
Awareness.getFenceClient(context).updateFences(new FenceUpdateRequest.Builder()
.addFence(Constans.DETECTION_FENCE_DRIVING, DetectedActivityFence.starting(DetectedActivity.IN_VEHICLE), mPendingIntent)
.addFence(Constans.DETECTION_FENCE_WALKING, DetectedActivityFence.starting(DetectedActivity.WALKING), mPendingIntent)
.build())
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
任何不是 'specific' 到您的应用程序的广播都是隐式的。例如,'ACTION_MY_PACKAGE_REPLACED' 的广播接收器特定于您的应用程序,应该是显式的,而 'ACTION_PACKAGE_REPLACED' 是隐式的,因为它会通知您所有包。
您的广播接收器似乎是隐含的,因为它不仅仅是 about/designed-for 'your' 应用程序。
在阅读了一些关于此的手册 (
清单:
<receiver android:name=".DetectionBroadcastReceiver" >
<intent-filter>
<action android:name="childincar.com.michlindevelopment.DETECTIONFENCE" />
</intent-filter>
</receiver>
检测广播接收器
public class DetectionBroadcastReceiver extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
Log.d("DTAG", "onReceive");
this.context = context;
if (!TextUtils.equals(Constans.FENCE_RECEIVER_ACTION, intent.getAction())) {
return;
}
//Some Code
}
}
康斯坦斯
public class Constans {
public static final String FENCE_RECEIVER_ACTION = BuildConfig.APPLICATION_ID + ".DETECTIONFENCE";
}
正在注册
public static void registerFences(final Context context) {
Intent intent = new Intent(Constans.FENCE_RECEIVER_ACTION);
PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
Awareness.getFenceClient(context).updateFences(new FenceUpdateRequest.Builder()
.addFence(Constans.DETECTION_FENCE_DRIVING, DetectedActivityFence.starting(DetectedActivity.IN_VEHICLE), mPendingIntent)
.addFence(Constans.DETECTION_FENCE_WALKING, DetectedActivityFence.starting(DetectedActivity.WALKING), mPendingIntent)
.build())
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
任何不是 'specific' 到您的应用程序的广播都是隐式的。例如,'ACTION_MY_PACKAGE_REPLACED' 的广播接收器特定于您的应用程序,应该是显式的,而 'ACTION_PACKAGE_REPLACED' 是隐式的,因为它会通知您所有包。
您的广播接收器似乎是隐含的,因为它不仅仅是 about/designed-for 'your' 应用程序。