2 つのサービス (別のサービスを呼び出す DashClock 拡張サービス) があり、2 番目のサービスは値を保存することになっているため、その値を使用して DashClock 拡張機能に表示できます。ただし、この値は拡張サービスに渡されないようです。
DashClock 拡張機能:
@Override
public void onCreate() {
super.onCreate();
be=this;
//numUpdates = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getInt("numUpdates", -1);
Intent i = new Intent(this, UpdateCheckService.class);
i.putExtra(Constants.CHECK_FOR_UPDATE, true);
startService(i);
//numUpdates = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getInt("numUpdates", 0);
registerReceiver(myReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
}
@Override
protected void onUpdateData(int reason) {
// Get preference value.
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
//String name = sp.getString(PREF_NAME, "Eric");
Log.d("hiya","updating");
/*while(getSharedPreferences("PREFERENCE", MODE_PRIVATE).getInt("numUpdates", -1)==-1){
Log.d("wait","waiting here");
}*/
//numUpdates = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getInt("numUpdates", -2);
int numUpdates = sp.getInt("numUpdates", -2);
Log.d("IMPORTANT FROM BrianExtension", "" + numUpdates);
Intent intent = new Intent();
intent.setClassName("com.cyanogenmod.updater", "com.cyanogenmod.updater.UpdatesSettings");
// Publish the extension data update.
if(numUpdates == 0){
shouldShow = false;
} else{
shouldShow = true;
}
publishUpdate(new ExtensionData()
.visible(shouldShow)
.icon(R.drawable.cid)
.status(numUpdates + " updates")
.expandedTitle(numUpdates + " Nightly CM Updates")
.expandedBody("Click here to go to CMUpdater.")
.clickIntent(intent));
}
UpdateCheckService:
@Override
public void onCreate() {
ucs = this;
registerReceiver(mReceiver, new IntentFilter("updatethis"));
/*prefs = getSharedPreferences("PREFERENCE", Context.MODE_PRIVATE);
prefs.registerOnSharedPreferenceChangeListener(mListener);*/
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
try {
int ericUpdates = getAvailableUpdates().getUpdateCount(getBaseContext());
Log.d("yes!", ""+ericUpdates);
sp.edit().putInt("numUpdates", ericUpdates).apply();
Log.d("IMPORTANT FROM UpdateCheckService", "" + sp.getInt("numUpdates", -99));
//getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit().putInt("numUpdates", ericUpdates).apply();
//Log.d("IMPORTANT FROM UpdateCheckService", "" + getSharedPreferences("PREFERENCE", MODE_PRIVATE).getInt("numUpdates", -99));
sendBroadcast(new Intent(ucs, BrianUpdaterReceiver.class));
//BrianExtension.be.onUpdateData(4);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
//stopSelf();
// Get the System Mod string
mSystemMod = TESTING_DOWNLOAD ? "cmtestdevice" : SysUtils.getSystemProperty(Customization.BOARD);
if (mSystemMod == null) {
Log.i(TAG, "Unable to determine System's Mod version. Updater will show all available updates");
}
}
ログは、「numUpdates」設定の値が UpdateCheckService では正しいが、BrianExtension では -2 のままであることを示しています。
マニフェスト エントリ:
<service android:name=".BrianExtension"
android:icon="@drawable/cid"
android:label="CyanogenMod Updates"
android:permission="com.google.android.apps.dashclock.permission.READ_EXTENSION_DATA">
<intent-filter>
<action android:name="com.google.android.apps.dashclock.Extension" />
</intent-filter>
<meta-data android:name="protocolVersion" android:value="1" />
<meta-data android:name="description"
android:value="Displays Number of New Nightly Updates Available" />
</service>
<service android:name="com.brianco.cyanogenmodupdatecheckfordashclock.UpdateCheckService"
android:process="com.brianco.cyanogenmodupdatecheckfordashclock.UpdateCheckService">
<intent-filter>
<action android:name="com.brianco.cyanogenmodupdatecheckfordashclock.IUpdateCheckService"/>
</intent-filter>
</service>