Example usage for android.app Activity getComponentName

List of usage examples for android.app Activity getComponentName

Introduction

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

Prototype

public ComponentName getComponentName() 

Source Link

Document

Returns the complete component name of this activity.

Usage

From source file:Main.java

public static String getActivityMetaData(Activity activity, String key) {
    try {/*from   w w w . j a v a  2 s.co m*/
        return activity.getPackageManager().getActivityInfo(activity.getComponentName(),
                PackageManager.GET_META_DATA).metaData.getString(key);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getMeta(Activity context, String key) throws PackageManager.NameNotFoundException {
    ActivityInfo info = context.getPackageManager().getActivityInfo(context.getComponentName(),
            PackageManager.GET_META_DATA);
    String value = info.metaData.getString(key);
    return value;
}

From source file:Main.java

/**
 * Get activity meta-data.//from w  w  w . j  a v  a 2 s. c  om
 * @param activity activity to get meta-data from.
 * @return meta-data, may be empty but never null.
 */
public static Bundle getActivityMetaData(Activity activity) {
    Bundle config;
    try {
        config = activity.getPackageManager().getActivityInfo(activity.getComponentName(),
                GET_META_DATA).metaData;
        if (config == null)
            config = new Bundle();
    } catch (Exception e) {
        /*
         * NameNotFoundException or in some rare scenario an undocumented "RuntimeException: Package
         * manager has died.", probably caused by a system app process crash.
         */
        config = new Bundle();
    }
    return config;
}

From source file:Main.java

public static String getActivityMetaData(Activity activity, String key) {
    String data = null;//from   w w  w .j a  v  a 2 s  . c  o m
    ActivityInfo info = null;
    try {
        info = activity.getPackageManager().getActivityInfo(activity.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    if (info != null) {
        data = info.metaData.get(key).toString();
    }
    return data;
}

From source file:Main.java

public static boolean isTopActivy(Activity activity) {
    ActivityManager manager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
    String cmpNameTemp = null;//from  w  w  w .j  ava  2s  .c o m

    if (null != runningTaskInfos) {
        cmpNameTemp = (runningTaskInfos.get(0).topActivity).toString();
    }
    return null != cmpNameTemp && cmpNameTemp.equals(activity.getComponentName().toString());
}

From source file:net.lp.actionbarpoirot.helpers.DualNavUtils.java

/**
 * Return the fully qualified class name of sourceActivity's parent activity
 * as specified by a {@link #PARENT_ACTIVITY} &lt;meta-data&gt; element
 * within the activity element in the application's manifest.
 * /* w w w  . j  av a  2  s .c om*/
 * @param sourceActivity
 *            Activity to fetch a parent class name for
 * @return The fully qualified class name of sourceActivity's parent
 *         activity or null if it was not specified
 */
public static String getParentActivityName(Activity sourceActivity) {
    try {
        return getParentActivityName(sourceActivity, sourceActivity.getComponentName());
    } catch (NameNotFoundException e) {
        // Component name of supplied activity does not exist...?
        throw new IllegalArgumentException(e);
    }
}

From source file:com.vinexs.tool.Utility.java

public static String getAppName(Activity activity) {
    try {//from  w w  w . j a va2 s . com
        PackageManager packageMgr = activity.getPackageManager();
        ActivityInfo activityInfo = packageMgr.getActivityInfo(activity.getComponentName(), 0);
        return activityInfo.loadLabel(packageMgr).toString();
    } catch (Exception e) {
        return "";
    }
}

From source file:info.papdt.blacklight.support.Utility.java

public static void initDarkMode(Activity activity) {
    if (isDarkMode(activity)) {
        int theme = 0;

        try {/*w ww  .ja va 2 s.  c o  m*/
            theme = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).theme;
        } catch (NameNotFoundException e) {
            return;
        }

        // Convert to dark theme
        if (theme == R.style.BL_Theme_Light) {
            theme = R.style.BL_Theme_Dark;
        } else if (theme == R.style.BL_Theme_Light_Translucent) {
            theme = R.style.BL_Theme_Dark_Translucent;
        } else if (theme == R.style.BL_Theme_Light_TranslucentActionBar_NoTranslucent) {
            theme = R.style.BL_Theme_Dark_TranslucentActionBar_NoTranslucent;
        } else if (theme == R.style.BL_Theme_Light_TranslucentActionBar) {
            theme = R.style.BL_Theme_Dark_TranslucentActionBar;
        } else if (theme == R.style.BL_Theme_Light_GradientActionBar) {
            theme = R.style.BL_Theme_Dark_GradientActionBar;
        } else if (theme == R.style.BL_Theme_Light_WithNav) {
            theme = R.style.BL_Theme_Dark_WithNav;
        }

        activity.setTheme(theme);
    }
}

From source file:com.android.browser.DownloadHandler.java

/**
 * Notify the host application a download should be done, or that
 * the data should be streamed if a streaming viewer is available.
 * @param activity Activity requesting the download.
 * @param url The full url to the content that should be downloaded
 * @param userAgent User agent of the downloading application.
 * @param contentDisposition Content-disposition http header, if present.
 * @param mimetype The mimetype of the content reported by the server
 * @param referer The referer associated with the downloaded url
 * @param privateBrowsing If the request is coming from a private browsing tab.
 *//*from  w w w. j a  v  a 2  s  . c  o m*/
public static void onDownloadStart(Activity activity, String url, String userAgent, String contentDisposition,
        String mimetype, String referer, boolean privateBrowsing) {
    // if we're dealing wih A/V content that's not explicitly marked
    //     for download, check if it's streamable.
    if (contentDisposition == null || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) {
        // query the package manager to see if there's a registered handler
        //     that matches.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(url), mimetype);
        ResolveInfo info = activity.getPackageManager().resolveActivity(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (info != null) {
            ComponentName myName = activity.getComponentName();
            // If we resolved to ourselves, we don't want to attempt to
            // load the url only to try and download it again.
            if (!myName.getPackageName().equals(info.activityInfo.packageName)
                    || !myName.getClassName().equals(info.activityInfo.name)) {
                // someone (other than us) knows how to handle this mime
                // type with this scheme, don't download.
                try {
                    activity.startActivity(intent);
                    return;
                } catch (ActivityNotFoundException ex) {
                    if (LOGD_ENABLED) {
                        Log.d(LOGTAG,
                                "activity not found for " + mimetype + " over " + Uri.parse(url).getScheme(),
                                ex);
                    }
                    // Best behavior is to fall back to a download in this
                    // case
                }
            }
        }
    }
    onDownloadStartNoStream(activity, url, userAgent, contentDisposition, mimetype, referer, privateBrowsing);
}

From source file:com.ontheroad.www.googlefragmentsimple.HeadlinesFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    Log.i("TAG", "HeadlinesFragment onAttach:" + activity.getComponentName().toString());
    // This makes sure that the container activity has implemented
    // the callback interface. If not, it throws an exception.
    try {/*  ww  w  .ja  v  a 2 s .c om*/
        //MainActivity
        mCallback = (OnHeadlineSelectedListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString() + " must implement OnHeadlineSelectedListener");
    }
}