Skip to content

Instantly share code, notes, and snippets.

@getsocial-im
Created February 3, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save getsocial-im/f026d9e2880ab6c173e7 to your computer and use it in GitHub Desktop.
Save getsocial-im/f026d9e2880ab6c173e7 to your computer and use it in GitHub Desktop.
Code for Android Unity App and the Intent Trouble Article on GetSocial Blog
package im.getsocial.sdk.core.unity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import im.getsocial.sdk.core.GetSocial;
import im.getsocial.sdk.core.util.Log;
/**
* Created by tarasleskiv on 29/01/16.
*
* This activity is created because we cannot get Activity.onNewIntent callback in Unity when the app is running in background.
*
* When the app is running in background and opened from e.g. browsers intent url, this activity intercepts the intent and forwards in to GetSocial.
*/
public class GetSocialDeepLinkingActivity extends Activity
{
private static String TAG = "GetSocial GetSocialDeepLinkingActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Log.v(TAG, "Forward the intent");
GetSocial.getInstance(getApplicationContext()).onNewIntent(getIntent());
Log.v(TAG, "Returning to main activity");
//start main activity
Intent newIntent = new Intent(this, getMainActivityClass());
this.startActivity(newIntent);
finish();
}
private Class<?> getMainActivityClass() {
String packageName = this.getPackageName();
Intent launchIntent = this.getPackageManager().getLaunchIntentForPackage(packageName);
try {
return Class.forName(launchIntent.getComponent().getClassName());
} catch (Exception e) {
Log.e(TAG, "Unable to find Main Activity Class");
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment