Init TelegramApplication from OsmAnd

This commit is contained in:
Alex Sytnyk 2018-09-06 15:54:47 +03:00
parent 1c2376f272
commit 20c14b5496
3 changed files with 32 additions and 0 deletions

View file

@ -53,6 +53,15 @@
<receiver android:name=".OnTelegramServiceAlarmReceiver" />
<receiver
android:name=".InitAppBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="net.osmand.telegram.InitApp"/>
</intent-filter>
</receiver>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="net.osmand.telegram.fileprovider"

View file

@ -0,0 +1,12 @@
package net.osmand.telegram
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
class InitAppBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// do nothing, TelegramApplication already initialized
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.aidl;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -176,6 +177,7 @@ public class OsmandAidlApi {
registerStopNavigationReceiver(mapActivity);
registerMuteNavigationReceiver(mapActivity);
registerUnmuteNavigationReceiver(mapActivity);
initOsmandTelegram();
}
public void onDestroyMapActivity(MapActivity mapActivity) {
@ -197,6 +199,15 @@ public class OsmandAidlApi {
return mapActivityActive;
}
private void initOsmandTelegram() {
String[] packages = new String[]{"net.osmand.telegram", "net.osmand.telegram.debug"};
Intent intent = new Intent("net.osmand.telegram.InitApp");
for (String pack : packages) {
intent.setComponent(new ComponentName(pack, "net.osmand.telegram.InitAppBroadcastReceiver"));
app.sendBroadcast(intent);
}
}
private void registerRefreshMapReceiver(MapActivity mapActivity) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
BroadcastReceiver refreshMapReceiver = new BroadcastReceiver() {