Example usage for android.content Intent ACTION_VIEW

List of usage examples for android.content Intent ACTION_VIEW

Introduction

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

Prototype

String ACTION_VIEW

To view the source code for android.content Intent ACTION_VIEW.

Click Source Link

Document

Activity Action: Display the data to the user.

Usage

From source file:dk.iface.cordova.plugin.googlenavigate.GoogleNavigate.java

private boolean navigate(JSONArray args, CallbackContext callbackContext) {
    boolean result;

    try {/*from  w  w w  .  j a  va2  s  . com*/
        String query = args.getString(0);

        if (query != null && query.length() > 0) {
            Log.d(LOG_TAG, "Navigating to " + query);
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + query));
            this.cordova.getActivity().startActivity(i);
            callbackContext.success();
        } else {
            Log.d(LOG_TAG, "Expected non-empty string arguments for query.");
            callbackContext.error("Expected non-empty string arguments for query.");
        }
        result = true;
    } catch (JSONException e) {
        Log.d(LOG_TAG, "Exception occurred: ".concat(e.getMessage()));
        result = false;
    }
    return result;
}

From source file:au.id.micolous.frogjump.Util.java

private static void newVersionAlert(final Activity activity) {
    // We have a new version available.  Prompt.
    AlertDialog.Builder updateDialog = new AlertDialog.Builder(activity);
    updateDialog.setTitle(R.string.update_available_title);
    updateDialog.setMessage(R.string.update_available_message);
    updateDialog.setPositiveButton(R.string.update_positive, new DialogInterface.OnClickListener() {
        @Override//from w w  w .ja  v  a2  s.co m
        public void onClick(DialogInterface dialogInterface, int i) {
            try {
                activity.startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
            } catch (ActivityNotFoundException anfe) {
                // Hmm, market is not installed
                Log.w(TAG, "Google Play is not installed; cannot install update");
            }
        }
    });
    updateDialog.setNegativeButton(R.string.update_negative, null);
    updateDialog.setCancelable(true);
    updateDialog.show();

}

From source file:com.duguang.baseanimation.ui.listivew.listviews.ListViewsMainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_main_github:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("http://nhaarman.github.io/ListViewAnimations?ref=app"));
        startActivity(intent);//from  w  w w  .j  av a  2 s  .c o  m
        return true;
    case R.id.menu_main_beer:
        buy("beer");
        return true;
    case R.id.menu_main_beer2:
        buy("beer2");
        return true;
    case R.id.menu_main_beer3:
        buy("beer3");
        return true;
    case R.id.menu_main_beer4:
        buy("beer4");
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:io.ionic.links.IonicDeeplink.java

public void handleIntent(Intent intent) {
    final String intentString = intent.getDataString();

    // read intent
    String action = intent.getAction();
    Uri url = intent.getData();//  w  ww  .  j  a  v  a  2s .  c o m
    JSONObject bundleData = this._bundleToJson(intent.getExtras());
    Log.d(TAG, "Got a new intent: " + intentString + " " + intent.getScheme() + " " + action + " " + url);

    // if app was not launched by the url - ignore
    if (!Intent.ACTION_VIEW.equals(action) || url == null) {
        return;
    }

    // store message and try to consume it
    try {
        lastEvent = new JSONObject();
        lastEvent.put("url", url.toString());
        lastEvent.put("path", url.getPath());
        lastEvent.put("queryString", url.getQuery());
        lastEvent.put("scheme", url.getScheme());
        lastEvent.put("host", url.getHost());
        lastEvent.put("fragment", url.getFragment());
        lastEvent.put("extra", bundleData);
        consumeEvents();
    } catch (JSONException ex) {
        Log.e(TAG, "Unable to process URL scheme deeplink", ex);
    }
}

From source file:cc.metapro.openct.allclasses.ExcelDialog.java

@NonNull
@Override// w  ww . jav  a 2  s .c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.import_from_excel)
            .setMessage(R.string.select_file_tip).setPositiveButton(R.string.select_file, null)
            .setNegativeButton(android.R.string.cancel, null)
            .setNeutralButton(R.string.refer_to_usage, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri
                            .parse("https://github.com/jeffreystoke/openct-mvp#import-from-xlsx-excel-2007"));
                    startActivity(intent);
                }
            }).create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        int hasPermission = ContextCompat.checkSelfPermission(getActivity(),
                                Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasPermission != PackageManager.PERMISSION_GRANTED) {
                            requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                    REQUEST_EXTERNAL_FILE_WRITE);
                        } else {
                            showFilerChooser();
                        }
                    } else {
                        showFilerChooser();
                    }
                }
            });
        }
    });
    return dialog;
}

