Use URI instead of app package

This commit is contained in:
Alex Sytnyk 2018-07-30 15:43:32 +03:00
parent 537acf4f53
commit c090c1c148
8 changed files with 40 additions and 32 deletions

View file

@ -30,6 +30,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="main_activity"
android:scheme="osmand_telegram" />
</intent-filter>
</activity>
<service

View file

@ -6,22 +6,22 @@ import android.os.Parcelable;
public class AddOpenAppNavDrawerItemParams implements Parcelable {
private String itemName;
private String appPackage;
private String uri;
private int flags;
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage) {
this(itemName, appPackage, -1);
public AddOpenAppNavDrawerItemParams(String itemName, String uri) {
this(itemName, uri, -1);
}
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage, int flags) {
public AddOpenAppNavDrawerItemParams(String itemName, String uri, int flags) {
this.itemName = itemName;
this.appPackage = appPackage;
this.uri = uri;
this.flags = flags;
}
protected AddOpenAppNavDrawerItemParams(Parcel in) {
itemName = in.readString();
appPackage = in.readString();
uri = in.readString();
flags = in.readInt();
}
@ -29,8 +29,8 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
return itemName;
}
public String getAppPackage() {
return appPackage;
public String getUri() {
return uri;
}
public int getFlags() {
@ -40,7 +40,7 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(itemName);
dest.writeString(appPackage);
dest.writeString(uri);
dest.writeInt(flags);
}

View file

@ -44,9 +44,7 @@ class TelegramApplication : Application(), OsmandHelperListener {
osmandAidlHelper.listener = object : OsmandAidlHelper.OsmandHelperListener {
override fun onOsmandConnectionStateChanged(connected: Boolean) {
if (connected) {
val basePackage = "net.osmand.telegram"
val appPackage = if (BuildConfig.DEBUG) "$basePackage.debug" else basePackage
osmandAidlHelper.addOpenAppNavDrawerItem(getString(R.string.app_name), appPackage, -1)
osmandAidlHelper.addOpenAppNavDrawerItem(getString(R.string.app_name), "osmand_telegram://main_activity", -1)
}
}
}

View file

@ -868,10 +868,10 @@ class OsmandAidlHelper(private val app: Application) {
return false
}
fun addOpenAppNavDrawerItem(itemName: String, appPackage: String, flags: Int): Boolean {
fun addOpenAppNavDrawerItem(itemName: String, uri: String, flags: Int): Boolean {
if (mIOsmAndAidlInterface != null) {
try {
return mIOsmAndAidlInterface!!.addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams(itemName, appPackage, flags))
return mIOsmAndAidlInterface!!.addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams(itemName, uri, flags))
} catch (e: RemoteException) {
e.printStackTrace()
}

View file

@ -1192,11 +1192,11 @@ public class OsmandAidlApi {
return true;
}
boolean addOpenAppNavDrawerItem(String itemName, String appPackage, int flags) {
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(appPackage)) {
boolean addOpenAppNavDrawerItem(String itemName, String uri, int flags) {
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(uri)) {
OsmandSettings settings = app.getSettings();
settings.API_NAV_DRAWER_ITEM_NAME.set(itemName);
settings.API_NAV_DRAWER_ITEM_APP_PACKAGE.set(appPackage);
settings.API_NAV_DRAWER_ITEM_URI.set(uri);
settings.API_NAV_DRAWER_ITEM_FLAGS.set(flags);
return true;
}
@ -1206,10 +1206,10 @@ public class OsmandAidlApi {
public void registerNavDrawerItem(final Activity activity, ContextMenuAdapter adapter) {
final OsmandSettings settings = app.getSettings();
final String itemName = settings.API_NAV_DRAWER_ITEM_NAME.get();
final String appPackage = settings.API_NAV_DRAWER_ITEM_APP_PACKAGE.get();
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(appPackage)) {
final Intent intent = activity.getPackageManager().getLaunchIntentForPackage(appPackage);
if (intent != null) {
final String uri = settings.API_NAV_DRAWER_ITEM_URI.get();
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(uri)) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
if (intent.resolveActivity(activity.getPackageManager()) != null) {
int flags = settings.API_NAV_DRAWER_ITEM_FLAGS.get();
if (flags != -1) {
intent.addFlags(flags);

View file

@ -462,7 +462,7 @@ public class OsmandAidlService extends Service {
@Override
public boolean addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams params) throws RemoteException {
try {
return params != null && getApi("addOpenAppNavDrawerItem").addOpenAppNavDrawerItem(params.getItemName(), params.getAppPackage(), params.getFlags());
return params != null && getApi("addOpenAppNavDrawerItem").addOpenAppNavDrawerItem(params.getItemName(), params.getUri(), params.getFlags());
} catch (Exception e) {
handleException(e);
return false;

View file

@ -6,22 +6,22 @@ import android.os.Parcelable;
public class AddOpenAppNavDrawerItemParams implements Parcelable {
private String itemName;
private String appPackage;
private String uri;
private int flags;
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage) {
this(itemName, appPackage, -1);
public AddOpenAppNavDrawerItemParams(String itemName, String uri) {
this(itemName, uri, -1);
}
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage, int flags) {
public AddOpenAppNavDrawerItemParams(String itemName, String uri, int flags) {
this.itemName = itemName;
this.appPackage = appPackage;
this.uri = uri;
this.flags = flags;
}
protected AddOpenAppNavDrawerItemParams(Parcel in) {
itemName = in.readString();
appPackage = in.readString();
uri = in.readString();
flags = in.readInt();
}
@ -29,8 +29,8 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
return itemName;
}
public String getAppPackage() {
return appPackage;
public String getUri() {
return uri;
}
public int getFlags() {
@ -40,7 +40,7 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(itemName);
dest.writeString(appPackage);
dest.writeString(uri);
dest.writeInt(flags);
}

View file

@ -743,7 +743,7 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_DASHBOARD_ON_MAP_SCREEN = new BooleanPreference("show_dashboard_on_map_screen", false).makeGlobal();
public final CommonPreference<String> API_NAV_DRAWER_ITEM_NAME = new StringPreference("api_nav_drawer_item_name", "").makeGlobal();
public final CommonPreference<String> API_NAV_DRAWER_ITEM_APP_PACKAGE = new StringPreference("api_nav_drawer_item_app_package", "").makeGlobal();
public final CommonPreference<String> API_NAV_DRAWER_ITEM_URI = new StringPreference("api_nav_drawer_item_uri", "").makeGlobal();
public final CommonPreference<Integer> API_NAV_DRAWER_ITEM_FLAGS = new IntPreference("api_nav_drawer_item_flags", -1).makeGlobal();
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();