Example usage for android.content.pm PackageManager GET_META_DATA

List of usage examples for android.content.pm PackageManager GET_META_DATA

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_META_DATA.

Prototype

int GET_META_DATA

To view the source code for android.content.pm PackageManager GET_META_DATA.

Click Source Link

Document

ComponentInfo flag: return the ComponentInfo#metaData data android.os.Bundle s that are associated with a component.

Usage

From source file:com.echopf.ECHOFcmListenerService.java

/**
 * Sets notification layouts.//from  w w  w.j  av a  2  s.  c  om
 * @param data 
 * @return NotificationCompat.Builder
 */
public NotificationCompat.Builder getNotificationBuilder(Bundle data) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setAutoCancel(true);

    // get ApplicationInfo
    ApplicationInfo appInfo = null;
    String appName = null;
    try {
        appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        appName = getPackageManager()
                .getApplicationLabel(getPackageManager().getApplicationInfo(getPackageName(), 0)).toString();
    } catch (NameNotFoundException e) {
        throw new RuntimeException(e);
    }

    // set title
    String title = (data.getString("title") != null) ? data.getString("title") : appName;
    notificationBuilder.setContentTitle(title);

    // set message
    if (data.getString("message") != null)
        notificationBuilder.setContentText(data.getString("message"));

    // set icon
    int manifestIco = appInfo.metaData.getInt(NOTIFICATION_ICON_KEY);
    int icon = (manifestIco != 0) ? manifestIco : appInfo.icon;
    notificationBuilder.setSmallIcon(icon);

    // set sound
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notificationBuilder.setSound(defaultSoundUri);

    // set content intent
    String activity = appInfo.metaData.getString(PUSH_OPEN_ACTIVITY_KEY);
    if (activity != null) {

        try {
            Intent intent = new Intent(this, Class.forName(activity)).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                    .setComponent(new ComponentName(appInfo.packageName, activity)).putExtras(data);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_CANCEL_CURRENT);
            notificationBuilder.setContentIntent(pendingIntent);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }

    return notificationBuilder;
}

From source file:info.icefilms.icestream.HelpFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // Call the base class method
    super.onActivityCreated(savedInstanceState);

    // Get the contact and about views
    TextView support = (TextView) getActivity().findViewById(R.id.support);
    TextView about = (TextView) getActivity().findViewById(R.id.about);

    // Linkify the support view
    Linkify.addLinks(support, Pattern.compile("(Ice Stream Support Thread)"), "", null, new TransformFilter() {
        public String transformUrl(Matcher match, String url) {
            // Return the proper link
            return "http://forum.icefilms.info/viewtopic.php?t=58350";
        }// w  w  w  .  j a  va  2s  .  co m
    });

    // Get the version information
    String version;
    try {
        version = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),
                PackageManager.GET_META_DATA).versionName;
    } catch (PackageManager.NameNotFoundException exception) {
        version = "?.?.?";
    }

    // Format the about text with the correct info and add it to the view
    about.setText(String.format(getString(R.string.help_about), getString(R.string.app_name), version));

    // Linkify the about view
    Linkify.addLinks(about, Linkify.WEB_URLS);
}

From source file:com.samsung.richnotification.RichNotification.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    String mPackageName = cordova.getActivity().getPackageName();
    PackageManager pm = cordova.getActivity().getPackageManager();
    try {//www.j a v a 2  s . co m
        ApplicationInfo ai = pm.getApplicationInfo(mPackageName, PackageManager.GET_META_DATA);
        if (ai.metaData != null) {
            pluginMetadata = ai.metaData.getBoolean(META_DATA);
        }
    } catch (NameNotFoundException e) {
    }
    IntentFilter filter = new IntentFilter("com.samsung.cordova.richnotification.remote_input_receiver");
    if (richRemoteInputReceiver != null) {
        cordova.getActivity().getApplicationContext().registerReceiver(richRemoteInputReceiver, filter);
    }
}

From source file:com.launcher.silverfish.AppDrawerTabFragment.java

private boolean addAppToArrayAdapter(String app_name) {
    try {/*  ww w. ja  v a2  s.  c  o m*/
        // Get the information about the app
        ApplicationInfo appInfo = mPacMan.getApplicationInfo(app_name, PackageManager.GET_META_DATA);
        AppDetail appDetail = new AppDetail();

        // And add it to the array adapter.
        appDetail.label = mPacMan.getApplicationLabel(appInfo);
        appDetail.icon = mPacMan.getApplicationIcon(appInfo);
        appDetail.name = app_name;
        arrayAdapter.add(appDetail);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        Toast.makeText(getActivity().getBaseContext(), "Error: Could not retrieve information about the app",
                Toast.LENGTH_LONG).show();
        return false;
    }
}

From source file:org.opensilk.music.ui2.loader.PluginLoader.java

