Example usage for android.content Intent putParcelableArrayListExtra

List of usage examples for android.content Intent putParcelableArrayListExtra

Introduction

In this page you can find the example usage for android.content Intent putParcelableArrayListExtra.

Prototype

public @NonNull Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value) 

Source Link

Document

Add extended data to the intent.

Usage

From source file:org.dvbviewer.controller.ui.fragments.ChannelList.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (mCHannelSelectedListener != null) {
        selectedPosition = position;//from   w  w w . jav a2s.com
        Cursor c = mAdapter.getCursor();
        c.moveToPosition(position);
        Channel chan = cursorToChannel(c);
        ArrayList<Channel> chans = cursorToChannellist(position);
        mCHannelSelectedListener.channelSelected(chans, chan, position);
        getListView().setItemChecked(position, true);
    } else {
        Intent epgPagerIntent = new Intent(getActivity(),
                org.dvbviewer.controller.ui.phone.EpgPagerActivity.class);
        // long[] feedIds = new long[data.getCount()];

        ArrayList<Channel> chans = cursorToChannellist(position);

        epgPagerIntent.putParcelableArrayListExtra(Channel.class.getName(), chans);
        epgPagerIntent.putExtra("position", position);
        startActivity(epgPagerIntent);
        selectedPosition = ListView.INVALID_POSITION;
    }
}

From source file:com.krayzk9s.imgurholo.activities.MainActivity.java

private void processIntent(Intent intent) {
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();/*from w ww.j  av a2  s .  c  o  m*/
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("imgur-holo")) {
        Uri uri = intent.getData();
        Log.d("URI", "" + action + "/" + type);
        String uripath = "";
        if (uri != null)
            uripath = uri.toString();
        Log.d("URI", uripath);
        Log.d("URI", "HERE");

        if (uri != null && uripath.startsWith(ApiCall.OAUTH_CALLBACK_URL)) {
            apiCall.verifier = new Verifier(uri.getQueryParameter("code"));
            CallbackAsync callbackAsync = new CallbackAsync(apiCall, this);
            callbackAsync.execute();
        }
    } else if (getSupportFragmentManager().getFragments() == null) {
        loadDefaultPage();
    }
}

From source file:com.android.contacts.ContactSaveService.java

/**
 * Creates an intent that can be sent to this service to create a new raw contact
 * using data presented as a set of ContentValues.
 *//*from   ww  w.j a  v a  2 s .co  m*/
