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:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String mimeType = obj.optString(MIME_TYPE);
    Uri uri = Uri.parse(obj.optString(URI));
    if (fileAvailable(mimeType, uri)) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_VIEW);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.setType(mimeType);/*ww w  .ja  va2 s  . c o m*/
        i.setData(uri);
        i.putExtra(Intent.EXTRA_TEXT, uri);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i,
                PendingIntent.FLAG_CANCEL_CURRENT);
        (new PresenceAwareNotify(context)).notify("New content from Musubi", "New Content from Musubi",
                mimeType + "  " + uri, contentIntent);
    } else {
        Log.w(TAG, "Received file, failed to handle: " + uri);
    }
}

From source file:com.krayzk9s.imgurholo.activities.ImgurLinkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    destroyed = false;/*from  w  w  w.  j  a  v  a 2 s.  com*/
    if (getActionBar() != null)
        getActionBar().setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();
    Log.d("New Intent", intent.toString());
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
            Intent serviceIntent = new Intent(this, UploadService.class);
            if (intent.getExtras() == null)
                finish();
            serviceIntent.setData((Uri) intent.getExtras().get("android.intent.extra.STREAM"));
            startService(serviceIntent);
            finish();
        }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
        Log.d("sending", "sending multiple");
        Toast.makeText(this, R.string.toast_uploading, Toast.LENGTH_SHORT).show();
        ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        Intent serviceIntent = new Intent(this, UploadService.class);
        serviceIntent.putParcelableArrayListExtra("images", list);
        startService(serviceIntent);
        finish();
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null
            && intent.getData().toString().startsWith("http://imgur.com/a")) {
        String uri = intent.getData().toString();
        album = uri.split("/")[4];
        Log.d("album", album);
        Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
        fetcher.execute();
    } else if (Intent.ACTION_VIEW.equals(action)
            && intent.getData().toString().startsWith("http://imgur.com/gallery/")) {
        String uri = intent.getData().toString();
        final String album = uri.split("/")[4];
        if (album.length() == 5) {
            Log.d("album", album);
            Fetcher fetcher = new Fetcher(this, "/3/album/" + album, ApiCall.GET, null, apiCall, ALBUM);
            fetcher.execute();
        } else if (album.length() == 7) {
            Log.d("image", album);
            Fetcher fetcher = new Fetcher(this, "/3/gallery/image/" + album, ApiCall.GET, null, apiCall, IMAGE);
            fetcher.execute();
        }
    } else if (Intent.ACTION_VIEW.equals(action) && intent.getData().toString().startsWith("http://i.imgur")) {
        String uri = intent.getData().toString();
        final String image = uri.split("/")[3].split("\\.")[0];
        Log.d("image", image);
        Fetcher fetcher = new Fetcher(this, "/3/image/" + image, ApiCall.GET, null, apiCall, IMAGE);
        fetcher.execute();
    }
}

From source file:com.gmail.project16543.com.phonegap.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 * //  w w w.j  av a  2s .co m
 * NOTE: If usePhoneGap is set, only trusted PhoneGap URLs should be loaded,
 * since any PhoneGap API can be called by the loaded HTML page.
 * 
 * @param url
 *            The url to load.
 * @param usePhoneGap
 *            Load url in PhoneGap webview.
 * @return "" if ok, or error message.
 */
public String showWebPage(String url, boolean usePhoneGap) {
    try {
        Intent intent = null;
        if (usePhoneGap) {
            intent = new Intent().setClass(this.ctx, com.phonegap.DroidGap.class);
            intent.setData(Uri.parse(url));
            intent.putExtra("url", url);
            intent.putExtra("loadUrlTimeoutValue", 60000);

            intent.putExtra("loadingDialog", "Wait,Loading web page...");
            intent.putExtra("hideLoadingDialogOnPageLoad", true);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
        }
        this.ctx.startActivity(intent);
        return "";
    } catch (android.content.ActivityNotFoundException e) {
        System.out.println("ChildBrowser: Error loading url " + url + ":" + e.toString());
        return e.toString();
    }
}

