Java Code Examples for android.app.Activity#getCallingActivity()

The following examples show how to use android.app.Activity#getCallingActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskerPlugin.java    From sony-headphones-control with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used by: plugin EditActivity.
 *
 * Description as above.
 *
 * This version also includes backwards compatibility with pre 4.2 Tasker versions.
 * At some point this function will be deprecated.
 *
 * @param  editActivity the plugin edit activity, needed to test calling Tasker version
 * @see #setVariableReplaceKeys(Bundle, String[])
 */

public static boolean hostSupportsOnFireVariableReplacement( Activity editActivity ) {

    boolean supportedFlag = hostSupportsOnFireVariableReplacement( editActivity.getIntent().getExtras() );

    if ( ! supportedFlag ) {

        ComponentName callingActivity = editActivity.getCallingActivity();

        if ( callingActivity == null )
            Log.w( TAG, "hostSupportsOnFireVariableReplacement: null callingActivity, defaulting to false" );
        else {
            String callerPackage = callingActivity.getPackageName();

            // Tasker only supporteed this from 1.0.10
            supportedFlag =
                    ( callerPackage.startsWith( BASE_KEY ) ) &&
                            ( getPackageVersionCode( editActivity.getPackageManager(), callerPackage ) > FIRST_ON_FIRE_VARIABLES_TASKER_VERSION )
            ;
        }
    }

    return supportedFlag;
}
 
Example 2
Source File: CallerUtil.java    From OpenYOLO-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the set of authentication domains for the caller of the provided activity.
 */
@NonNull
public static Set<AuthenticationDomain> extractCallerAuthDomains(@NonNull Activity activity) {
    ComponentName callingActivity = activity.getCallingActivity();
    if (callingActivity == null) {
        return Collections.emptySet();
    }

    String callingPackage = callingActivity.getPackageName();
    AuthenticationDomain authenticationDomain =
            AuthenticationDomain.fromPackageName(activity, callingPackage);
    if (null == authenticationDomain) {
        return Collections.EMPTY_SET;
    }

    return new HashSet<>(Arrays.asList(authenticationDomain));
}
 
Example 3
Source File: TaskerPlugin.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used by: plugin EditActivity.
 * 
 * Description as above.
 * 
 * This version also includes backwards compatibility with pre 4.2 Tasker versions.
 * At some point this function will be deprecated.
 * 
 * @param  editActivity the plugin edit activity, needed to test calling Tasker version
 * @see #setVariableReplaceKeys(Bundle, String[])
*/

public static boolean hostSupportsOnFireVariableReplacement( Activity editActivity ) {
	
	boolean supportedFlag = hostSupportsOnFireVariableReplacement( editActivity.getIntent().getExtras() );
	
	if ( ! supportedFlag ) {
		String callerPackage = (editActivity.getCallingActivity() != null) ? editActivity.getCallingActivity().getPackageName() : "null";
		
		// Tasker only supporteed this from 1.0.10
		supportedFlag = 
				( callerPackage.startsWith( BASE_KEY ) ) &&
				( getPackageVersionCode( editActivity.getPackageManager(), callerPackage ) > FIRST_ON_FIRE_VARIABLES_TASKER_VERSION )
		;
	}
	
	return supportedFlag;
}
 
Example 4
Source File: TaskerPlugin.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used by: plugin EditActivity.
 * 
 * Description as above.
 * 
 * This version also includes backwards compatibility with pre 4.2 Tasker versions.
 * At some point this function will be deprecated.
 * 
 * @param  editActivity the plugin edit activity, needed to test calling Tasker version
 * @see #setVariableReplaceKeys(Bundle, String[])
*/

public static boolean hostSupportsOnFireVariableReplacement( Activity editActivity ) {
	
	boolean supportedFlag = hostSupportsOnFireVariableReplacement( editActivity.getIntent().getExtras() );
	
	if ( ! supportedFlag ) {
		String callerPackage = (editActivity.getCallingActivity() != null) ? editActivity.getCallingActivity().getPackageName() : "null";
		
		// Tasker only supporteed this from 1.0.10
		supportedFlag = 
				( callerPackage.startsWith( BASE_KEY ) ) &&
				( getPackageVersionCode( editActivity.getPackageManager(), callerPackage ) > FIRST_ON_FIRE_VARIABLES_TASKER_VERSION )
		;
	}
	
	return supportedFlag;
}
 