public static Intent createNewRawContactIntent(Context context, ArrayList<ContentValues> values,
        AccountWithDataSet account, Class<? extends Activity> callbackActivity, String callbackAction) {
    Intent serviceIntent = new Intent(context, ContactSaveService.class);
    serviceIntent.setAction(ContactSaveService.ACTION_NEW_RAW_CONTACT);
    if (account != null) {
        serviceIntent.putExtra(ContactSaveService.EXTRA_ACCOUNT_NAME, account.name);
        serviceIntent.putExtra(ContactSaveService.EXTRA_ACCOUNT_TYPE, account.type);
        serviceIntent.putExtra(ContactSaveService.EXTRA_DATA_SET, account.dataSet);
    }
    serviceIntent.putParcelableArrayListExtra(ContactSaveService.EXTRA_CONTENT_VALUES, values);

    // Callback intent will be invoked by the service once the new contact is
    // created.  The service will put the URI of the new contact as "data" on
    // the callback intent.
    Intent callbackIntent = new Intent(context, callbackActivity);
    callbackIntent.setAction(callbackAction);
    serviceIntent.putExtra(ContactSaveService.EXTRA_CALLBACK_INTENT, callbackIntent);
    return serviceIntent;
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static boolean sendEmail(final Context ctx, final String to, final String subject, final String body,
        final String[] attachment, final String authorities) {
    try {/*www  .ja v a  2 s  . com*/
        final String[] recipients = new String[] { to };

        final Intent intent = new Intent(
                attachment.length > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SENDTO);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, recipients);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, body);

        boolean grant_permissions_workaround = false;
        final ArrayList<Uri> uri = new ArrayList<>();
        if (attachment.length > 0) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                for (final String fileName : attachment) {
                    uri.add(Uri.fromFile(new File(fileName)));
                }
            } else {
                // Android 6+: going the longer route.
                // For more information, please see:
                // http://stackoverflow.com/questions/32981194/android-6-cannot-share-files-anymore
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                grant_permissions_workaround = true;
                for (final String fileName : attachment) {
                    uri.add(FileProvider.getUriForFile(ctx, authorities, new File(fileName)));
                }
            }
            // Should not put array with only one element into intent because of a bug in GMail.
            if (uri.size() == 1) {
                intent.putExtra(Intent.EXTRA_STREAM, uri.get(0));
            } else {
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uri);
            }
        }

        final IntentResolverInfo mailtoIntentResolvers = new IntentResolverInfo(ctx.getPackageManager());
        mailtoIntentResolvers
                .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", to, null)));

        final Intent chooserIntent;

        if (mailtoIntentResolvers.isEmpty()) {
            chooserIntent = Intent.createChooser(intent, null);
        } else {
            final IntentResolverInfo messageIntentResolvers = new IntentResolverInfo(ctx.getPackageManager());
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("sms", "", null)));
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mms", "", null)));
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("tel", "", null)));

            mailtoIntentResolvers.removeSamePackages(messageIntentResolvers.getResolveInfos());

            final List<Intent> intentList = new ArrayList<>();

            for (final ActivityInfo activityInfo : mailtoIntentResolvers.getResolveInfos()) {
                final String packageName = activityInfo.getPackageName();
                final String name = activityInfo.getName();

                // Some mail clients will not read the URI unless this is done.
                // See here: https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial
                if (grant_permissions_workaround) {
                    for (int i = 0; i < uri.size(); ++i) {
                        try {
                            ctx.grantUriPermission(packageName, uri.get(i),
                                    Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        } catch (final Throwable e) {
                            Log.e(TAG, "grantUriPermission error: ", e);
                        }
                    }
                }

                final Intent cloneIntent = (Intent) intent.clone();
                cloneIntent.setComponent(new ComponentName(packageName, name));
                intentList.add(cloneIntent);
            }

            final Intent targetIntent = intentList.get(0);
            intentList.remove(0);

            chooserIntent = Intent.createChooser(targetIntent, null);
            if (!intentList.isEmpty()) {
                final Intent[] extraIntents = intentList.toArray(new Intent[intentList.size()]);
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
                } else {
                    chooserIntent.putExtra(Intent.EXTRA_ALTERNATE_INTENTS, extraIntents);
                }
            }
        }

        chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        ctx.startActivity(chooserIntent);

        return true;
    } catch (final Throwable exception) {
        Log.e(TAG, "sendEmail exception: ", exception);
        return false;
    }
}

From source file:com.asksven.betterbatterystats.StatsActivity.java

