Example usage for android.net Uri fromParts

List of usage examples for android.net Uri fromParts

Introduction

In this page you can find the example usage for android.net Uri fromParts.

Prototype

public static Uri fromParts(String scheme, String ssp, String fragment) 

Source Link

Document

Creates an opaque Uri from the given components.

Usage

From source file:com.example.android.hdrviewfinder.HdrViewfinderActivity.java

/**
 * Callback received when a permissions request has been completed.
 *//*  w  w w.  j a v  a  2  s.  c o m*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    Log.i(TAG, "onRequestPermissionResult");
    if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
        if (grantResults.length <= 0) {
            // If user interaction was interrupted, the permission request is cancelled and you
            // receive empty arrays.
            Log.i(TAG, "User interaction was cancelled.");
        } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Permission was granted.
            findAndOpenCamera();
        } else {
            // Permission denied.

            // In this Activity we've chosen to notify the user that they
            // have rejected a core permission for the app since it makes the Activity useless.
            // We're communicating this message in a Snackbar since this is a sample app, but
            // core permissions would typically be best requested during a welcome-screen flow.

            // Additionally, it is important to remember that a permission might have been
            // rejected without asking the user for permission (device policy or "Never ask
            // again" prompts). Therefore, a user interface affordance is typically implemented
            // when permissions are denied. Otherwise, your app could appear unresponsive to
            // touches or interactions which have required permissions.
            Snackbar.make(rootView, R.string.camera_permission_denied_explanation, Snackbar.LENGTH_INDEFINITE)
                    .setAction(R.string.settings, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            // Build intent that displays the App settings screen.
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
                            intent.setData(uri);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    }).show();
        }
    }
}

From source file:com.lypeer.fcpermission.FcPermissionsB.java

/**
 * ????????/*from www.ja v  a 2s  . c  om*/
 */
private boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton,
        @Nullable DialogInterface.OnClickListener negativeButtonOnClickListener, List<String> deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = shouldShowRequestPermissionRationale(object, perm);
        if (!shouldShowRationale) {
            final Activity activity = getActivity(object);
            if (null == activity) {
                return true;
            }

            AlertDialog dialog = new AlertDialog.Builder(activity).setMessage(rationale)
                    .setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                            intent.setData(uri);
                            startAppSettingsScreen(object, intent);
                        }
                    }).setNegativeButton(negativeButton, negativeButtonOnClickListener).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

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();
    }/*from   ww w .  j  av  a 2  s .  c o m*/
    sendOrderedBroadcast(intent, PreventIntent.PERMISSION_SYSTEM, receiver, null, 0, null, null);
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerAccount,
        final ConnectionRequest originalRequest) {

    final Uri handle = originalRequest.getAddress();
    String number = originalRequest.getAddress().getSchemeSpecificPart();
    log("call, number: " + number);

    // Crash on 555-DEAD to test call service crashing.
    if ("5550340".equals(number)) {
        throw new RuntimeException("Goodbye, cruel world.");
    }/*from   w  ww .  j  a  va  2 s .  c  o  m*/

    Bundle extras = originalRequest.getExtras();
    String gatewayPackage = extras.getString(TelecomManager.GATEWAY_PROVIDER_PACKAGE);
    Uri originalHandle = extras.getParcelable(TelecomManager.GATEWAY_ORIGINAL_ADDRESS);

    log("gateway package [" + gatewayPackage + "], original handle [" + originalHandle + "]");

    final TestConnection connection = new TestConnection(false /* isIncoming */);
    setAddress(connection, handle);

    // If the number starts with 555, then we handle it ourselves. If not, then we
    // use a remote connection service.
    // TODO: Have a special phone number to test the account-picker dialog flow.
    if (number != null && number.startsWith("555")) {
        // Normally we would use the original request as is, but for testing purposes, we are
        // adding ".." to the end of the number to follow its path more easily through the logs.
        final ConnectionRequest request = new ConnectionRequest(originalRequest.getAccountHandle(),
                Uri.fromParts(handle.getScheme(), handle.getSchemeSpecificPart() + "..", ""),
                originalRequest.getExtras(), originalRequest.getVideoState());
        connection.setVideoState(originalRequest.getVideoState());
        /// M: only VideoCall addVideoProvider @{
        if (originalRequest.getVideoState() == VideoProfile.STATE_BIDIRECTIONAL) {
            addVideoProvider(connection);
        }
        /// @}

        addCall(connection);
        connection.startOutgoing();

        for (Connection c : getAllConnections()) {
            c.setOnHold();
        }
    } else {
        log("Not a test number");
    }
    return connection;
}

