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:de.electricdynamite.pasty.ClipboardFragment.java

@Override
public void onLoadFinished(Loader<PastyLoader.PastyResponse> loader, PastyLoader.PastyResponse response) {

    ProgressBar pbLoading = (ProgressBar) getSherlockActivity().findViewById(R.id.progressbar_downloading);
    pbLoading.setVisibility(View.GONE);
    pbLoading = null;/*w  w w.j  a  va2 s  .  c  o m*/

    mHelpTextBig.setTextColor(getResources().getColor(R.color.abs__primary_text_holo_light));
    mHelpTextBig.setBackgroundDrawable(mBackground);

    if (response.isFinal) {
        getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
        if (response.getResultSource() == PastyResponse.SOURCE_CACHE) {
            Toast.makeText(getSherlockActivity().getApplicationContext(),
                    getString(R.string.warning_no_network_short), Toast.LENGTH_SHORT).show();
        }
    }
    if (response.hasException) {
        if (LOCAL_LOG)
            Log.v(TAG, "onLoadFinished(): Loader delivered exception; calling handleException()");
        // an error occured

        getSherlockActivity().setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
        PastyException mException = response.getException();
        handleException(mException);
    } else {
        switch (loader.getId()) {
        case PastyLoader.TASK_CLIPBOARD_FETCH:
            JSONArray Clipboard = response.getClipboard();
            mItems.clear();
            mAdapter.notifyDataSetChanged();
            getListView().invalidateViews();
            try {
                if (Clipboard.length() == 0) {
                    //Clipboard is empty
                    mHelpTextBig.setText(R.string.helptext_PastyActivity_clipboard_empty);
                    mHelpTextSmall.setText(R.string.helptext_PastyActivity_how_to_add);
                } else {
                    for (int i = 0; i < Clipboard.length(); i++) {
                        JSONObject Item = Clipboard.getJSONObject(i);
                        ClipboardItem cbItem = new ClipboardItem(Item.getString("_id"), Item.getString("item"));
                        this.mItems.add(cbItem);
                    }

                    mHelpTextBig.setText(R.string.helptext_PastyActivity_copy);
                    mHelpTextSmall.setText(R.string.helptext_PastyActivity_options);

                    //Assign adapter to ListView
                    ListView listView = (ListView) getSherlockActivity().findViewById(R.id.listItems);
                    listView.setAdapter(mAdapter);
                    listView.setItemsCanFocus(false);
                    listView.setOnItemClickListener(new OnItemClickListener() {
                        @SuppressLint("NewApi")
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            ClipboardItem Item = mItems.get(position); // get a ClipboardItem from the clicked position
                            if (Item.isLinkified() && prefs.getClickableLinks()) {
                                /* If the clicked item was originally linkified and prefs.getClickableLinks() is true, we manually
                                 * fire an ACTION_VIEW intent to simulate Linkify() behavior
                                 */
                                String url = Item.getText();
                                if (!URLUtil.isValidUrl(url))
                                    url = "http://" + url;
                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(url));
                                startActivity(i);
                            } else {
                                /* Else we copy the item to the systems clipboard,
                                 * show a Toast and finish() the activity
                                 */
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                    android.content.ClipboardManager sysClipboard = (android.content.ClipboardManager) getSherlockActivity()
                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                    Item.copyToClipboard(sysClipboard);
                                    sysClipboard = null;
                                } else {
                                    ClipboardManager sysClipboard = (ClipboardManager) getSherlockActivity()
                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                    Item.copyToClipboard(sysClipboard);
                                    sysClipboard = null;
                                }
                                Toast.makeText(getSherlockActivity().getApplicationContext(),
                                        getString(R.string.item_copied), Toast.LENGTH_LONG).show();
                                getSherlockActivity().finish();
                            }
                        }
                    });
                    registerForContextMenu(listView);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        default:
            break;
        }
    }
}