public Dialog getShareDialog() {

    final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>();

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean saveDumpfile = sharedPrefs.getBoolean("save_dumpfile", true);
    boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false);
    boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false);

    if (saveDumpfile) {
        selectedSaveActions.add(0);//from w ww .j  a  v  a 2s  .  c  om
    }
    if (saveLogcat) {
        selectedSaveActions.add(1);
    }
    if (saveDmesg) {
        selectedSaveActions.add(2);
    }

    //----
    LinearLayout layout = new LinearLayout(this);
    LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(parms);

    layout.setGravity(Gravity.CLIP_VERTICAL);
    layout.setPadding(2, 2, 2, 2);

    final TextView editTitle = new TextView(StatsActivity.this);
    editTitle.setText(R.string.share_dialog_edit_title);
    editTitle.setPadding(40, 40, 40, 40);
    editTitle.setGravity(Gravity.LEFT);
    editTitle.setTextSize(20);

    final EditText editDescription = new EditText(StatsActivity.this);

    LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    tv1Params.bottomMargin = 5;
    layout.addView(editTitle, tv1Params);
    layout.addView(editDescription, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    //----

    // Set the dialog title
    builder.setTitle(R.string.title_share_dialog)
            .setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveDumpfile, saveLogcat, saveDmesg },
                    new DialogInterface.OnMultiChoiceClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                            if (isChecked) {
                                // If the user checked the item, add it to the
                                // selected items
                                selectedSaveActions.add(which);
                            } else if (selectedSaveActions.contains(which)) {
                                // Else, if the item is already in the array,
                                // remove it
                                selectedSaveActions.remove(Integer.valueOf(which));
                            }
                        }
                    })
            .setView(layout)
            // Set the action buttons
            .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    ArrayList<Uri> attachements = new ArrayList<Uri>();

                    Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName,
                            StatsActivity.this);
                    Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName,
                            StatsActivity.this);

                    Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);

                    // save as text is selected
                    if (selectedSaveActions.contains(0)) {
                        attachements.add(reading.writeDumpfile(StatsActivity.this,
                                editDescription.getText().toString()));
                    }
                    // save logcat if selected
                    if (selectedSaveActions.contains(1)) {
                        attachements.add(StatsProvider.getInstance().writeLogcatToFile());
                    }
                    // save dmesg if selected
                    if (selectedSaveActions.contains(2)) {
                        attachements.add(StatsProvider.getInstance().writeDmesgToFile());
                    }

                    if (!attachements.isEmpty()) {
                        Intent shareIntent = new Intent();
                        shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
                        shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements);
                        shareIntent.setType("text/*");
                        startActivity(Intent.createChooser(shareIntent, "Share info to.."));
                    }
                }
            }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {

                    try {
                        Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName,
                                StatsActivity.this);
                        Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName,
                                StatsActivity.this);

                        Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);

                        // save as text is selected
                        if (selectedSaveActions.contains(0)) {
                            reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString());
                        }
                        // save logcat if selected
                        if (selectedSaveActions.contains(1)) {
                            StatsProvider.getInstance().writeLogcatToFile();
                        }
                        // save dmesg if selected
                        if (selectedSaveActions.contains(2)) {
                            StatsProvider.getInstance().writeDmesgToFile();
                        }

                        Snackbar.make(findViewById(android.R.id.content), getString(R.string.info_files_written)
                                + ": " + StatsProvider.getWritableFilePath(), Snackbar.LENGTH_LONG).show();
                    } catch (Exception e) {
                        Log.e(TAG, "an error occured writing files: " + e.getMessage());
                        Snackbar.make(findViewById(android.R.id.content), R.string.info_files_write_error,
                                Snackbar.LENGTH_LONG).show();
                    }

                }
            }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    // do nothing
                }
            });

    return builder.create();
}

From source file:com.android.mms.rcs.FavoriteDetailAdapter.java

