Example usage for android.content.pm PackageManager getText

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

Introduction

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

Prototype

public abstract CharSequence getText(String packageName, @StringRes int resid, ApplicationInfo appInfo);

Source Link

Document

Retrieve text from a package.

Usage

From source file:org.droid2droid.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.main_fragment_menu, menu);

    // Share menu
    try {/*from   ww w  . j  a va 2s. c o  m*/
        MenuItem item = menu.findItem(R.id.share);

        PackageManager pm = getPackageManager();
        ApplicationInfo info = pm.getApplicationInfo(getPackageName(), 0);

        Intent shareIntent = new Intent(Intent.ACTION_SEND)
                .putExtra(Intent.EXTRA_SUBJECT, pm.getText(getPackageName(), info.labelRes, info))
                .putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(info.sourceDir)))
                //             .setType("application/vnd.android.package-archive");
                .setType("*/*") // Android >3.x refuse to download apk
        //             .setType("image/jpeg")
        ;
        ShareActionProvider shareActionProvider = (ShareActionProvider) item.getActionProvider();
        shareActionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
        shareActionProvider.setShareIntent(shareIntent);
    } catch (NameNotFoundException e) {
        // Ignore
        if (E)
            Log.e(TAG_INSTALL, "Impossible to share RemoteAndroid");
    }
    return true;
}