My Target: By pressing a button, a whatsapp video call to a specific person starts. I don't know Java well enough, so I would like to accomplish this via C# in Unity.
I tried to replicate this process by translating it into C#.
But there is something wrong, because once the button is pressed I can only access the whatsapp home.
I also added permissions to access contacts from the manifest.
I'm doing everything manually, so I pasted the script on android studio to find the _id of a specific contact that had the mimetype for whatsapp video calls.
So I tried to translate the call function via Unity's AndroidJavaClass:
Java code:
public void videoCall(String id){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://com.android.contacts/data/" + id),
"vnd.android.cursor.item/vnd.com.whatsapp.video.call");
intent.setPackage("com.whatsapp");
startActivity(intent);
}
C# code:
public static class Intentions
{
static string id = "5576";
static string data_url = "content://com.android.contacts/data/" + id;
static string type_url = "vnd.android.cursor.item / vnd.com.whatsapp.video.call";
public static AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
public static AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>
("currentActivity");
public static AndroidJavaObject packageManager = currentActivity.Call<AndroidJavaObject>
("getPackageManager");
public static AndroidJavaObject intent = packageManager.Call<AndroidJavaObject>
("getLaunchIntentForPackage", "com.whatsapp");
public static AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
public static AndroidJavaObject uriData = uriClass.CallStatic<AndroidJavaObject>("parse", data_url);
public static void Launch()
{
intent.Call<AndroidJavaObject>("setAction", "android.intent.action.VIEW");
intent.Call<AndroidJavaObject>("setDataAndType", uriData, type_url);
if (IsAndroid())
{
currentActivity.Call("startActivity", intent);
}
}
public static bool IsAndroid()
{
#if UNITY_ANDROID && !UNITY_EDITOR
return true;
#else
return false;
#endif
}
}