【发布时间】:2015-03-24 09:27:27
【问题描述】:
我有两个服务。我需要使用来自一项服务的数据广播自定义意图。在第二次服务中,我需要收到它。我试过以下:
首次服役:
public String ACTION_CHANGE_TIME_FORMAT = "com.example.agile.mywatchface.changetimeformat";
Intent timeFormatIntent = new Intent();
timeFormatIntent.putExtra("format", 12);
timeFormatIntent.setAction(ACTION_CHANGE_TIME_FORMAT);
LocalBroadcastManager.getInstance(this).sendBroadcast(timeFormatIntent);
二次服役:
public String ACTION_CHANGE_TIME_FORMAT = "com.example.agile.mywatchface.changetimeformat";
public class TimeFormatReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Log.d(MyPreferences.LOGCAT_TAG, "Time format Broadcast received: ");
format = intent.getExtras().getInt("format", 0);
updateTime();
}
}
并且我已经在第二次服务中正确注册和未注册接收器:
IntentFilter timeFormatIntentFilter = new IntentFilter();
timeFormatIntentFilter.addAction(ACTION_CHANGE_TIME_FORMAT);
MyWatchfaceService.this.registerReceiver(timeFormatReceiver, timeFormatIntentFilter);
这里有什么问题吗?我无法获取数据(format)。
编辑:onRecieve() 没有调用。
【问题讨论】:
标签: android android-intent android-service android-broadcast watch-face-api