get Channel Id - Android android.content.pm

Android examples for android.content.pm:ApplicationInfo

Description

get Channel Id

Demo Code

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 w w  w . j av  a 2 s. co  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