Example 5
Source File: TaskerPlugin.java    From MaxLock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Used by: plugin EditActivity.
 * <p>
 * Description as above.
 * <p>
 * This version also includes backwards compatibility with pre 4.2 Tasker versions.
 * At some point this function will be deprecated.
 *
 * @param editActivity the plugin edit activity, needed to test calling Tasker version
 * @see #setVariableReplaceKeys(Bundle, String[])
 */

public static boolean hostSupportsOnFireVariableReplacement(Activity editActivity) {

    boolean supportedFlag = hostSupportsOnFireVariableReplacement(editActivity.getIntent().getExtras());

    if (!supportedFlag) {

        ComponentName callingActivity = editActivity.getCallingActivity();

        if (callingActivity == null)
            Log.w(TAG, "hostSupportsOnFireVariableReplacement: null callingActivity, defaulting to false");
        else {
            String callerPackage = callingActivity.getPackageName();

            // Tasker only supporteed this from 1.0.10
            supportedFlag =
                    (callerPackage.startsWith(BASE_KEY)) &&
                            (getPackageVersionCode(editActivity.getPackageManager(), callerPackage) > FIRST_ON_FIRE_VARIABLES_TASKER_VERSION)
            ;
        }
    }

    return supportedFlag;
}
 
Example 6
Source File: LoginFragment.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private void initializeCallingPackage(final Activity activity) {
    ComponentName componentName = activity.getCallingActivity();
    if (componentName == null) {
        return;
    }
    callingPackage = componentName.getPackageName();
}
 
Example 7
Source File: AbstractSamplerPropertiesFragment.java    From ShaderEditor with MIT License 5 votes vote down vote up
protected View initView(
		Activity activity,
		LayoutInflater inflater,
		ViewGroup container) {
	View view = inflater.inflate(
			R.layout.fragment_sampler_properties,
			container,
			false);

	sizeCaption = view.findViewById(R.id.size_caption);
	sizeBarView = view.findViewById(R.id.size_bar);
	sizeView = view.findViewById(R.id.size);
	nameView = view.findViewById(R.id.name);
	addUniformView = view.findViewById(
			R.id.should_add_uniform);
	textureParameterView = view.findViewById(
			R.id.texture_parameters);
	progressView = view.findViewById(R.id.progress_view);

	view.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			saveSamplerAsync();
		}
	});

	if (activity.getCallingActivity() == null) {
		addUniformView.setVisibility(View.GONE);
		addUniformView.setChecked(false);
		textureParameterView.setVisibility(View.GONE);
	}

	initSizeView();
	initNameView();

	return view;
}
 
Example 8
Source File: ShareCompat.java    From letv with Apache License 2.0 5 votes vote down vote up
public static ComponentName getCallingActivity(Activity calledActivity) {
    ComponentName result = calledActivity.getCallingActivity();
    if (result == null) {
        return (ComponentName) calledActivity.getIntent().getParcelableExtra(EXTRA_CALLING_ACTIVITY);
    }
    return result;
}
 
Example 9
Source File: AppEventsLogger.java    From facebook-api-android-maven with Apache License 2.0 4 votes vote down vote up
/**
 * Source Application setters and getters
 */
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;
}
 
Example 10
Source File: AppEventsLogger.java    From Abelana-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Source Application setters and getters
 */
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;
}
 
Example 11
Source File: LoginFragment.java    From letv with Apache License 2.0 4 votes vote down vote up
private void initializeCallingPackage(Activity activity) {
    ComponentName componentName = activity.getCallingActivity();
    if (componentName != null) {
        this.callingPackage = componentName.getPackageName();
    }
}
 
Example 12
Source File: AppEventsLogger.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
/**
 * Source Application setters and getters
 */
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;
}
 
