我正在开发一个Android应用程序,它具有在应用程序在用户启用或禁用GPS的情况下运行时的功能。我收到广播并使用界面在活动上显示状态。将来自BroadcastReceiver类的字符串数据传递给Android活动
GpsLocationReceiver
public class GpsLocationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Toast.makeText(context, "GPS Disabled", Toast.LENGTH_SHORT).show();
}
}
我注册这个广播接收器中的Manifest.xml
<receiver android:name=".GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
什么是你的问题?你面临的问题是什么? –
我想将数据从BroadcastReceiver传递给一个活动。 –
这将帮助你https://stackoverflow.com/questions/9137477/passing-data-from-broadcast-receiver-to-another-activity –