get package name from PackageInfo - Android android.content.pm

Android examples for android.content.pm:PackageManager

Description

get package name from PackageInfo

Demo Code

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.res.Resources;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String getString(ComponentName component) {
        return String.format("%s/%s", component.getPackageName(),
                component.getClassName());
    }// ww  w .java 2  s .c o m
    public static String getString(PackageInfo info) {
        return info.packageName;
    }
    public static String getString(ApplicationInfo info) {
        return info.packageName;
    }
    public static String getString(ActivityInfo info) {
        return String.format("%s/%s", info.packageName, info.name);
    }
    public static String getString(String format, String separator,
            byte... bytes) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            if (separator != null && i > 0) {
                builder.append(separator);
            }
            builder.append(String.format(format, bytes[i]));
        }
        return builder.toString();
    }

}

Related Tutorials