Forward calls from msg to off VK apps (#1094)

Co-authored-by: saoq <wfmfe@ya.ru>
This commit is contained in:
Saoqq
2023-02-12 02:18:27 +03:00
committed by GitHub
co-authored by saoq
parent a15cd9bd0b
commit 62c11b90dc
6 changed files with 189 additions and 829 deletions
@@ -13,6 +13,7 @@ import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.LifecycleUtils;
import static android.widget.Toast.LENGTH_SHORT;
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
public class CallsHook {
public static void forwardToVkOffApps(View view, ExtendedUserProfile p) {
@@ -23,6 +24,10 @@ public class CallsHook {
call(view.getContext(), dl.getId());
}
public static void forwardToVkOffApps(Context ctx, int userId) {
call(ctx, userId);
}
public static void call(Context ctx, int id) {
// FIXME: add com.vk.calls, right now it doesn't support intent
var vkim = checkPackage("com.vk.im");
@@ -33,9 +38,13 @@ public class CallsHook {
Toast.makeText(LifecycleUtils.getCurrentActivity(), AndroidUtils.getString("calls_not_available"), LENGTH_SHORT).show();
try {
ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.vkontakte.android")));
var action = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.vkontakte.android"));
action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(action);
} catch (android.content.ActivityNotFoundException e) {
ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.vkontakte.android")));
var action = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.vkontakte.android"));
action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(action);
}
return;
@@ -43,12 +52,13 @@ public class CallsHook {
var link = "https://vk.com/call?id=" + id;
var startCall = new Intent(Intent.ACTION_VIEW, Uri.parse(link)).setPackage(vk ? "com.vkontakte.android" : "com.vk.im");
startCall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(startCall);
}
private static Boolean checkPackage(String packageName) {
try {
var pm = AndroidUtils.getGlobalContext().getPackageManager();
var pm = getGlobalContext().getPackageManager();
return pm.getApplicationInfo(packageName, 0).enabled;
} catch (PackageManager.NameNotFoundException e) {
return false;