private static void mergeVcardDetail(Context context, ArrayList<PropertyNode> propList) {
    Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(Contacts.CONTENT_ITEM_TYPE);
    ArrayList<ContentValues> phoneValue = new ArrayList<ContentValues>();
    for (PropertyNode propertyNode : propList) {
        if ("FN".equals(propertyNode.propName)) {
            if (!TextUtils.isEmpty(propertyNode.propValue)) {
                intent.putExtra(ContactsContract.Intents.Insert.NAME, propertyNode.propValue);
            }//  w ww .  j a  v a 2 s. c o  m
        } else if ("TEL".equals(propertyNode.propName)) {
            if (!TextUtils.isEmpty(propertyNode.propValue)) {
                ContentValues value = new ContentValues();
                value.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
                value.put(Phone.TYPE, RcsUtils.getVcardNumberType(propertyNode));
                value.put(Phone.NUMBER, propertyNode.propValue);
                phoneValue.add(value);
            }
        } else if ("ADR".equals(propertyNode.propName)) {
            if (!TextUtils.isEmpty(propertyNode.propValue)) {
                intent.putExtra(ContactsContract.Intents.Insert.POSTAL, propertyNode.propValue);
                intent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE,
                        ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
            }
        } else if ("ORG".equals(propertyNode.propName)) {
            if (!TextUtils.isEmpty(propertyNode.propValue)) {
                intent.putExtra(ContactsContract.Intents.Insert.COMPANY, propertyNode.propValue);
            }
        } else if ("TITLE".equals(propertyNode.propName)) {
            if (!TextUtils.isEmpty(propertyNode.propValue)) {
                intent.putExtra(ContactsContract.Intents.Insert.JOB_TITLE, propertyNode.propValue);
            }
        }
    }
    if (phoneValue.size() > 0) {
        intent.putParcelableArrayListExtra(Insert.DATA, phoneValue);
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    context.startActivity(intent);
}

From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.cellscanner.CellScanner.java

public void start(final ActiveOrPassiveStumbling stumblingMode) {
    if (!mSimpleCellScanner.isSupportedOnThisDevice()) {
        return;// ww w .j a v a2  s .co  m
    }

    if (mCellScanTimer != null) {
        return;
    }

    LocalBroadcastManager.getInstance(mAppContext).registerReceiver(mReportFlushedReceiver,
            new IntentFilter(Reporter.ACTION_NEW_BUNDLE));

    // This is to ensure the broadcast happens from the same thread the CellScanner start() is on
    mBroadcastScannedHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            Intent intent = (Intent) msg.obj;
            LocalBroadcastManager.getInstance(mAppContext).sendBroadcastSync(intent);
        }
    };

    mSimpleCellScanner.start();

    mCellScanTimer = new Timer();

    mCellScanTimer.schedule(new TimerTask() {
        int mPassiveScanCount;

        @Override
        public void run() {
            if (!mSimpleCellScanner.isStarted()) {
                return;
            }

            if (stumblingMode == ActiveOrPassiveStumbling.PASSIVE_STUMBLING
                    && mPassiveScanCount++ > AppGlobals.PASSIVE_MODE_MAX_SCANS_PER_GPS) {
                mPassiveScanCount = 0;
                stop();
                return;
            }

            final long curTime = System.currentTimeMillis();
            ArrayList<CellInfo> cells = new ArrayList<CellInfo>(mSimpleCellScanner.getCellInfo());

            if (mReportWasFlushed.getAndSet(false)) {
                clearCells();
            }

            if (cells.isEmpty()) {
                return;
            }

            for (CellInfo cell : cells) {
                addToCells(cell.getCellIdentity());
            }

            Intent intent = new Intent(ACTION_CELLS_SCANNED);
            intent.putParcelableArrayListExtra(ACTION_CELLS_SCANNED_ARG_CELLS, cells);
            intent.putExtra(ACTION_CELLS_SCANNED_ARG_TIME, curTime);
            // send to handler, so broadcast is not from timer thread
            Message message = new Message();
            message.obj = intent;
            mBroadcastScannedHandler.sendMessage(message);
        }
    }, 0, CELL_MIN_UPDATE_TIME);
}

From source file:com.nexes.manager.EventHandler.java

/**
 * This method, handles the button presses of the top buttons found in the
 * Main activity./*from  ww w  .  j a v  a  2 s. c o  m*/
 */