From source file:com.irccloud.android.activity.PastebinsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));/* w w w.jav a 2  s  .c om*/
        cloud.recycle();
    }

    setContentView(R.layout.ignorelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
        getSupportActionBar().setElevation(0);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("adapter")) {
        try {
            page = savedInstanceState.getInt("page");
            Pastebin[] pastebins = (Pastebin[]) savedInstanceState.getSerializable("adapter");
            for (Pastebin p : pastebins) {
                adapter.addPastebin(p);
            }
            adapter.notifyDataSetChanged();
        } catch (Exception e) {
            page = 0;
            adapter.clear();
        }
    }

    footer = getLayoutInflater().inflate(R.layout.messageview_header, null);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.addFooterView(footer);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) {
                canLoadMore = false;
                new FetchPastebinsTask().execute((Void) null);
            }
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            final Pastebin p = (Pastebin) adapter.getItem(i);

            Intent intent = new Intent(PastebinsActivity.this, PastebinViewerActivity.class);
            intent.setData(Uri.parse(p.url + "?id=" + p.id + "&own_paste=" + (p.own_paste ? "1" : "0")));
            startActivity(intent);
        }
    });

    Toast.makeText(this, "Tap a pastebin to view full text with syntax highlighting", Toast.LENGTH_LONG).show();
}

From source file:com.vyasware.vaani.MainActivity.java

private void doMsg(String noun) {
    System.out.println("msg");

    Cursor cur = null;/*from w  w w .  ja  v a2 s .com*/
    ContentResolver cr = null;

    try {
        cr = getContentResolver();

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        boolean called = false;
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {

                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                // Log.i("Names", name);
                if (Integer.parseInt(
                        cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                    // Query phone here. Covered next
                    Cursor phones = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
                    while (phones.moveToNext()) {
                        String phoneNumberX = phones.getString(
                                phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        // Log.i("Number", phoneNumber);
                        boolean a = (name.equalsIgnoreCase(noun));
                        System.out.println(name + "  " + a + "  " + phoneNumberX);

                        if (a)
                            System.out.println(phoneNumberX);

                        if (a) {
                            String b = "sms:";
                            String smsUri = b + phoneNumberX;
                            Intent smsIntent = new Intent(Intent.ACTION_VIEW);
                            smsIntent.setData(Uri.parse(smsUri));
                            called = true;
                            startActivity(smsIntent);
                            tts.speak(noun + "  ? !",
                                    TextToSpeech.QUEUE_FLUSH, null);

                        }

                    }
                    phones.close();

                }

            }

            if (!called)
                tts.speak(noun + "  ?    !",
                        TextToSpeech.QUEUE_FLUSH, null);

        }

    } catch (Exception ex) {
        ex.printStackTrace();

    }
}

From source file:com.appteam.nimbus.activity.homeActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override//from w ww  . j  a v  a  2s.  c  o  m
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.navigation_to_profile) {
        // Handle the camera action
        Intent i = new Intent(homeActivity.this, Profile.class);
        startActivity(i);

    } else if (id == R.id.aboutus_nav) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(String.format("%1$s", getString(R.string.app_name)));
        builder.setMessage(getResources().getText(R.string.aboutus_text));
        builder.setPositiveButton("OK", null);
        builder.setIcon(R.mipmap.nimbus16);
        AlertDialog welcomeAlert = builder.create();
        welcomeAlert.show();
        ((TextView) welcomeAlert.findViewById(android.R.id.message))
                .setMovementMethod(LinkMovementMethod.getInstance());
    } else if (id == R.id.feedback_nav) {
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        String uriText = "mailto:" + Uri.encode("appteam.nith@gmail.com") + "?subject="
                + Uri.encode("Reporting A Bug/Feedback") + "&body=" + Uri.encode(
                        "Hello, Appteam \nI want to report a bug/give feedback corresponding to the app Nimbus 2k16.\n.....\n\n-Your name");

        Uri uri = Uri.parse(uriText);
        intent.setData(uri);
        startActivity(Intent.createChooser(intent, "Send Email"));
    } else if (id == R.id.opensourcelicenses_nav) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(String.format("%1$s", getString(R.string.open_source_licenses)));
        builder.setMessage(getResources().getText(R.string.licenses_text));
        builder.setPositiveButton("OK", null);
        //builder.setIcon(R.mipmap.nimbus_icon);
        AlertDialog welcomeAlert = builder.create();
        welcomeAlert.show();
        ((TextView) welcomeAlert.findViewById(android.R.id.message))
                .setMovementMethod(LinkMovementMethod.getInstance());
    } else if (id == R.id.contributors_nav) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(String.format("%1$s", getString(R.string.contributors)));
        builder.setMessage(getResources().getText(R.string.contributors_text));
        builder.setPositiveButton("OK", null);
        //builder.setIcon(R.mipmap.nimbus_icon);
        AlertDialog welcomeAlert = builder.create();
        welcomeAlert.show();
        ((TextView) welcomeAlert.findViewById(android.R.id.message))
                .setMovementMethod(LinkMovementMethod.getInstance());
    } else if (id == R.id.notifications) {
        startActivity(new Intent(homeActivity.this, ViewActivity.class));
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:com.vyasware.vaani.MainActivity.java

private void doOpen(String[] sentence) {
    System.out.println("open");
    for (String word : sentence) {
        switch (word) {
        //? ???  
        case "?":
        case "facebook":
            //open facebook
            Intent fbintent = new Intent();
            fbintent.setAction(Intent.ACTION_VIEW);
            fbintent.setData(android.net.Uri.parse("http://www.facebook.com"));
            startActivity(fbintent);/*from w w w. j a  v a 2  s .  co m*/
            break;
        case "whatsapp":
        case "???":
            //todo run whatsapp
            break;
        case "camera":
        case "":
        case "":
            //open camera
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            try {
                PackageManager pm = getPackageManager();

                final ResolveInfo mInfo = pm.resolveActivity(i, 0);

                Intent intent = new Intent();
                intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name));
                intent.setAction(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_LAUNCHER);

                startActivity(intent);
            } catch (Exception e) {
                Log.i("open", "Unable to launch camera: " + e);
            }
            break;
        case "browser":
        case "?":
            // open browser
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(android.net.Uri.parse("http://www.google.com"));
            startActivity(intent);
            break;
        case "youtube":
        case "???":
            //run youtube
            Intent ytintent = new Intent();
            ytintent.setAction(Intent.ACTION_VIEW);
            ytintent.setData(android.net.Uri.parse("http://www.youtube.com"));
            startActivity(ytintent);
            break;

        }
    }

}