From source file:com.amaze.filemanager.fragments.preference_fragments.Preffrag.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.reset();//from  w  w  w. ja  v a 2  s . co  m
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    final int th1 = Integer.parseInt(sharedPref.getString("theme", "0"));
    theme = th1 == 2 ? PreferenceUtils.hourOfDay() : th1;
    findPreference("donate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ((com.amaze.filemanager.activities.Preferences) getActivity()).donate();
            return false;
        }
    });
    findPreference("columns").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            final String[] sort = getResources().getStringArray(R.array.columns);
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.title(R.string.gridcolumnno);
            int current = Integer.parseInt(sharedPref.getString("columns", "-1"));
            current = current == -1 ? 0 : current;
            if (current != 0)
                current = current - 1;
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("columns", "" + (which != 0 ? sort[which] : "" + -1)).commit();
                    dialog.dismiss();
                    return true;
                }
            });
            a.build().show();
            return true;
        }
    });

    findPreference("theme").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            String[] sort = getResources().getStringArray(R.array.theme);
            int current = Integer.parseInt(sharedPref.getString("theme", "0"));
            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.items(sort).itemsCallbackSingleChoice(current, new MaterialDialog.ListCallbackSingleChoice() {
                @Override
                public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    sharedPref.edit().putString("theme", "" + which).commit();
                    dialog.dismiss();
                    restartPC(getActivity());
                    return true;
                }
            });
            a.title(R.string.theme);
            a.build().show();
            return true;
        }
    });
    findPreference("colors").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            ((com.amaze.filemanager.activities.Preferences) getActivity()).selectItem(1);
            return true;
        }
    });

    final CheckBx rootmode = (CheckBx) findPreference("rootmode");
    rootmode.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            boolean b = sharedPref.getBoolean("rootmode", false);
            if (b) {
                if (RootTools.isAccessGiven()) {
                    rootmode.setChecked(true);

                } else {
                    rootmode.setChecked(false);

                    Toast.makeText(getActivity(), getResources().getString(R.string.rootfailure),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                rootmode.setChecked(false);

            }

            return false;
        }
    });

    // Authors
    Preference preference4 = (Preference) findPreference("authors");
    preference4.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            skin = PreferenceUtils.getPrimaryColorString(sharedPref);
            int fab_skin = Color.parseColor(PreferenceUtils.getAccentString(sharedPref));
            if (theme == 1)
                a.theme(Theme.DARK);

            a.positiveText(R.string.close);
            a.positiveColor(fab_skin);
            LayoutInflater layoutInflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.authors, null);
            a.customView(view, true);
            a.title(R.string.authors);
            a.callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog materialDialog) {

                    materialDialog.cancel();
                }

                @Override
                public void onNegative(MaterialDialog materialDialog) {

                }
            });
            /*a.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.cancel();
            }
            });*/
            a.build().show();

            final Intent intent = new Intent(Intent.ACTION_VIEW);

            TextView googlePlus1 = (TextView) view.findViewById(R.id.googlePlus1);
            googlePlus1.setTextColor(Color.parseColor(skin));
            TextView googlePlus2 = (TextView) view.findViewById(R.id.googlePlus2);
            googlePlus2.setTextColor(Color.parseColor(skin));
            TextView git1 = (TextView) view.findViewById(R.id.git1);
            git1.setTextColor(Color.parseColor(skin));
            TextView git2 = (TextView) view.findViewById(R.id.git2);
            git2.setTextColor(Color.parseColor(skin));

            googlePlus1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://plus.google.com/u/0/110424067388738907251/"));
                    startActivity(intent);
                }
            });
            googlePlus2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://plus.google.com/+VishalNehra/"));
                    startActivity(intent);
                }
            });
            git1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://github.com/arpitkh96"));
                    startActivity(intent);
                }
            });
            git2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    intent.setData(Uri.parse("https://github.com/vishal0071"));
                    startActivity(intent);
                }
            });

            // icon credits
            TextView textView = (TextView) view.findViewById(R.id.icon_credits);
            textView.setMovementMethod(LinkMovementMethod.getInstance());
            textView.setLinksClickable(true);
            textView.setText(Html.fromHtml(getActivity().getString(R.string.icon_credits)));

            return false;
        }
    });

    // Changelog
    Preference preference1 = (Preference) findPreference("changelog");
    preference1.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
            if (theme == 1)
                a.theme(Theme.DARK);
            a.title(R.string.changelog);
            a.content(Html.fromHtml(getActivity().getString(R.string.changelog_version_9)
                    + getActivity().getString(R.string.changelog_change_9)
                    + getActivity().getString(R.string.changelog_version_8)
                    + getActivity().getString(R.string.changelog_change_8)
                    + getActivity().getString(R.string.changelog_version_7)
                    + getActivity().getString(R.string.changelog_change_7)
                    + getActivity().getString(R.string.changelog_version_6)
                    + getActivity().getString(R.string.changelog_change_6)
                    + getActivity().getString(R.string.changelog_version_5)
                    + getActivity().getString(R.string.changelog_change_5)
                    + getActivity().getString(R.string.changelog_version_4)
                    + getActivity().getString(R.string.changelog_change_4)
                    + getActivity().getString(R.string.changelog_version_3)
                    + getActivity().getString(R.string.changelog_change_3)
                    + getActivity().getString(R.string.changelog_version_2)
                    + getActivity().getString(R.string.changelog_change_2)
                    + getActivity().getString(R.string.changelog_version_1)
                    + getActivity().getString(R.string.changelog_change_1)));
            a.negativeText(R.string.close);
            a.positiveText(R.string.fullChangelog);
            int fab_skin = Color.parseColor(PreferenceUtils.getAccentString(sharedPref));
            a.positiveColor(fab_skin);
            a.negativeColor(fab_skin);
            a.callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog materialDialog) {

                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://github.com/arpitkh96/AmazeFileManager/commits/master"));
                    startActivity(intent);
                }

                @Override
                public void onNegative(MaterialDialog materialDialog) {

                    materialDialog.cancel();
                }
            }).build().show();
            return false;
        }
    });

    // Open Source Licenses
    Preference preference2 = (Preference) findPreference("os");
    //Defining dialog layout
    final Dialog dialog = new Dialog(getActivity(),
            android.R.style.Theme_Holo_Light_DialogWhenLarge_NoActionBar);
    //dialog.setTitle("Open-Source Licenses");
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    final View dialog_view = inflater.inflate(R.layout.open_source_licenses, null);
    dialog.setContentView(dialog_view);

    preference2.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {

            WebView wv = (WebView) dialog_view.findViewById(R.id.webView1);
            PreferenceUtils preferenceUtils = new PreferenceUtils();
            wv.loadData(PreferenceUtils.LICENCE_TERMS, "text/html", null);
            dialog.show();
            return false;
        }
    });

    // Feedback
    Preference preference3 = (Preference) findPreference("feedback");
    preference3.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                    Uri.fromParts("mailto", "arpitkh96@gmail.com", null));
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback : Amaze File Manager");
            Toast.makeText(getActivity(), getActivity().getFilesDir().getPath(), Toast.LENGTH_SHORT).show();
            File f = new File(getActivity().getExternalFilesDir("internal"), "log.txt");
            if (f.exists()) {
                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
            }
            startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.feedback)));
            return false;
        }
    });

    // rate
    Preference preference5 = (Preference) findPreference("rate");
    preference5.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent1 = new Intent(Intent.ACTION_VIEW);
            intent1.setData(Uri.parse("market://details?id=com.amaze.filemanager"));
            startActivity(intent1);
            return false;
        }
    });

    // studio
    Preference studio = findPreference("studio");
    studio.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            COUNT++;
            if (COUNT >= 5) {
                if (toast != null)
                    toast.cancel();
                toast = Toast.makeText(getActivity(), "Studio Mode : " + COUNT, Toast.LENGTH_SHORT);
                toast.show();

                sharedPref.edit().putInt("studio", Integer.parseInt(Integer.toString(COUNT) + "000")).apply();
            } else {
                sharedPref.edit().putInt("studio", 0).apply();
            }
            return false;
        }
    });

    // G+
    gplus = (CheckBx) findPreference("plus_pic");
    gplus.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (gplus.isChecked()) {
                boolean b = checkGplusPermission();
                if (!b)
                    requestGplusPermission();
            }
            return false;
        }
    });
    if (BuildConfig.IS_VERSION_FDROID)
        gplus.setEnabled(false);

    // Colored navigation bar
}