@Override
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.back_button:
        if (mFileMang.getCurrentDir() != "/") {
            if (multi_select_flag) {
                mDelegate.killMultiSelect(true);
                Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show();
            }

            stopThumbnailThread();
            updateDirectory(mFileMang.getPreviousDir());
            if (mPathLabel != null)
                mPathLabel.setText(mFileMang.getCurrentDir());
        }
        break;

    case R.id.home_button:
        if (multi_select_flag) {
            mDelegate.killMultiSelect(true);
            Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show();
        }

        stopThumbnailThread();
        updateDirectory(mFileMang.setHomeDir("/sdcard"));
        if (mPathLabel != null)
            mPathLabel.setText(mFileMang.getCurrentDir());
        break;

    case R.id.info_button:
        Intent info = new Intent(mContext, DirectoryInfo.class);
        info.putExtra("PATH_NAME", mFileMang.getCurrentDir());
        mContext.startActivity(info);
        break;

    case R.id.help_button:
        Intent help = new Intent(mContext, HelpManager.class);
        mContext.startActivity(help);
        break;

    case R.id.manage_button:
        display_dialog(MANAGE_DIALOG);
        break;

    case R.id.multiselect_button:
        if (multi_select_flag) {
            mDelegate.killMultiSelect(true);

        } else {
            LinearLayout hidden_lay = (LinearLayout) ((Activity) mContext).findViewById(R.id.hidden_buttons);

            multi_select_flag = true;
            hidden_lay.setVisibility(LinearLayout.VISIBLE);
        }
        break;

    /*
     * three hidden buttons for multiselect
     */
    case R.id.hidden_attach:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        ArrayList<Uri> uris = new ArrayList<Uri>();
        int length = mMultiSelectData.size();
        Intent mail_int = new Intent();

        mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
        mail_int.setType("application/mail");
        mail_int.putExtra(Intent.EXTRA_BCC, "");
        mail_int.putExtra(Intent.EXTRA_SUBJECT, " ");

        for (int i = 0; i < length; i++) {
            File file = new File(mMultiSelectData.get(i));
            uris.add(Uri.fromFile(file));
        }

        mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        mContext.startActivity(Intent.createChooser(mail_int, "Email using..."));

        mDelegate.killMultiSelect(true);
        break;

    case R.id.hidden_move:
    case R.id.hidden_copy:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        if (v.getId() == R.id.hidden_move)
            delete_after_copy = true;

        mInfoLabel.setText("Holding " + mMultiSelectData.size() + " file(s)");

        mDelegate.killMultiSelect(false);
        break;

    case R.id.hidden_delete:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        final String[] data = new String[mMultiSelectData.size()];
        int at = 0;

        for (String string : mMultiSelectData)
            data[at++] = string;

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(
                "Are you sure you want to delete " + data.length + " files? This cannot be " + "undone.");
        builder.setCancelable(false);
        builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                new BackgroundWork(DELETE_TYPE).execute(data);
                mDelegate.killMultiSelect(true);
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mDelegate.killMultiSelect(true);
                dialog.cancel();
            }
        });

        builder.create().show();
        break;
    }
}

From source file:it.geosolutions.geocollect.android.map.GeoCollectMapActivity.java

/**
 * add the confirm button to the control bar
 *//*www  .j  a v a 2  s.c om*/
private void addConfirmButton() {
    Log.v(TAG, "adding confirm button");
    ImageButton b = (ImageButton) findViewById(R.id.button_confirm_marker_position);
    b.setVisibility(View.VISIBLE);
    final MapActivityBase activity = this;
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (!canConfirm) {
                Toast.makeText(activity, R.string.error_unable_getfeature_db, Toast.LENGTH_LONG).show();
                return;
            }

            new AlertDialog.Builder(activity).setTitle(R.string.button_confirm_marker_position_title)
                    .setMessage(R.string.button_confirm_marker_position)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Intent returnIntent = new Intent();
                            // get current markers
                            ArrayList<DescribedMarker> markers = overlayManager.getMarkerOverlay().getMarkers();
                            // serialize markers in the response
                            returnIntent.putParcelableArrayListExtra(MapsActivity.PARAMETERS.MARKERS,
                                    MarkerUtils.getMarkersDTO(markers));
                            setResult(RESULT_OK, returnIntent);
                            finish();
                            return;
                            // if you don't want to return data:
                            // setResult(RESULT_CANCELED, returnIntent);
                            // finish();
                            // activity.finish();
                        }

                    }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // do nothing
                        }
                    }).show();

        }
    });
}

From source file:cx.ring.model.CallContact.java

public Intent getAddNumberIntent() {
    final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);

    ArrayList<ContentValues> data = new ArrayList<>();
    ContentValues values = new ContentValues();

    SipUri number = getPhones().get(0).getNumber();
    if (number.isRingId()) {
        values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
        values.put(ContactsContract.CommonDataKinds.Im.DATA, number.getRawUriString());
        values.put(ContactsContract.CommonDataKinds.Im.PROTOCOL,
                ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM);
        values.put(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL, "Ring");
    } else {/*from  w  w w  .  ja va  2  s.c o m*/
        values.put(ContactsContract.Data.MIMETYPE,
                ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE);
        values.put(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, number.getRawUriString());
    }
    data.add(values);
    intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);
    return intent;
}