get Channel Id from PackageManager - Android App

Android examples for App:Package

Description

get Channel Id from PackageManager

Demo Code


//package com.java2s;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;

public class Main {

    public static String getChannelId(Context context) {
        if (context == null) {
            return "channel";
        }/*from  www  .ja  v a2 s .c o  m*/
        PackageManager pm = context.getPackageManager();
        ApplicationInfo appinfo;
        String platform_id = "";
        try {
            appinfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Bundle metaData = appinfo.metaData;
            platform_id = metaData.getString("UMENG_CHANNEL");
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return platform_id;
    }
}

Related Tutorials