From source file:com.fsa.en.dron.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    RateThisApp.Config config = new RateThisApp.Config(5, 10);
    config.setTitle(R.string.my_own_title);
    config.setMessage(R.string.my_own_message);
    config.setYesButtonText(R.string.my_own_rate);
    config.setNoButtonText(R.string.my_own_thanks);
    config.setCancelButtonText(R.string.my_own_cancel);
    RateThisApp.init(config);//from   www.j  av a 2s  . co m
    RateThisApp.setCallback(new RateThisApp.Callback() {
        @Override
        public void onYesClicked() {
            final String appPackageName = getPackageName(); // getPackageName() from Context or Activity  object
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }

        @Override
        public void onNoClicked() {
            TastyToast.makeText(getApplicationContext(), "Vuelve pronto!", TastyToast.LENGTH_LONG,
                    TastyToast.INFO);
        }

        @Override
        public void onCancelClicked() {
            TastyToast.makeText(getApplicationContext(), "Prometo tomar mejores fotografias!",
                    TastyToast.LENGTH_LONG, TastyToast.ERROR);
        }
    });
    button = (Button) findViewById(R.id.button);
    button.setVisibility(View.INVISIBLE);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            checkConnection();
        }
    });
    BottomNavigationBar bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
    bottomNavigationBar.setMode(BottomNavigationBar.MODE_FIXED);
    bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC);
    bottomNavigationBar.setBarBackgroundColor(R.color.material_light_blue_800);
    bottomNavigationBar.setActiveColor(R.color.material_grey_900);
    bottomNavigationBar.setInActiveColor(R.color.material_blue_grey_200);
    bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.compose, "Mensaje"))
            .addItem(new BottomNavigationItem(R.drawable.sociales, "Sociales"))
            .addItem(new BottomNavigationItem(R.drawable.share, "Cuntale a un amigo")).initialise();
    bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
        @Override
        public void onTabSelected(int position) {
            switch (position) {
            case 0:
                Intent email = new Intent(Intent.ACTION_SEND);
                email.putExtra(Intent.EXTRA_EMAIL, new String[] { "marceloespinoza00@gmail.com" });
                email.putExtra(Intent.EXTRA_SUBJECT, "Formosa en dron");
                email.putExtra(Intent.EXTRA_TEXT, "Dej tu mensaje");
                email.setType("message/rfc822");
                startActivity(Intent.createChooser(email, "Elige un cliente :"));
                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Formosa en dron");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                        "https://play.google.com/store/apps/details?id=com.fsa.en.dron");
                startActivity(Intent.createChooser(sharingIntent, "Compartir via"));
                break;

            }

        }

        @Override
        public void onTabUnselected(int position) {

        }

        @Override
        public void onTabReselected(int position) {
            switch (position) {
            case 0:

                break;
            case 1:
                Intent intent = new Intent(getApplication(), FacebookActivity.class);
                startActivity(intent);
                break;
            case 2:

                break;

            }
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    LayoutInflater inflator = LayoutInflater.from(this);
    View v = inflator.inflate(R.layout.toolbar_title, null);
    Typeface budget = Typeface.createFromAsset(getAssets(), "fonts/Budget.otf");
    Typeface typographica = Typeface.createFromAsset(getAssets(), "fonts/TypoGraphica.otf");
    TextView mToolbarCustomTitle = (TextView) v.findViewById(R.id.title);
    TextView mToolbarCustomSubTitle = (TextView) v.findViewById(R.id.subtitle);
    mToolbarCustomTitle.setText("Formosa");
    mToolbarCustomSubTitle.setText("en dron");
    mToolbarCustomTitle.setTypeface(typographica);
    mToolbarCustomSubTitle.setTypeface(budget);
    getSupportActionBar().setCustomView(v);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            if (id == R.id.recargar) {
                checkConnection();
            }
            if (id == R.id.info) {
                showDialog();
            }
            return false;
        }
    });
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(getApplicationContext(),
            recyclerView, new GalleryAdapter.ClickListener() {
                @Override
                public void onClick(View view, int position) {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("images", images);
                    bundle.putInt("position", position);

                    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
                    SlideshowDialogFragment newFragment = SlideshowDialogFragment.newInstance();
                    newFragment.setArguments(bundle);
                    newFragment.show(ft, "slideshow");
                }

                @Override
                public void onLongClick(View view, int position) {

                }
            }));
    pDialog = new ProgressDialog(this);
    images = new ArrayList<>();
    mAdapter = new GalleryAdapter(getApplicationContext(), images);
    RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setAdapter(mAdapter);

}

From source file:com.google.android.apps.muzei.featuredart.FeaturedArtSource.java