public List<PluginInfo> getPluginInfos(boolean wantIcon) {
    final List<ComponentName> disabledPlugins = readDisabledPlugins();
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(API_PLUGIN_SERVICE),
            PackageManager.GET_META_DATA);
    final List<PluginInfo> pluginInfos = new ArrayList<PluginInfo>(resolveInfos.size() + 1);
    for (final ResolveInfo resolveInfo : resolveInfos) {
        if (resolveInfo.serviceInfo == null)
            continue;
        final PluginInfo pi = readResolveInfo(pm, disabledPlugins, resolveInfo);
        if (!wantIcon)
            pi.icon = null;// w ww .j a  v a  2s .c o m
        pluginInfos.add(pi);
    }
    Collections.sort(pluginInfos);
    // folders is special and is always first
    List<ResolveInfo> folderResolveInfos = pm
            .queryIntentServices(new Intent(context, FolderLibraryService.class), PackageManager.GET_META_DATA);
    if (folderResolveInfos != null && folderResolveInfos.size() > 0) {
        final ResolveInfo resolveInfo = folderResolveInfos.get(0);
        if (resolveInfo.serviceInfo != null) {
            final PluginInfo pi = readResolveInfo(pm, disabledPlugins, resolveInfo);
            if (!wantIcon)
                pi.icon = null;
            pluginInfos.add(0, pi);
        }
    }
    return pluginInfos;
}

From source file:eu.geopaparazzi.library.core.fragments.AboutFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    try {/* w w  w. jav  a 2 s .  c o  m*/
        AssetManager assetManager = getActivity().getAssets();
        InputStream inputStream = assetManager.open("about.html");
        String htmlText = new Scanner(inputStream).useDelimiter("\\A").next();

        String applicationName = "Geopaparazzi";
        try {
            applicationName = ResourcesManager.getInstance(getActivity()).getApplicationName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (packageName != null) {
            String version = "";
            try {
                PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(packageName,
                        PackageManager.GET_META_DATA);
                version = pInfo.versionName;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }

            htmlText = htmlText.replaceFirst("VERSION", version);
        } else {
            htmlText = htmlText.replaceFirst("VERSION", "");
        }

        htmlText = htmlText.replaceAll("Geopaparazzi", applicationName);

        WebView aboutView = (WebView) view;
        aboutView.loadData(htmlText, "text/html", "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.androidzeitgeist.dashwatch.muzei.SourceManager.java

public List<SourceListing> getAvailableSources() {
    List<SourceListing> sources = new ArrayList<SourceListing>();

    PackageManager pm = mApplicationContext.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(MuzeiArtSource.ACTION_MUZEI_ART_SOURCE),
            PackageManager.GET_META_DATA);

    for (ResolveInfo resolveInfo : resolveInfos) {
        SourceListing listing = new SourceListing();

        listing.componentName = new ComponentName(resolveInfo.serviceInfo.packageName,
                resolveInfo.serviceInfo.name);
        listing.title = resolveInfo.loadLabel(pm).toString();

        sources.add(listing);//from w  w  w .  j  a  va  2  s  .c  o m
    }

    return sources;
}

From source file:org.asl19.paskoocheh.push.MyFirebaseMessagingService.java

/**
 * Determine if application with package name targetPackage is installed
 *
 * @param targetPackage Package name of application
 * @return true iff application with package name is installed.
 *///w  w w .ja v  a 2  s .  c om
public boolean isInstalledPackage(String targetPackage) {
    PackageManager pm = getPackageManager();
    try {
        pm.getPackageInfo(targetPackage, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException exception) {
        return false;
    }

    return true;
}

From source file:de.arcus.framework.activities.CrashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_crash);

    // Reads the crash information
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        if (bundle.containsKey(EXTRA_FLAG_CRASH_MESSAGE))
            mCrashMessage = bundle.getString(EXTRA_FLAG_CRASH_MESSAGE);
        if (bundle.containsKey(EXTRA_FLAG_CRASH_LOG))
            mCrashLog = bundle.getString(EXTRA_FLAG_CRASH_LOG);
    } else {/*from  ww  w.ja v a  2  s.c  o  m*/
        // No information; close activity
        finish();
        return;
    }

    try {
        // Get the PackageManager to load information about the app
        PackageManager packageManager = getPackageManager();
        // Loads the ApplicationInfo with meta data
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);

        if (applicationInfo.metaData != null) {
            // Reads the crash handler settings from meta data
            if (applicationInfo.metaData.containsKey("crashhandler.email"))
                mMetaDataEmail = applicationInfo.metaData.getString("crashhandler.email");
            if (applicationInfo.metaData.containsKey("crashhandler.supporturl"))
                mMetaDataSupportURL = applicationInfo.metaData.getString("crashhandler.supporturl");
        }

        // Gets the app name
        mAppName = packageManager.getApplicationLabel(applicationInfo).toString();
        // Gets the launch intent for the restart
        mLaunchIntent = packageManager.getLaunchIntentForPackage(getPackageName());

    } catch (PackageManager.NameNotFoundException ex) {
        // If this occurs then god must be already dead
        Logger.getInstance().logError("CrashHandler", ex.toString());
    }

    // Set the action bar title
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(getString(R.string.crashhandler_app_has_stopped_working, mAppName));
    }

    // Set the message
    TextView textViewMessage = (TextView) findViewById(R.id.text_view_crash_message);
    if (textViewMessage != null) {
        textViewMessage.setText(mCrashLog);
    }
}

From source file:io.lqd.sdk.gcm.LQMessageHandler.java

private static int getAppIconInt(Context context) {
    PackageManager manager = context.getPackageManager();
    try {// w  ww .j ava  2 s . c  o  m
        ApplicationInfo appinfo = manager.getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);

        Bundle b = appinfo.metaData;
        if (b != null && b.getInt("io.lqd.sdk.notification_icon", 0) > 0)
            return b.getInt("io.lqd.sdk.notification_icon");

        return appinfo.icon;
    } catch (PackageManager.NameNotFoundException e) {
        return android.R.drawable.sym_def_app_icon;
    }
}