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:com.byhook.cordova.chromelauncher.ChromeLauncher.java

/**
 * Executes the request and returns PluginResult.
 * @param action                 The action to execute.
 * @param args                         JSONArry of arguments for the plugin.
 * @param callbackContext                The callback context used when calling back into JavaScript.
 * @return                                 A PluginResult object with a status and message.
 *//*w  ww.j  a  va2  s . c  om*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    if (action.equals("open")) {
        String url = args.getString(0);

        Intent i = new Intent("android.intent.action.MAIN");
        i.setComponent(ComponentName.unflattenFromString("com.android.chrome/com.android.chrome.Main"));
        i.addCategory("android.intent.category.LAUNCHER");
        i.setData(Uri.parse(url));
        ((Activity) cordova).startActivity(i);
    } else if (action.equals("checkInstall")) {
        if (isInstalled("com.android.chrome")) {
            callbackContext.sendPluginResult(new PluginResult(status, true));
            return true;
        } else {
            status = PluginResult.Status.ERROR;
            callbackContext.sendPluginResult(new PluginResult(status, false));
            return true;
        }
    } else if (action.equals("openStore")) {
        Uri marketUri = Uri.parse("market://details?id=com.android.chrome");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
        ((Activity) cordova).startActivity(marketIntent);
    }

    callbackContext.sendPluginResult(new PluginResult(status, result));
    return true;
}

From source file:com.haarman.listviewanimations.MainActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_main_github:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(URL_GITHUB_IO));
        startActivity(intent);// w ww. ja v  a  2s. com
        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:com.g_node.gca.map.MapActivity.java

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

    getActionBar().setIcon(getResources().getDrawable(R.drawable.icon_maps));
    getActionBar().setTitle("Locations Map");

    getActionBar().setDisplayHomeAsUpEnabled(true);

    try {//ww w  .  jav a 2 s  .c om
        MapsInitializer.initialize(this);
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
    }
    locationMarkers();

    //Lisener for infoWindow to get LAT & LONG of that marker
    supportMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        public void onInfoWindowClick(Marker marker) {
            LatLng position = marker.getPosition();
            Log.i(gtag, "Marker Info Clicked - LAT: " + position.latitude + ", LONG: " + position.longitude);

            Intent navigateIntent = new Intent(Intent.ACTION_VIEW);

            String currentLat = String.valueOf(position.latitude);
            String currentLong = String.valueOf(position.longitude);
            String currLabel = marker.getTitle();

            String geoLocation = "geo:0,0?q=" + currentLat + "," + currentLong + "(" + currLabel + ")";
            navigateIntent.setData(Uri.parse(geoLocation));
            startActivity(navigateIntent);

        }
    });

    //adapter for custom info-window - added icon for navigation
    supportMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public View getInfoContents(Marker arg0) {
            // TODO Auto-generated method stub
            // Getting view from the layout file info_window_layout
            View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

            // Getting reference to the TextView to set title
            TextView note = (TextView) v.findViewById(R.id.note);

            note.setText(arg0.getTitle());

            // Returning the view containing InfoWindow contents
            return v;
        }
    });

}

From source file:com.midisheetmusicmemo.ChooseSongActivity.java

public void doOpenFile(FileUri file) {
    byte[] data = file.getData(this);
    if (data == null || data.length <= 6 || !MidiFile.hasMidiHeader(data)) {
        ChooseSongActivity.showErrorDialog("Error: Unable to open song: " + file.toString(), this);
        return;//from  w w w . ja v a 2s . co  m
    }
    updateRecentFile(file);
    Intent intent;
    if (MidiSheetMusicActivity.USE_ORIGINAL_MSM) {
        intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SheetMusicActivity.class);
    } else {
        intent = new Intent(this, TommyIntroActivity.class);
    }
    Log.v("doOpenFile", "URI: " + file.getUri().toString());
    intent.putExtra(SheetMusicActivity.MidiTitleID, file.toString());
    intent.putExtra(SheetMusicActivity.MidiDataID, file.getData(this));
    intent.putExtra(TommyConfig.FILE_URI_ID, file.toStringFull());
    startActivity(intent);
}

From source file:fr.bde_eseo.eseomega.version.AsyncCheckVersion.java

@Override
protected void onPostExecute(String data) {

    if (Utilities.isNetworkDataValid(data)) {
        try {/*from  www.j a  v a 2s.  c  om*/
            JSONObject obj = new JSONObject(data);
            int status = obj.getInt("status");

            if (status == 1) {
                JSONObject jsonData = obj.getJSONObject("data");
                String servVersion = jsonData.getString("version");

                if (!servVersion.equals(BuildConfig.VERSION_NAME)) {
                    new MaterialDialog.Builder(context).title(R.string.update_title)
                            .content(R.string.update_content).positiveText(R.string.dialog_yes)
                            .negativeText(R.string.dialog_no).callback(new MaterialDialog.ButtonCallback() {
                                @Override
                                public void onPositive(MaterialDialog dialog) {
                                    super.onPositive(dialog);

                                    try {
                                        Intent storeIntent = new Intent(Intent.ACTION_VIEW,
                                                Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID));
                                        context.startActivity(storeIntent);
                                    } catch (android.content.ActivityNotFoundException anfe) {
                                        Toast.makeText(context, "Erreur d'accs Play Store",
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }).show();
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

From source file:br.com.hotforms.usewaze.UseWaze.java

private void callWaze(final String url) {
    final Activity activity = this.cordova.getActivity();
    activity.runOnUiThread(new Runnable() {
        @Override/*from  w  w  w  . j a v a2 s. co m*/
        public void run() {
            try {
                Intent intent = null;
                intent = new Intent(Intent.ACTION_VIEW);
                // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
                // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
                Uri uri = Uri.parse(url);
                if ("file".equals(uri.getScheme())) {
                    intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                } else {
                    intent.setData(uri);
                }

                activity.startActivity(intent);
            } catch (ActivityNotFoundException ex) {
                String urlMarket = "market://details?id=com.waze";
                Intent intent = null;
                intent = new Intent(Intent.ACTION_VIEW);
                // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
                // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
                Uri uri = Uri.parse(urlMarket);
                if ("file".equals(uri.getScheme())) {
                    intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
                } else {
                    intent.setData(uri);
                }

                activity.startActivity(intent);
            }
        }
    });
}

From source file:mobisocial.bento.anyshare.ui.FeedItemListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    DbObj obj = mManager.getFeedItemObj(position);
    if (obj == null) {
        return;//from   w  w w .  j  ava 2  s.c  o  m
    }
    mManager.setContextObj(obj);
    if (obj.getType().equals(DataManager.TYPE_APP_STATE)) {
        Intent intent = new Intent(getActivity(), ViewActivity.class);
        startActivityForResult(intent, HomeActivity.REQUEST_VIEW);
    } else if (obj.getType().equals(DataManager.TYPE_PICTURE)) {
        Intent intent = new Intent(getActivity(), ImageViewActivity.class);
        intent.putExtra("hash", obj.getHash());
        startActivityForResult(intent, HomeActivity.REQUEST_VIEW);
    } else if (obj.getType().equals(DataManager.TYPE_LINK)) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        try {
            intent.setData(Uri.parse(obj.getJson().getString("uri")));
            startActivityForResult(intent, HomeActivity.REQUEST_VIEW);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    // super.onListItemClick(l, v, position, id);

}

From source file:com.polyvi.xface.extension.video.XVideoExt.java

private void play(String filePath, XCallbackContext callbackCtx) {
    XPathResolver pathResolver = new XPathResolver(filePath, mWebContext.getWorkSpace());
    String path = pathResolver.resolve();
    XPathResolver.Scheme scheme = pathResolver.getSchemeType();
    Boolean isPathValid = false;/*from w  w w.j a va2  s  . co  m*/

    //?
    if (null != path) {
        if (scheme == XPathResolver.Scheme.NONE || scheme == XPathResolver.Scheme.FILE
                || scheme == XPathResolver.Scheme.CONTENT) {//?
            File file = new File(path);
            if (file.exists()) {
                //??
                XFileUtils.setPermission(XFileUtils.READABLE_BY_OTHER, path);
                isPathValid = true;
            }
        } else {//?
            isPathValid = true;
        }
    }

    if (isPathValid) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(pathResolver.getUri(), "video/*");
        mExtensionContext.getSystemContext().startActivityForResult(new XVideoActResultListener(callbackCtx),
                intent, PLAY_VIDEO_REQUEST_CODE);
    } else {
        callbackCtx.error("video file not found error");
    }
}

From source file:co.uk.gauntface.mobile.devicelab.receiver.PushNotificationReceiver.java

private void launchBrowserTask(Context context, String url, String packageName) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    browserIntent.setPackage(packageName);
    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    List<ResolveInfo> activitiesList = context.getPackageManager().queryIntentActivities(browserIntent, -1);
    if (activitiesList.size() > 0) {
        context.startActivity(browserIntent);
    } else {/*from  www .  java  2  s  .  co m*/
        Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
        playStoreIntent.setData(Uri.parse("market://details?id=" + packageName));
        playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(playStoreIntent);
    }
}

From source file:com.netatmo.weatherstation.sample.LoginActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent browserIntent = new Intent();
    browserIntent.setAction(Intent.ACTION_VIEW);

    switch (item.getItemId()) {
    case R.id.action_forgot_password:
        browserIntent.setData(Uri.parse("https://auth.netatmo.com/access/lostpassword"));
        startActivity(browserIntent);//from w  ww .  jav a  2  s .c  om
        return true;
    case R.id.action_create_account:
        browserIntent.setData(Uri.parse("https://auth.netatmo.com/access/signup"));
        startActivity(browserIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}