Example usage for android.app Activity getCallingActivity

List of usage examples for android.app Activity getCallingActivity

Introduction

In this page you can find the example usage for android.app Activity getCallingActivity.

Prototype

@Nullable
public ComponentName getCallingActivity() 

Source Link

Document

Return the name of the activity that invoked this activity.

Usage

From source file:Main.java

static String getCallingPackageName(Activity activity) {
    // getCallingPackage() was unstable until android-18, use this
    String packageName = activity.getCallingActivity().getPackageName();
    if (TextUtils.isEmpty(packageName)) {
        packageName = activity.getIntent().getPackage();
    }//from  w  w  w  .  j ava2 s  .  com
    if (TextUtils.isEmpty(packageName)) {
        Log.e(activity.getPackageName(),
                "Received blank Panic.ACTION_DISCONNECT Intent, it must be sent using startActivityForResult()!");
    }
    return packageName;
}

From source file:com.facebook.login.LoginFragment.java

private void initializeCallingPackage(final Activity activity) {
    ComponentName componentName = activity.getCallingActivity();
    if (componentName == null) {
        return;/* w w  w. j a  v a  2s  .  c o m*/
    }
    callingPackage = componentName.getPackageName();
}

From source file:com.facebook.AppEventsLogger.java

/**
 * Source Application setters and getters
 *//*from www  .  j a v  a  2s .  c  o m*/
private static void setSourceApplication(Activity activity) {

    ComponentName callingApplication = activity.getCallingActivity();
    if (callingApplication != null) {
        String callingApplicationPackage = callingApplication.getPackageName();
        if (callingApplicationPackage.equals(activity.getPackageName())) {
            // open by own app.
            resetSourceApplication();
            return;
        }
        sourceApplication = callingApplicationPackage;
    }

    // Tap icon to open an app will still get the old intent if the activity was opened by an intent before.
    // Introduce an extra field in the intent to force clear the sourceApplication.
    Intent openIntent = activity.getIntent();
    if (openIntent == null
            || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
        resetSourceApplication();
        return;
    }

    Bundle applinkData = AppLinks.getAppLinkData(openIntent);

    if (applinkData == null) {
        resetSourceApplication();
        return;
    }

    isOpenedByApplink = true;

    Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");

    if (applinkReferrerData == null) {
        sourceApplication = null;
        return;
    }

    String applinkReferrerPackage = applinkReferrerData.getString("package");
    sourceApplication = applinkReferrerPackage;

    // Mark this intent has been used to avoid use this intent again and again.
    openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);

    return;
}

From source file:com.facebook.appevents.AppEventsLogger.java

/**
 * Source Application setters and getters
 *//*from ww  w  .ja  va2s.com*/
private static void setSourceApplication(Activity activity) {

    ComponentName callingApplication = activity.getCallingActivity();
    if (callingApplication != null) {
        String callingApplicationPackage = callingApplication.getPackageName();
        if (callingApplicationPackage.equals(activity.getPackageName())) {
            // open by own app.
            resetSourceApplication();
            return;
        }
        sourceApplication = callingApplicationPackage;
    }

    // Tap icon to open an app will still get the old intent if the activity was opened by an
    // intent before. Introduce an extra field in the intent to force clear the
    // sourceApplication.
    Intent openIntent = activity.getIntent();
    if (openIntent == null
            || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
        resetSourceApplication();
        return;
    }

    Bundle applinkData = AppLinks.getAppLinkData(openIntent);

    if (applinkData == null) {
        resetSourceApplication();
        return;
    }

    isOpenedByApplink = true;

    Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");

    if (applinkReferrerData == null) {
        sourceApplication = null;
        return;
    }

    String applinkReferrerPackage = applinkReferrerData.getString("package");
    sourceApplication = applinkReferrerPackage;

    // Mark this intent has been used to avoid use this intent again and again.
    openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);

    return;
}