From source file:DetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);

    detector = new GestureDetector(this, new GalleryGestureDetector());
    listener = new View.OnTouchListener() {

        @Override//from   w  ww.  j a v  a2 s  .c  om
        public boolean onTouch(View v, MotionEvent event) {
            return detector.onTouchEvent(event);
        }
    };

    ImageIndex = 0;

    detailImage = (ImageView) findViewById(R.id.detail_image);
    detailImage.setOnTouchListener(listener);

    TextView detailName = (TextView) findViewById(R.id.detail_name);
    TextView detailDistance = (TextView) findViewById(R.id.detail_distance);
    TextView detailText = (TextView) findViewById(R.id.detail_text);
    detailText.setMovementMethod(new ScrollingMovementMethod());
    ImageView detailWebLink = (ImageView) findViewById(R.id.detail_web_link);

    int i = MainActivity.currentItem;
    Random n = new Random();
    int m = n.nextInt((600 - 20) + 1) + 20;
    setTitle(getString(R.string.app_name) + " - " + MainData.nameArray[i]);
    detailImage.setImageResource(MainData.detailImageArray[i]);
    detailName.setText(MainData.nameArray[i]);
    detailDistance.setText(String.valueOf(m) + " miles");
    detailText.setText(MainData.detailTextArray[i]);

    detailWebLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setData(Uri.parse(MainData.detailWebLink[MainActivity.currentItem]));
            startActivity(intent);
        }
    });
}

From source file:com.manning.androidhacks.hack004.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.prefs);

    Preference sharePref = findPreference("pref_share");
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Check this app!");
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this awesome app at: ...");
    sharePref.setIntent(shareIntent);//  w ww  .j av  a2s .c o m

    Preference ratePref = findPreference("pref_rate");
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    ratePref.setIntent(goToMarket);

    updateUserText();
}

From source file:piramide.multimodal.downloader.client.ApplicationDownloader.java

void install() {
    final Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(//from w w w . j  a v a 2s .com
            Uri.parse("file://" + this.context.getFilesDir().getAbsolutePath() + "/" + APK_FILENAME),
            "application/vnd.android.package-archive");
    this.context.startActivity(intent);
}

From source file:com.digitalarx.android.files.FileOperationsHelper.java

public void openFile(OCFile file) {
    if (file != null) {
        String storagePath = file.getStoragePath();
        String encodedStoragePath = WebdavUtils.encodePath(storagePath);

        Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW);
        intentForSavedMimeType.setDataAndType(Uri.parse("file://" + encodedStoragePath), file.getMimetype());
        intentForSavedMimeType/* w w  w  . j  a v a  2  s. c om*/
                .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

        Intent intentForGuessedMimeType = null;
        if (storagePath.lastIndexOf('.') >= 0) {
            String guessedMimeType = MimeTypeMap.getSingleton()
                    .getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));
            if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) {
                intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW);
                intentForGuessedMimeType.setDataAndType(Uri.parse("file://" + encodedStoragePath),
                        guessedMimeType);
                intentForGuessedMimeType.setFlags(
                        Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            }
        }

        Intent chooserIntent = null;
        if (intentForGuessedMimeType != null) {
            chooserIntent = Intent.createChooser(intentForGuessedMimeType,
                    mFileActivity.getString(R.string.actionbar_open_with));
        } else {
            chooserIntent = Intent.createChooser(intentForSavedMimeType,
                    mFileActivity.getString(R.string.actionbar_open_with));
        }

        mFileActivity.startActivity(chooserIntent);

    } else {
        Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
    }
}

From source file:com.dawsonloudon.videoplayer.VideoPlayer.java

private void playVideo(String url) throws IOException {
    if (url.contains("bit.ly/") || url.contains("goo.gl/") || url.contains("tinyurl.com/")
            || url.contains("youtu.be/")) {
        //support for google / bitly / tinyurl / youtube shortens
        URLConnection con = new URL(url).openConnection();
        con.connect();/*from  w  w  w.j a  v  a2 s  .  c  om*/
        InputStream is = con.getInputStream();
        //new redirected url
        url = con.getURL().toString();
        is.close();
    }

    // Create URI
    Uri uri = Uri.parse(url);

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
        // If we don't do it this way you don't have the option for youtube
        uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
        if (isYouTubeInstalled()) {
            intent = new Intent(Intent.ACTION_VIEW, uri);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=com.google.android.youtube"));
        }
    } else if (url.contains(ASSETS)) {
        // get file path in assets folder
        String filepath = url.replace(ASSETS, "");
        // get actual filename from path as command to write to internal storage doesn't like folders
        String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

        // Don't copy the file if it already exists
        File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);
        if (!fp.exists()) {
            this.copy(filepath, filename);
        }

        // change uri to be to the new file in internal storage
        uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);

        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    } else {
        // Display video player
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
}