Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

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

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        switch (item.getItemId()) {
        case R.id.call_button:
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse("tel:" + contact));
            startActivity(intent);/*from w  w w .  j  a  va  2 s. com*/
            return true;
        case R.id.delete_button:
            Conversation conversation = database.getConversation(preferences.getDid(), contact);
            if (conversation.getMessages().length == 0) {
                NavUtils.navigateUpFromSameTask(this);
            } else {
                List<Long> databaseIds = new ArrayList<>();
                for (int i = 0; i < adapter.getItemCount(); i++) {
                    if (adapter.getItem(i).getDatabaseId() != null) {
                        databaseIds.add(adapter.getItem(i).getDatabaseId());
                    }
                }

                Long[] databaseIdsArray = new Long[databaseIds.size()];
                databaseIds.toArray(databaseIdsArray);
                deleteMessages(databaseIdsArray);
            }
            return true;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.beesham.popularmovies.DetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_details_view, container, false);
    ButterKnife.bind(this, rootView);

    mTrailerList = new ArrayList();
    mReviewsList = new ArrayList();

    mReviewAdapter = new ReviewAdapter(getActivity(), mReviewsList);
    reviewsListView.setAdapter(mReviewAdapter);
    reviewsListView.setEmptyView(emptyReviewsTextView);

    mTrailersAdapter = new TrailersAdapter(getActivity(), mTrailerList);
    trailersListView.setAdapter(mTrailersAdapter);
    trailersListView.setEmptyView(emptyTrailersTextView);
    trailersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from ww w  .jav a  2s.c  o m
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);

            String movieBaseYoutubeUrl = getString(R.string.movies_base_youtube_url,
                    ((Trailer) mTrailerList.get(i)).getTrailerKey());

            intent.setData(Uri.parse(movieBaseYoutubeUrl));
            if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                startActivity(intent);
            }
        }
    });

    favoriteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (checkForFavorite()) {
                removeFavorite();
                favoriteButton.setText(R.string.mark_favorite);
            } else {
                insertFavoriteMovie();
                favoriteButton.setText(R.string.mark_unfavorite);
            }
        }
    });

    Bundle args = getArguments();
    if (args != null) {
        mUri = args.getParcelable(DetailsFragment.DETAIL_URI);
    }

    if (savedInstanceState != null && args.containsKey(DetailsFragment.DETAIL_URI)) {
        mUri = args.getParcelable(DetailsFragment.DETAIL_URI);
    }

    return rootView;
}

From source file:com.zxing.qrcode.decoding.CaptureActivityHandler.java

