Example usage for android.content.pm LabeledIntent putExtra

List of usage examples for android.content.pm LabeledIntent putExtra

Introduction

In this page you can find the example usage for android.content.pm LabeledIntent putExtra.

Prototype

public @NonNull Intent putExtra(String name, boolean value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:com.swisscom.safeconnect.activity.DashboardActivity.java

private void share() {
    final String appUrl = Config.GPLAY_URL;
    final String content = getString(R.string.share_content);
    final String subject = getString(R.string.share_subject);

    List<Intent> shareIntents = new ArrayList<Intent>();
    //fb & twitter
    shareIntents.add(new FacebookSharing(this).getIntent(content, appUrl));
    shareIntents.add(new TwitterSharing(this).getIntent(content, appUrl));

    //favorite sharing apps
    for (String packageName : Sharing.favoriteApps) {
        Intent i = Sharing.getSharingApp(packageName, subject, content + ' ' + appUrl, this);
        if (i != null) {
            shareIntents.add(i);/*from   ww w.  j a v  a2s  .c o  m*/
        }
    }

    //trigger to load all sharing apps
    LabeledIntent share = new LabeledIntent(new Intent(), "", getString(R.string.share_more_apps), 0);
    share.putExtra("more", true);
    shareIntents.add(share);

    AlertDialog.Builder builder = new AlertDialog.Builder(DashboardActivity.this,
            R.style.AppCompat_Pipe_Dialog_Alert);
    builder.setTitle(R.string.share_with);
    final SharingAdapter adapter = new SharingAdapter(this, R.layout.item_sharing, shareIntents);
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent i = adapter.getItem(which);

            //Trigger to load the standard android sharing dialog
            if (i.getBooleanExtra("more", false)) {
                Intent intent = Intent.createChooser(Sharing.getSharingIntent(subject, content + ' ' + appUrl),
                        getString(R.string.share_with));
                startActivity(intent);
                return;
            }

            //fix exception when launching labeled-intent
            if (i instanceof LabeledIntent) {
                i = new Intent(i);
            }
            startActivity(i);
        }
    });

    builder.show();
}