From source file:com.vyasware.vaani.MainActivity.java

private void doCall(String noun) {
    System.out.println("call");
    System.out.println(noun);//w w w .  java 2 s.c o m

    Cursor cur = null;
    ContentResolver cr = null;

    try {
        cr = getContentResolver();

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        boolean called = false;
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {

                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                // Log.i("Names", name);
                if (Integer.parseInt(
                        cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                    // Query phone here. Covered next
                    Cursor phones = getContentResolver().query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + id, null, null);
                    while (phones.moveToNext()) {
                        String phoneNumberX = phones.getString(
                                phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        // Log.i("Number", phoneNumber);
                        boolean a = (name.equalsIgnoreCase(noun));
                        System.out.println(name + "  " + a + "  " + phoneNumberX);

                        if (a)
                            System.out.println(phoneNumberX);

                        if (a) {
                            String b = "tel:";
                            String phoneCallUri = b + phoneNumberX;
                            Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
                            phoneCallIntent.setData(Uri.parse(phoneCallUri));
                            called = true;
                            startActivity(phoneCallIntent);

                        }

                    }
                    phones.close();

                }

            }

            if (!called)
                tts.speak(noun + "  ?    !",
                        TextToSpeech.QUEUE_FLUSH, null);

        }

    } catch (Exception ex) {
        ex.printStackTrace();

    }
    // tts.speak(noun + "  ?    !",TextToSpeech.QUEUE_FLUSH, null);
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

private void retrieveInfo() {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
    intent.setAction(PreventIntent.ACTION_GET_INFO);
    intent.setData(Uri.fromParts(PreventIntent.SCHEME, getPackageName(), null));
    UILog.i("sending get info broadcast");
    if (receiver == null) {
        receiver = new HookReceiver();
    }/*  w  w w.ja va2 s . c  o  m*/
    sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, null, 0, null, null);
}

From source file:net.openid.appauth.AuthorizationService.java