@Override
public void handleMessage(Message message) {
    switch (message.what) {
    case R.id.auto_focus:
        // Log.d(TAG, "Got auto-focus message");
        // When one auto focus pass finishes, start another. This is the
        // closest thing to
        // continuous AF. It does seem to hunt a bit, but I'm not sure what
        // else to do.
        if (state == State.PREVIEW) {
            CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
        }/*from  ww w  . j  a  va  2s  . c o m*/
        break;
    case R.id.restart_preview:
        Log.d(TAG, "Got restart preview message");
        restartPreviewAndDecode();
        break;
    case R.id.decode_succeeded:
        Log.d(TAG, "Got decode succeeded message");
        state = State.SUCCESS;
        Bundle bundle = message.getData();
        Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);
        final String str_result = ((Result) message.obj).getText();
        System.out.println("====str_result====" + str_result);
        String match = "^[0-9]{13}";
        boolean b = str_result.matches(match);
        // Toast.makeText(activity, ""+b, 1).show();
        // activity.handleDecode((Result) message.obj, barcode);
        if (b) {
            String url = RequestUrls.TIAOXING_CODE_URL.replace("[code]", str_result);
            FinalHttp fh = new FinalHttp();
            fh.get(url, new AjaxCallBack<Object>() {
                @Override
                public void onSuccess(Object t) {
                    // TODO Auto-generated method stub
                    super.onSuccess(t);
                    try {

                        System.out.println("===TIAOXING_CODE_URL====" + new JSONObject(t.toString()));
                        Intent tagIntent = new Intent(activity, TagdetialActivity.class);
                        tagIntent.putExtra("jsonStr", t.toString());
                        tagIntent.putExtra("barcodes", str_result);
                        tagIntent.putExtra("eid", eid);
                        tagIntent.putExtra("tag_ids", tag_ids);
                        activity.startActivity(tagIntent);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(Throwable t, String strMsg) {
                    // TODO Auto-generated method stub
                    super.onFailure(t, strMsg);
                }
            });
        } else {
            try {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                // //// intent.setPackage("com.tencent.mm");//
                intent.putExtra(Intent.EXTRA_SUBJECT, "share");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                // // 
                // intent.setData(Uri.parse("http://weixin.qq.com/r/o3w_sRvEMSVOhwrSnyCH"));
                intent.setData(Uri.parse(str_result));
                activity.startActivity(intent);
            } catch (Exception e) {
                Toast.makeText(activity, R.string.no_wechat_rem, Toast.LENGTH_SHORT).show();
            }
        }

        break;
    case R.id.decode_failed:
        // We're decoding as fast as possible, so when one decode fails,
        // start another.
        state = State.PREVIEW;
        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
        break;
    case R.id.return_scan_result:
        Log.d(TAG, "Got return scan result message");
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
        break;
    }
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

private void Sendsms() {
    TextView title = (TextView) findViewById(R.id.title);
    String sTitle = title.getText().toString();
    String smstext = "" + Html.fromHtml("<h2>" + "NewSum app : " + sTitle + "</h2><br>" + sText);

    // track the sendSms Action
    if (getAnalyticsPref()) {
        EasyTracker.getTracker().sendEvent(SHARING_ACTION, "Send SMS", title.getText().toString(), 0l);
    }/*from  ww  w.j  a  v a  2s  .  c o  m*/
    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.setData(Uri.parse("sms:"));
    sendIntent.putExtra("sms_body", smstext);
    startActivity(sendIntent);

}

From source file:com.ibuildapp.romanblack.MultiContactsPlugin.ContactDetailsActivity.java

/**
 * Opens a contact detial pare depending on contact type.
 *
 * @param position contact position//from  w  w w  .j a va2  s.  c  o  m
 */
private void listViewItemClick(int position) {
    try {//ErrorLogging

        int type = neededContacts.get(position).getType();
        switch (type) {
        case 0: {
        }
            break;
        case 1: {
            final String phoneNumber = neededContacts.get(position).getDescription();

            new CallDialog(this, phoneNumber, new CallDialog.ActionListener() {
                @Override
                public void onCall(DialogInterface dialog) {
                    dialog.dismiss();
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:" + phoneNumber));
                    startActivity(callIntent);
                    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
                }

                @Override
                public void onAddContact(DialogInterface dialog) {
                    createNewContact(person.getName(), person.getPhone(), person.getEmail());
                    dialog.dismiss();
                }

                @Override
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                }
            }).show();
        }
            break;
        case 2: {
            String email = neededContacts.get(position).getDescription();
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/html");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { email });
            startActivity(emailIntent);
            overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
        }
            break;
        case 3: {
            String url = neededContacts.get(position).getDescription();

            if (!url.startsWith("http://") && !url.startsWith("https://")) {
                url = "http://" + url;
            }

            Intent intent = new Intent(this, ContactsWebActivity.class);
            intent.putExtra("link", url);
            startActivity(intent);
            overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
        }
            break;
        case 4: {
            Intent intent = new Intent(this, NativeMapActivity.class);
            intent.putExtra("person", person);
            startActivity(intent);
            overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);
        }
            break;
        }

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openintents.updatechecker.UpdateChecker.java

public void parseVeeCheck(String uri) {
    VeecheckResult result = null;//from  w  w w  .j a  v a2  s. c o  m
    try {
        VeecheckVersion version = new VeecheckVersion(mPackageName, String.valueOf(mCurrentVersion),
                mCurrentVersionName);
        try {
            result = performRequest(version, uri);
        } catch (Exception e) {
            Log.v(LOG_TAG, "Failed to process versions.", e);
            return;
        } finally {
        }

        if (result.matched) {
            Log.d(LOG_TAG, "Matching intent found.");
            if (result.latestVersion.getVersionCode() != null) {
                try {
                    mLatestVersion = Integer.parseInt(result.latestVersion.getVersionCode());
                } catch (NumberFormatException e) {
                    mLatestVersion = 0;
                }
            } else {
                mLatestVersion = 0;
            }
            mLatestVersionName = result.latestVersion.getVersionName();
            mComment = null;

            // create intent
            Intent intent = new Intent();
            if (Intent.ACTION_VIEW.equals(result.action)) {
                intent.setAction(result.action);
                if (result.data != null) {
                    Uri intentUri = Uri.parse(result.data);
                    if (result.type != null) {
                        intent.setDataAndType(intentUri, result.type);
                    } else {
                        intent.setData(intentUri);
                    }
                } else {
                    if (result.type != null) {
                        intent.setType(result.type);
                    }
                }

                if (result.extras != null) {
                    for (Entry<String, String> e : result.extras.entrySet()) {
                        intent.putExtra(e.getKey(), e.getValue());
                    }
                }
                ResolveInfo info = mContext.getPackageManager().resolveActivity(intent, 0);
                if (info != null) {
                    mUpdateIntent = intent;
                }
            } else {
                Log.v(TAG, "no view action but " + result.action);
            }

        } else {
            result = null;
            Log.d(LOG_TAG, "No matching intent found.");
        }

    } finally {

    }
}

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

/**
 * Gets the video intent./*from   w  w w. ja v  a2  s.  com*/
 *
 * @return the video intent
 * @author RayBa
 * @date 07.04.2013
 */
private Intent getVideoIntent() {
    String videoUrl = null;
    String videoType = null;
    switch (mStreamType) {
    case STREAM_TYPE_DIRECT:
        switch (mFileType) {
        case FILE_TYPE_LIVE:
            videoUrl = liveUrl + mFileId + ".ts";
            break;
        case FILE_TYPE_RECORDING:
            videoUrl = mediaUrl + mFileId + ".ts";
            break;

        default:
            break;
        }
        videoType = "video/*";

        break;
    case STREAM_TYPE_TRANSCODE:
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Preset", String.valueOf(qualitySpinner.getSelectedItemPosition())));
        params.add(new BasicNameValuePair("aspect", aspectSpinner.getSelectedItem().toString()));
        params.add(new BasicNameValuePair("ffPreset", ffmpegSpinner.getSelectedItem().toString()));

        /**
         * Check if height is set from user, otherwise the the default values are used
         */
        if (widthSpinner.getSelectedItemPosition() > 0) {
            params.add(new BasicNameValuePair("maxwidth", widthSpinner.getSelectedItem().toString()));
        }
        if (heightSpinner.getSelectedItemPosition() > 0) {
            params.add(new BasicNameValuePair("maxheight", heightSpinner.getSelectedItem().toString()));
        }

        /**
         * Calculate startposition in seconds
         */
        int hours = TextUtils.isEmpty(startHours.getText()) ? 0
                : Integer.valueOf(startHours.getText().toString());
        int minutes = TextUtils.isEmpty(startMinutes.getText()) ? 0
                : Integer.valueOf(startMinutes.getText().toString());
        int seconds = TextUtils.isEmpty(startSeconds.getText()) ? 0
                : Integer.valueOf(startSeconds.getText().toString());
        int start = 3600 * hours + 60 * minutes + seconds;
        params.add(new BasicNameValuePair("start", String.valueOf(start)));

        switch (mFileType) {
        case FILE_TYPE_LIVE:
            params.add(new BasicNameValuePair("chid", String.valueOf(mFileId)));
            break;
        case FILE_TYPE_RECORDING:
            params.add(new BasicNameValuePair("recid", String.valueOf(mFileId)));
            break;

        default:
            break;
        }
        String query = URLEncodedUtils.format(params, "utf-8");
        videoUrl = flashUrl + query;
        break;

    default:
        break;
    }
    Log.i(StreamConfig.class.getSimpleName(), "url: " + videoUrl);

    DVBViewerPreferences prefs = new DVBViewerPreferences(getActivity());
    boolean external = prefs.getPrefs().getBoolean(DVBViewerPreferences.KEY_STREAM_EXTERNAL_PLAYER, true);
    Intent videoIntent;
    if (external) {
        videoType = "video/mpeg";
        videoIntent = new Intent(Intent.ACTION_VIEW);
        videoIntent.setDataAndType(Uri.parse(videoUrl), videoType);
    } else {
        videoIntent = new Intent(getActivity(), VideoPlayerActivity.class);
        videoIntent.setData(Uri.parse(videoUrl));
    }
    return videoIntent;
}

From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java

private RemoteViews makeErrorView(final int appWidgetId) {
    final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(),
            R.layout.appwidget_error);/*from w ww  .j  a va 2 s.  c  om*/

    // 6. Activity launcher.
    final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class);
    resultIntent.putExtra("actionFromUser", true);
    resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget
    final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId));
    resultIntent.setData(data);

    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(WidgetConfigure.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteView.setOnClickPendingIntent(R.id.weather_appwidget_error, resultPendingIntent);

    return remoteView;
}

From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java

public void showAppSettings() {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(Uri.parse("package:" + getContext().getPackageName()));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    getContext().startActivity(intent);/*from  www  .j av a2 s.com*/
}