social share button with setPackage and setClassName
I'm trying to make a game with social share buttons for Facebook, Twitter, Instagram, etc separately. Because there are lots of social network apps, I'd like to use general approach which can be used for all apps universally rather than specific APIs. I use GalaxyS6 as a test phone and Android version is 7.0. Below is my code. When I use this, Facebook comes up correctly.
private void openSnsTest()
{
bool fail = false;
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
AndroidJavaObject launchIntent = null;
try
{
launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", "com.facebook.katana");
}
catch (System.Exception e)
{
fail = true;
}
if (fail)
{
Debug.Log("app not found");
}
else
{
ca.Call("startActivity", launchIntent);
}
up.Dispose();
ca.Dispose();
packageManager.Dispose();
launchIntent.Dispose();
}
And to open Twitter, I think I have to set the className because there are several apps for the same package name.
I changed this line:
launchIntent = packageManager.Call("getLaunchIntentForPackage", "com.facebook.katana");
into these lines:
launchIntent = packageManager.Call("getLaunchIntentForPackage", "com.twitter.android");
launchIntent.Call("setClassName", "com.twitter.android", "com.twitter.android.composer.ComposerActivity");
And, it's not working anymore. How can I call Twitter directly?
Your answer
![](https://koobas.hobune.stream/wayback/20220612133210im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Failed authenticating with google play services on android 0 Answers
How can I get friends list why playing my game by facebook sdk 0 Answers
Creating a Score/Highscore image at runtime 0 Answers
How can i reward the players who shared my game. 0 Answers
How does the Networking in Games like 'Draw Something' work? 1 Answer