Use URI instead of app package
This commit is contained in:
parent
537acf4f53
commit
c090c1c148
8 changed files with 40 additions and 32 deletions
|
@ -30,6 +30,16 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</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>
|
</activity>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
|
|
|
@ -6,22 +6,22 @@ import android.os.Parcelable;
|
||||||
public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
|
|
||||||
private String itemName;
|
private String itemName;
|
||||||
private String appPackage;
|
private String uri;
|
||||||
private int flags;
|
private int flags;
|
||||||
|
|
||||||
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage) {
|
public AddOpenAppNavDrawerItemParams(String itemName, String uri) {
|
||||||
this(itemName, appPackage, -1);
|
this(itemName, uri, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage, int flags) {
|
public AddOpenAppNavDrawerItemParams(String itemName, String uri, int flags) {
|
||||||
this.itemName = itemName;
|
this.itemName = itemName;
|
||||||
this.appPackage = appPackage;
|
this.uri = uri;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AddOpenAppNavDrawerItemParams(Parcel in) {
|
protected AddOpenAppNavDrawerItemParams(Parcel in) {
|
||||||
itemName = in.readString();
|
itemName = in.readString();
|
||||||
appPackage = in.readString();
|
uri = in.readString();
|
||||||
flags = in.readInt();
|
flags = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
return itemName;
|
return itemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAppPackage() {
|
public String getUri() {
|
||||||
return appPackage;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFlags() {
|
public int getFlags() {
|
||||||
|
@ -40,7 +40,7 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeString(itemName);
|
dest.writeString(itemName);
|
||||||
dest.writeString(appPackage);
|
dest.writeString(uri);
|
||||||
dest.writeInt(flags);
|
dest.writeInt(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,7 @@ class TelegramApplication : Application(), OsmandHelperListener {
|
||||||
osmandAidlHelper.listener = object : OsmandAidlHelper.OsmandHelperListener {
|
osmandAidlHelper.listener = object : OsmandAidlHelper.OsmandHelperListener {
|
||||||
override fun onOsmandConnectionStateChanged(connected: Boolean) {
|
override fun onOsmandConnectionStateChanged(connected: Boolean) {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
val basePackage = "net.osmand.telegram"
|
osmandAidlHelper.addOpenAppNavDrawerItem(getString(R.string.app_name), "osmand_telegram://main_activity", -1)
|
||||||
val appPackage = if (BuildConfig.DEBUG) "$basePackage.debug" else basePackage
|
|
||||||
osmandAidlHelper.addOpenAppNavDrawerItem(getString(R.string.app_name), appPackage, -1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -868,10 +868,10 @@ class OsmandAidlHelper(private val app: Application) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addOpenAppNavDrawerItem(itemName: String, appPackage: String, flags: Int): Boolean {
|
fun addOpenAppNavDrawerItem(itemName: String, uri: String, flags: Int): Boolean {
|
||||||
if (mIOsmAndAidlInterface != null) {
|
if (mIOsmAndAidlInterface != null) {
|
||||||
try {
|
try {
|
||||||
return mIOsmAndAidlInterface!!.addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams(itemName, appPackage, flags))
|
return mIOsmAndAidlInterface!!.addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams(itemName, uri, flags))
|
||||||
} catch (e: RemoteException) {
|
} catch (e: RemoteException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1192,11 +1192,11 @@ public class OsmandAidlApi {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean addOpenAppNavDrawerItem(String itemName, String appPackage, int flags) {
|
boolean addOpenAppNavDrawerItem(String itemName, String uri, int flags) {
|
||||||
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(appPackage)) {
|
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(uri)) {
|
||||||
OsmandSettings settings = app.getSettings();
|
OsmandSettings settings = app.getSettings();
|
||||||
settings.API_NAV_DRAWER_ITEM_NAME.set(itemName);
|
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);
|
settings.API_NAV_DRAWER_ITEM_FLAGS.set(flags);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1206,10 +1206,10 @@ public class OsmandAidlApi {
|
||||||
public void registerNavDrawerItem(final Activity activity, ContextMenuAdapter adapter) {
|
public void registerNavDrawerItem(final Activity activity, ContextMenuAdapter adapter) {
|
||||||
final OsmandSettings settings = app.getSettings();
|
final OsmandSettings settings = app.getSettings();
|
||||||
final String itemName = settings.API_NAV_DRAWER_ITEM_NAME.get();
|
final String itemName = settings.API_NAV_DRAWER_ITEM_NAME.get();
|
||||||
final String appPackage = settings.API_NAV_DRAWER_ITEM_APP_PACKAGE.get();
|
final String uri = settings.API_NAV_DRAWER_ITEM_URI.get();
|
||||||
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(appPackage)) {
|
if (!TextUtils.isEmpty(itemName) && !TextUtils.isEmpty(uri)) {
|
||||||
final Intent intent = activity.getPackageManager().getLaunchIntentForPackage(appPackage);
|
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
|
||||||
if (intent != null) {
|
if (intent.resolveActivity(activity.getPackageManager()) != null) {
|
||||||
int flags = settings.API_NAV_DRAWER_ITEM_FLAGS.get();
|
int flags = settings.API_NAV_DRAWER_ITEM_FLAGS.get();
|
||||||
if (flags != -1) {
|
if (flags != -1) {
|
||||||
intent.addFlags(flags);
|
intent.addFlags(flags);
|
||||||
|
|
|
@ -462,7 +462,7 @@ public class OsmandAidlService extends Service {
|
||||||
@Override
|
@Override
|
||||||
public boolean addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams params) throws RemoteException {
|
public boolean addOpenAppNavDrawerItem(AddOpenAppNavDrawerItemParams params) throws RemoteException {
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -6,22 +6,22 @@ import android.os.Parcelable;
|
||||||
public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
|
|
||||||
private String itemName;
|
private String itemName;
|
||||||
private String appPackage;
|
private String uri;
|
||||||
private int flags;
|
private int flags;
|
||||||
|
|
||||||
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage) {
|
public AddOpenAppNavDrawerItemParams(String itemName, String uri) {
|
||||||
this(itemName, appPackage, -1);
|
this(itemName, uri, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddOpenAppNavDrawerItemParams(String itemName, String appPackage, int flags) {
|
public AddOpenAppNavDrawerItemParams(String itemName, String uri, int flags) {
|
||||||
this.itemName = itemName;
|
this.itemName = itemName;
|
||||||
this.appPackage = appPackage;
|
this.uri = uri;
|
||||||
this.flags = flags;
|
this.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AddOpenAppNavDrawerItemParams(Parcel in) {
|
protected AddOpenAppNavDrawerItemParams(Parcel in) {
|
||||||
itemName = in.readString();
|
itemName = in.readString();
|
||||||
appPackage = in.readString();
|
uri = in.readString();
|
||||||
flags = in.readInt();
|
flags = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
return itemName;
|
return itemName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAppPackage() {
|
public String getUri() {
|
||||||
return appPackage;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFlags() {
|
public int getFlags() {
|
||||||
|
@ -40,7 +40,7 @@ public class AddOpenAppNavDrawerItemParams implements Parcelable {
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
dest.writeString(itemName);
|
dest.writeString(itemName);
|
||||||
dest.writeString(appPackage);
|
dest.writeString(uri);
|
||||||
dest.writeInt(flags);
|
dest.writeInt(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<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_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> 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();
|
public final CommonPreference<Integer> NUMBER_OF_STARTS_FIRST_XMAS_SHOWN = new IntPreference("number_of_starts_first_xmas_shown", 0).makeGlobal();
|
||||||
|
|
Loading…
Reference in a new issue