From source file:de.tap.easy_xkcd.Activities.MainActivity.java

public void selectDrawerItem(final MenuItem menuItem, final boolean showOverview) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (menuItem.getItemId() == R.id.nav_whatif)
            toolbar.setElevation(0);/*from w ww  . java  2s.com*/
        else {
            Resources r = getResources();
            float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, r.getDisplayMetrics());
            toolbar.setElevation(px);
        }
    }
    switch (menuItem.getItemId()) {
    case R.id.nav_browser:
        if (!prefHelper.isOnline(this) && !fullOffline) {
            showDrawerErrorToast(R.string.no_connection);
            return;
        }
        //showComicBrowserFragment
        animateToolbar(-300);
        showFragment("pref_random_comics", menuItem.getItemId(), "Comics", BROWSER_TAG, FAV_TAG, WHATIF_TAG,
                showOverview);
        break;
    case R.id.nav_favorites:
        //Check if there are any Favorites
        if (Favorites.getFavoriteList(this).length == 0) {
            showDrawerErrorToast(R.string.no_favorites);
            return;
        }
        //showFavoritesFragment
        animateToolbar(300);
        showFragment("pref_random_favorites", menuItem.getItemId(),
                getResources().getString(R.string.nv_favorites), FAV_TAG, BROWSER_TAG, WHATIF_TAG,
                showOverview);
        break;
    case R.id.nav_whatif:
        if (!prefHelper.isOnline(this) && !fullOfflineWhatIf) {
            showDrawerErrorToast(R.string.no_connection);
            return;
        }
        animateToolbar(300);
        if (getSupportFragmentManager().findFragmentByTag(WHATIF_TAG) == null) {
            mDrawer.closeDrawers();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    showFragment("", menuItem.getItemId(), "What if?", WHATIF_TAG, FAV_TAG, BROWSER_TAG,
                            showOverview);
                }
            }, 150);
        } else {
            showFragment("", menuItem.getItemId(), "What if?", WHATIF_TAG, FAV_TAG, BROWSER_TAG, showOverview);
        }
        break;

    case R.id.nav_settings:
        mDrawer.closeDrawers();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivity(i);
            }
        }, 200);
        return;

    case R.id.nav_feedback:
        mDrawer.closeDrawers();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(Intent.ACTION_SENDTO,
                        Uri.fromParts("mailto", "easyxkcd@gmail.com", null));
                startActivity(Intent.createChooser(i, getResources().getString(R.string.nav_feedback_send)));
            }
        }, 200);
        return;

    case R.id.nav_about:
        mDrawer.closeDrawers();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(i);
            }
        }, 250);
        return;
    }
    menuItem.setChecked(true);
    mDrawer.closeDrawers();
    mCurrentFragment = menuItem.getItemId();
    invalidateOptionsMenu();
}

