Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Last active April 26, 2016 03:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TarasOsiris/1ab79165909ea01575a0 to your computer and use it in GitHub Desktop.
Save TarasOsiris/1ab79165909ea01575a0 to your computer and use it in GitHub Desktop.
This activity is created because we cannot get Activity.onNewIntent callback in Unity when the app is running in background.
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