/**
 * Sends an authorization request to the authorization service, using a
 * [custom tab](https://developer.chrome.com/multidevice/android/customtabs).
 * The parameters of this request are determined by both the authorization service
 * configuration and the provided {@link AuthorizationRequest request object}. Upon completion
 * of this request, the provided {@link PendingIntent completion PendingIntent} will be invoked.
 * If the user cancels the authorization request, the provided
 * {@link PendingIntent cancel PendingIntent} will be invoked.
 *
 * @param customTabsIntent/*from  ww  w.  ja v a  2 s .  c  o  m*/
 *     The intent that will be used to start the custom tab. It is recommended that this intent
 *     be created with the help of {@link #createCustomTabsIntentBuilder(Uri[])}, which will
 *     ensure that a warmed-up version of the browser will be used, minimizing latency.
 *
 * @throws android.content.ActivityNotFoundException if no suitable browser is available to
 *     perform the authorization flow.
 */
public void performAuthorizationRequest(@NonNull AuthorizationRequest request,
        @NonNull PendingIntent completedIntent, @Nullable PendingIntent canceledIntent,
        @NonNull CustomTabsIntent customTabsIntent) {
    checkNotDisposed();

    if (mBrowser == null) {
        throw new ActivityNotFoundException();
    }

    Uri requestUri = request.toUri();
    Intent intent;
    if (mBrowser.useCustomTab) {
        intent = customTabsIntent.intent;
    } else {
        intent = new Intent(Intent.ACTION_VIEW);
    }
    intent.setPackage(mBrowser.packageName);
    intent.setData(requestUri);

    Logger.debug("Using %s as browser for auth, custom tab = %s", intent.getPackage(),
            mBrowser.useCustomTab.toString());
    intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, CustomTabsIntent.NO_TITLE);

    Logger.debug("Initiating authorization request to %s", request.configuration.authorizationEndpoint);
    mContext.startActivity(AuthorizationManagementActivity.createStartIntent(mContext, request, intent,
            completedIntent, canceledIntent));
}

From source file:com.achep.base.ui.fragments.dialogs.FeedbackDialog.java

private void send(@NonNull CharSequence title, @NonNull CharSequence body, boolean attachLog) {
    Activity context = getActivity();/*from ww w. j  a v  a 2  s  .  c om*/
    String[] recipients = { Build.SUPPORT_EMAIL };
    Intent intent = new Intent().putExtra(Intent.EXTRA_EMAIL, recipients).putExtra(Intent.EXTRA_SUBJECT, title)
            .putExtra(Intent.EXTRA_TEXT, body);

    if (attachLog) {
        attachLog(intent);
        intent.setAction(Intent.ACTION_SEND);
        intent.setType("message/rfc822");
    } else {
        intent.setAction(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:")); // only email apps should handle it
    }

    if (IntentUtils.hasActivityForThat(context, intent)) {
        startActivity(intent);
        dismiss();
    } else {
        ToastUtils.showLong(context, R.string.feedback_error_no_app);
    }
}

From source file:ac.robinson.bettertogether.ConnectionSetupActivity.java

private boolean checkSettingsAccess() {
    // TODO: by default, applications are not granted access, but the settings switch shows access is allowed - need to
    // TODO: toggle this switch to actually grant access. Need to improve this interaction generally
    if (!canWriteSettings()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this);
        builder.setTitle(R.string.title_settings_access);
        builder.setMessage(R.string.hint_enable_settings_access);
        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override/*from  w w w.  ja va  2s .  c o  m*/
            public void onDismiss(DialogInterface dialog) {
                // note: dismiss rather than cancel so we always take this action (pos or neg result)
                if (checkSettingsAccess()) {
                    if (mConnectionMode == ConnectionMode.CONNECTION_INITIATED_HOTSPOT) {
                        createHotspot();
                        return;
                    }
                }
                mConnectionMode = ConnectionMode.SCANNING;
                setupDefaultUI();
            }
        });
        builder.setPositiveButton(R.string.hint_edit_settings_access, new DialogInterface.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.M)
            @Override
            public void onClick(DialogInterface dialog, int which) {
                try {
                    Intent settingsIntent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                    settingsIntent.setData(Uri.parse("package:" + PluginIntent.HOST_PACKAGE));
                    startActivity(settingsIntent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(ConnectionSetupActivity.this, R.string.error_editing_settings,
                            Toast.LENGTH_LONG).show();
                    // TODO: reset ui?
                }
                dialog.dismiss();
            }
        });
        builder.setNeutralButton(R.string.button_done, null);
        builder.show();
        return false;
    }
    return true;
}