From source file:com.albedinsky.android.support.intent.EmailIntent.java

/**
 * Creates an URI specific for the {@link Intent#ACTION_SENDTO} intent action
 * from the given set of e-mails./*from   www . jav a  2s .co  m*/
 *
 * @param addresses List with e-mail addresses.
 * @return Created URI containing the specified addresses or {@code null} if the given list of
 * addresses is empty.
 */
@Nullable
protected static Uri createUri(@NonNull List<String> addresses) {
    final int n = addresses.size();
    if (n == 0)
        return null;
    final StringBuilder data = new StringBuilder(n * 15);
    for (int i = 0; i < n; i++) {
        data.append(addresses.get(i));
        if (i < (n - 1)) {
            data.append(",");
        }
    }
    return Uri.fromParts(URI_SCHEME, data.toString(), null);
}

From source file:org.totschnig.myexpenses.activity.ProtectedFragmentActivity.java

public void requestCalendarPermission() {
    if (calendarPermissionPermanentlyDeclined()) {
        //noinspection InlinedApi
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts("package", getPackageName(), null);
        intent.setData(uri);/*from   w  w  w  .  ja  va2s .  c  o m*/
        startActivity(intent);
    } else {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_CALENDAR },
                ProtectionDelegate.PERMISSIONS_REQUEST_WRITE_CALENDAR);
    }
}

From source file:com.base.utils.permission.EasyPermissions.java

@TargetApi(11)
public static void startAppSettings(Object object) {
    final Activity activity = getActivity(object);
    if (null == activity) {
        return;// w  ww  .  j  a  v  a 2 s  .  co  m
    }
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
    intent.setData(uri);
    startAppSettingsScreen(object, intent);
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerAccount,
        final ConnectionRequest request) {
    PhoneAccountHandle accountHandle = request.getAccountHandle();
    ComponentName componentName = new ComponentName(this, TestConnectionService.class);

    if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) {
        final TestConnection connection = new TestConnection(true);
        // Get the stashed intent extra that determines if this is a video call or audio call.
        Bundle extras = request.getExtras();
        boolean isVideoCall = extras.getBoolean(EXTRA_IS_VIDEO_CALL);
        Uri providedHandle = extras.getParcelable(EXTRA_HANDLE);

        // Use dummy number for testing incoming calls.
        Uri address = providedHandle == null
                ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(isVideoCall), null)
                : providedHandle;//  ww w  . ja  va2s  .c om

        int videoState = isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY;
        connection.setVideoState(videoState);
        setAddress(connection, address);

        addVideoProvider(connection);

        addCall(connection);

        ConnectionRequest newRequest = new ConnectionRequest(request.getAccountHandle(), address,
                request.getExtras(), videoState);
        connection.setVideoState(videoState);
        return connection;
    } else {
        return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR,
                "Invalid inputs: " + accountHandle + " " + componentName));
    }
}