Example 13
Source File: TrustedIntents.java    From TrustedIntents with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Get the package name of the {@link Activity} that sent the
 * {@link Intent} that started this {@code Activity}.
 * <p/>
 * <strong>WARNING</strong>: If the {@code Activity} has
 * {@code android:launchMode="singleInstance"} or {@code "singleTask"}, then
 * this method will not disconnect because it is not possible to get the
 * calling {@code Activity}, as set by
 * {@link Activity#startActivityForResult(Intent, int)}
 *
 * @param activity the {@code Activity} to check for the {@code Intent}
 * @return the package of the sending app or {@code null} if it was not a
 * {@code ACTION_CONNECT Intent} or the {@code Intent} was not sent
 * with {@link Activity#startActivityForResult(Intent, int)}
 */
public static String getCallingPackageName(Activity activity) {
    // getCallingPackage() was unstable until android-18, use this
    ComponentName componentName = activity.getCallingActivity();
    if (componentName == null)
        return null;
    String packageName = componentName.getPackageName();
    if (TextUtils.isEmpty(packageName)) {
        Log.e(activity.getClass().getSimpleName(),
                "Received Intent without sender! The Intent must be sent using startActivityForResult() and received without launchMode singleTask or singleInstance!");
    }
    return packageName;
}
 
Example 14
Source File: ShareCompat.java    From android-recipes-app with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieve the ComponentName of the activity that launched calledActivity from a share intent.
 * Apps that provide social sharing functionality can use this to provide attribution
 * for the app that shared the content.
 *
 * <p><em>Note:</em> This data may have been provided voluntarily by the calling
 * application. As such it should not be trusted for accuracy in the context of
 * security or verification.</p>
 *
 * @param calledActivity Current activity that was launched to share content
 * @return ComponentName of the calling activity
 */
public static ComponentName getCallingActivity(Activity calledActivity) {
    ComponentName result = calledActivity.getCallingActivity();
    if (result == null) {
        result = calledActivity.getIntent().getParcelableExtra(EXTRA_CALLING_ACTIVITY);
    }
    return result;
}
 
Example 15
Source File: ShareCompat.java    From V.FlyoutTest with MIT License 3 votes vote down vote up
/**
 * Retrieve the ComponentName of the activity that launched calledActivity from a share intent.
 * Apps that provide social sharing functionality can use this to provide attribution
 * for the app that shared the content.
 *
 * <p><em>Note:</em> This data may have been provided voluntarily by the calling
 * application. As such it should not be trusted for accuracy in the context of
 * security or verification.</p>
 *
 * @param calledActivity Current activity that was launched to share content
 * @return ComponentName of the calling activity
 */
public static ComponentName getCallingActivity(Activity calledActivity) {
    ComponentName result = calledActivity.getCallingActivity();
    if (result == null) {
        result = calledActivity.getIntent().getParcelableExtra(EXTRA_CALLING_ACTIVITY);
    }
    return result;
}
 
Example 16
Source File: ShareCompat.java    From adt-leanback-support with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieve the ComponentName of the activity that launched calledActivity from a share intent.
 * Apps that provide social sharing functionality can use this to provide attribution
 * for the app that shared the content.
 *
 * <p><em>Note:</em> This data may have been provided voluntarily by the calling
 * application. As such it should not be trusted for accuracy in the context of
 * security or verification.</p>
 *
 * @param calledActivity Current activity that was launched to share content
 * @return ComponentName of the calling activity
 */
public static ComponentName getCallingActivity(Activity calledActivity) {
    ComponentName result = calledActivity.getCallingActivity();
    if (result == null) {
        result = calledActivity.getIntent().getParcelableExtra(EXTRA_CALLING_ACTIVITY);
    }
    return result;
}
 
Example 17
Source File: ShareCompat.java    From guideshow with MIT License 3 votes vote down vote up
/**
 * Retrieve the ComponentName of the activity that launched calledActivity from a share intent.
 * Apps that provide social sharing functionality can use this to provide attribution
 * for the app that shared the content.
 *
 * <p><em>Note:</em> This data may have been provided voluntarily by the calling
 * application. As such it should not be trusted for accuracy in the context of
 * security or verification.</p>
 *
 * @param calledActivity Current activity that was launched to share content
 * @return ComponentName of the calling activity
 */
public static ComponentName getCallingActivity(Activity calledActivity) {
    ComponentName result = calledActivity.getCallingActivity();
    if (result == null) {
        result = calledActivity.getIntent().getParcelableExtra(EXTRA_CALLING_ACTIVITY);
    }
    return result;
}
 
Example 18
Source File: ShareCompat.java    From CodenameOne with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Retrieve the ComponentName of the activity that launched calledActivity from a share intent.
 * Apps that provide social sharing functionality can use this to provide attribution
 * for the app that shared the content.
 *
 * <p><em>Note:</em> This data may have been provided voluntarily by the calling
 * application. As such it should not be trusted for accuracy in the context of
 * security or verification.</p>
 *
 * @param calledActivity Current activity that was launched to share content
 * @return ComponentName of the calling activity
 */
public static ComponentName getCallingActivity(Activity calledActivity) {
    ComponentName result = calledActivity.getCallingActivity();
    if (result == null) {
        result = calledActivity.getIntent().getParcelableExtra(EXTRA_CALLING_ACTIVITY);
    }
    return result;
}