@Override
protected void onUpdate(int reason) {
    List<UserCommand> commands = new ArrayList<UserCommand>();
    if (reason == UPDATE_REASON_INITIAL) {
        // Show initial photo (starry night)
        publishArtwork(new Artwork.Builder().imageUri(Uri.parse("file:///android_asset/starrynight.jpg"))
                .title("The Starry Night").token("initial")
                .byline("Vincent van Gogh, 1889.\nMuzei shows a new painting every day.")
                .viewIntent(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.wikipaintings.org/en/vincent-van-gogh/the-starry-night-1889")))
                .build());/*from w  w  w.j  a va 2s.c om*/
        commands.add(new UserCommand(BUILTIN_COMMAND_ID_NEXT_ARTWORK));
        // show the latest photo in 15 minutes
        scheduleUpdate(System.currentTimeMillis() + 15 * 60 * 1000);

    } else {
        // For everything but the initial update, defer to RemoteMuzeiArtSource
        super.onUpdate(reason);
    }

    commands.add(new UserCommand(COMMAND_ID_SHARE, getString(R.string.action_share_artwork)));
    if (BuildConfig.DEBUG) {
        commands.add(new UserCommand(COMMAND_ID_DEBUG_INFO, "Debug info"));
    }
    setUserCommands(commands);
}

From source file:de.nico.asura.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {

    case R.id.action_prefs:
        startActivity(new Intent(this, Preferences.class));
        return true;

    case R.id.action_WebView1:
        if (!(Utils.isNetworkAvailable(this)))
            Utils.makeLongToast(this, offline);
        else//from  w  w w.ja  v  a  2  s .c  o m
            startActivity(new Intent(this, WebView1.class));
        return true;

    case R.id.action_Link1:
        if (!(Utils.isNetworkAvailable(this)))
            Utils.makeLongToast(this, offline);
        else
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.menu_Link_1_url))));
        return true;

    case R.id.action_AuthWebView1:
        if (!(Utils.isNetworkAvailable(this)))
            Utils.makeLongToast(this, offline);
        else
            startActivity(new Intent(this, AuthWebView1.class));
        return true;

    default:
        return super.onOptionsItemSelected(item);

    }

}

From source file:com.example.faisal.sunshine.app.ForecastFragment.java

public void startMap() {
    preferences = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
    String location = preferences.getString(getString(R.string.pref_location_key),
            getString(R.string.pref_location_default));
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("geo:0,0?q=" + location));
    startActivity(intent);//from   ww  w .  j ava2 s .com
}

From source file:jp.co.conit.sss.sn.ex2.service.SendMessageIdIntentService.java

/**
 * SamuraiNotification????snUserdata???????
 * //from w w w .j a  v  a2s  . c om
 * @param snUserdata
 */
private void startActivity4Userdata(String snUserdata) {
    Intent activityIntent = new Intent();
    if (StringUtil.isEmpty(snUserdata) || snUserdata.equals("null")) {
        activityIntent.setClass(getApplicationContext(), MessagesActivity.class);
    } else {
        if (snUserdata.startsWith("http")) {
            activityIntent.setAction(Intent.ACTION_VIEW);
            activityIntent.setData(Uri.parse(snUserdata));
        } else {
            activityIntent.setClass(getApplicationContext(), UserDataActivity.class);
            activityIntent.putExtra("option", snUserdata);
        }
    }
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(activityIntent);
}

From source file:com.moust.cordova.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 ww.  j  a v  a 2 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, "");
        //Remove the path to the file from any location
        if (filepath.contains("www/file:")) {
            filepath = filepath.replace("www/file://", "");
        }
        // 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);

        //It uses a fixed name to optimize memory space
        File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + VIDEO_FILE_NAME);

        //Always copy the file
        //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);
}

From source file:com.hybris.mobile.activity.OrderDetailActivity.java

private void handleIntent(Intent intent) {

    if (Hybris.isUserLoggedIn()) {
        if (intent.hasExtra("orderDetails")) {
            ((TextView) findViewById(R.id.lbl_thankYou)).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.lbl_orderConfirmation)).setVisibility(View.VISIBLE);
            // TODO
            setmOrderDetails(JsonUtils.fromJson(intent.getStringExtra("orderDetails"), CartOrder.class));
        }/*from   w  w  w .j a  va  2  s  .  c  o  m*/
        if (intent.hasExtra(DataConstants.ORDER_ID)) {
            setmOrderID(intent.getStringExtra(DataConstants.ORDER_ID));
        }
        // Call from another application (QR Code) 
        else if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
            setmOrderID(RegexUtil.getOrderIdFromHybrisPattern(intent.getDataString()));
        }
    }
    // User not logged in, redirection to the login page
    else {
        Intent loginIntent = new Intent(this, LoginActivity.class);

        // Call from another application (QR Code) 
        if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
            loginIntent.putExtra(DataConstants.ORDER_ID,
                    RegexUtil.getOrderIdFromHybrisPattern(intent.getDataString()));
        }

        loginIntent.putExtra(DataConstants.INTENT_DESTINATION, DataConstants.INTENT_ORDER_DETAILS);
        loginIntent.putExtras(intent);
        startActivity(loginIntent);
    }
}