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.codebutler.farebot.activities.MainActivity.java

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Uri uri = ContentUris.withAppendedId(CardProvider.CONTENT_URI_CARD, id);
    startActivity(new Intent(Intent.ACTION_VIEW, uri));
}

From source file:com.ecml.ChooseSongActivity.java

/** Open the chosen file in the right activity */
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 ww.  j a  v  a  2  s  .c o  m
    }

    ECML.song = file;
    updateRecentFile(file);

    String mode = "";
    // Get the mode for which we are opening a file
    if (ECML.intent != null) {
        mode = ECML.intent.getStringExtra(ChooseSongActivity.mode);
    }
    Log.d("MODE", "" + mode);

    // Get the number of the current activity
    int number = this.getIntent().getIntExtra("number", 0);

    // Get the level of the mode (speed/reading of notes) if there is one 
    int lvl = this.getIntent().getIntExtra("level", level);

    if (mode.equals("speed")) {
        if (lvl == 1) {
            intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SpeedGamelvl1.class);
            intent.putExtra(SpeedGamelvl1.MidiTitleID, file.toString());
            intent.putExtra("number", number);
            startActivity(intent);
            finish();
        } else {
            intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SpeedGamelvln.class);
            intent.putExtra(SpeedGamelvln.MidiTitleID, file.toString());
            intent.putExtra("level", lvl);
            intent.putExtra("number", number);
            startActivity(intent);
            finish();
        }

    } else if (mode.equals("reading")) {
        if (lvl == 1) {
            intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, ReadingGameBeginner.class);
            intent.putExtra(ReadingGameBeginner.MidiTitleID, file.toString());
            intent.putExtra("number", number);
            startActivity(intent);
            finish();
        } else {
            intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, ReadingGameNormal.class);
            intent.putExtra(ReadingGameNormal.MidiTitleID, file.toString());
            intent.putExtra("number", number);
            startActivity(intent);
            finish();
        }

    } else if (mode.equals("chooseSong")) {
        intent = new Intent(Intent.ACTION_VIEW, file.getUri(), this, SheetMusicActivity.class);
        intent.putExtra("number", number);
        startActivity(intent);
        finish();
    } else if (mode.equals("studentActivities")) {
        intent = new Intent();
        intent.putExtra("song", file.toString());
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}

From source file:com.krayzk9s.imgurholo.services.DownloadService.java

@Override
protected void onHandleIntent(Intent intent) {
    final NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    ids = intent.getParcelableArrayListExtra("ids");
    albumName = "/";
    downloaded = 0;/*  w  ww  . j  a va 2s .  c  o m*/
    if (ids.size() > 0) {
        albumName += intent.getStringExtra("albumName") + "/";
        File myDirectory = new File(
                android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                albumName);
        if (!myDirectory.exists()) {
            myDirectory.mkdirs();
        }
    }
    for (int i = 0; i < ids.size(); i++) {
        try {
            final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE)
                    .split("/")[1];
            final String id = ids.get(i).getJSONObject().getString("id");
            final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK);
            Log.d("data", ids.get(i).getJSONObject().toString());
            Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE,
                    ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]);
            Log.d("id", ids.get(i).getJSONObject().getString("id"));
            Log.d(ImgurHoloActivity.IMAGE_DATA_LINK,
                    ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK));
            final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
            notificationBuilder.setContentTitle(getString(R.string.picture_download))
                    .setContentText(getString(R.string.download_in_progress))
                    .setSmallIcon(R.drawable.icon_desaturated);
            Ion.with(getApplicationContext(), link).progress(new ProgressCallback() {
                @Override
                public void onProgress(int i, int i2) {
                    notificationBuilder.setProgress(i2, i, false);
                }
            }).write(new File(
                    android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                            + albumName + id + "." + type))
                    .setCallback(new FutureCallback<File>() {
                        @Override
                        public void onCompleted(Exception e, File file) {
                            if (file == null)
                                return;
                            downloaded += 1;
                            if (downloaded == ids.size()) {
                                NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder(
                                        getApplicationContext());
                                if (ids.size() == 1) {
                                    Intent viewImageIntent = new Intent(Intent.ACTION_VIEW);
                                    viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*");
                                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                                    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                                    shareIntent.setType("image/*");
                                    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                                    PendingIntent viewImagePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(),
                                            viewImageIntent, 0);
                                    PendingIntent sharePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(),
                                            shareIntent, 0);
                                    notificationComplete.setContentTitle(getString(R.string.download_complete))
                                            .setSmallIcon(R.drawable.icon_desaturated)
                                            .setContentText(String.format(getString(R.string.download_progress),
                                                    downloaded))
                                            .setContentIntent(viewImagePendingIntent)
                                            .addAction(R.drawable.dark_social_share, getString(R.string.share),
                                                    sharePendingIntent);
                                } else {
                                    Intent i = new Intent(Intent.ACTION_PICK);
                                    i.setDataAndType(
                                            Uri.fromFile(new File(
                                                    android.os.Environment.getExternalStoragePublicDirectory(
                                                            Environment.DIRECTORY_PICTURES) + albumName)),
                                            "image/*");
                                    PendingIntent viewImagePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(), i, 0);
                                    notificationComplete.setContentTitle(getString(R.string.download_complete))
                                            .setSmallIcon(R.drawable.icon_desaturated).setContentText(String
                                                    .format(getString(R.string.download_progress), downloaded))
                                            .setContentIntent(viewImagePendingIntent);
                                }
                                notificationManager.cancel(0);
                                notificationManager.cancel(1);
                                notificationManager.notify(1, notificationComplete.build());
                            }
                            MediaScannerConnection.scanFile(getApplicationContext(),
                                    new String[] { android.os.Environment.getExternalStoragePublicDirectory(
                                            Environment.DIRECTORY_PICTURES) + albumName + id + "." + type },
                                    null, new MediaScannerConnection.OnScanCompletedListener() {
                                        @Override
                                        public void onScanCompleted(final String path, final Uri uri) {
                                            Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path,
                                                    uri.toString()));
                                        }
                                    });
                        }
                    });
            notificationManager.notify(0, notificationBuilder.build());
        } catch (JSONException e) {
            Log.e("Error!", e.toString());
        }
    }
}

From source file:com.geekytheory.miguelcatalandev.developerdays.Main_Fragment_Social.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    final Tweet tweet = tweets.get(position - 1);
    String url = "https://twitter.com/" + tweet.getUserNick() + "/status/" + tweet.getTweetUrl();

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));//from  w  w  w .  ja va 2s . com
    startActivity(intent);
}

From source file:bolts.AppLinkTest.java

public void testGeneralMeasurementEventsBroadcast() throws Exception {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    i.putExtra("foo", "bar");
    ArrayList<String> arr = new ArrayList<>();
    arr.add("foo2");
    arr.add("bar2");
    i.putExtra("foobar", arr);
    Map<String, String> other = new HashMap<>();
    other.put("yetAnotherFoo", "yetAnotherBar");

    final CountDownLatch lock = new CountDownLatch(1);
    final String[] receivedStrings = new String[5];
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext());
    manager.registerReceiver(new BroadcastReceiver() {
        @Override/*from w w  w  .j  a  v  a 2  s  . c  o  m*/
        public void onReceive(Context context, Intent intent) {
            String eventName = intent.getStringExtra("event_name");
            Bundle eventArgs = intent.getBundleExtra("event_args");
            receivedStrings[0] = eventName;
            receivedStrings[1] = eventArgs.getString("foo");
            receivedStrings[2] = eventArgs.getString("foobar");
            receivedStrings[3] = eventArgs.getString("yetAnotherFoo");
            receivedStrings[4] = eventArgs.getString("intentData");
            lock.countDown();
        }
    }, new IntentFilter("com.parse.bolts.measurement_event"));

    MeasurementEvent.sendBroadcastEvent(getInstrumentation().getTargetContext(), "myEventName", i, other);
    lock.await(2000, TimeUnit.MILLISECONDS);

    assertEquals("myEventName", receivedStrings[0]);
    assertEquals("bar", receivedStrings[1]);
    assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]);
    assertEquals("yetAnotherBar", receivedStrings[3]);
    assertEquals("http://www.example.com", receivedStrings[4]);
}

From source file:de.geeksfactory.opacclient.frontend.AccountEditActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(getLayoutResource());

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    etLabel = (EditText) findViewById(R.id.etLabel);
    etName = (EditText) findViewById(R.id.etName);
    etPassword = (EditText) findViewById(R.id.etPassword);

    AccountDataSource data = new AccountDataSource(this);
    data.open();/*from w  ww  . j a va  2  s  .c  o  m*/
    account = data.getAccount(getIntent().getLongExtra(EXTRA_ACCOUNT_ID, -1));

    if (account == null) {
        finish();
        return;
    }

    data.close();

    if (account.getLabel().equals(getString(R.string.default_account_name))) {
        etLabel.setText("");
    } else {
        etLabel.setText(account.getLabel());
    }
    etName.setText(account.getName());
    etPassword.setText(account.getPassword());

    try {
        lib = ((OpacClient) getApplication()).getLibrary(account.getLibrary());
        if (findViewById(R.id.tvCity) != null) {
            TextView tvCity = (TextView) findViewById(R.id.tvCity);
            tvCity.setText(lib.getDisplayName());
        }

        if (lib.getReplacedBy() != null && findViewById(R.id.rlReplaced) != null) {
            findViewById(R.id.rlReplaced).setVisibility(View.VISIBLE);
            findViewById(R.id.ivReplacedStore).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        Intent i = new Intent(Intent.ACTION_VIEW,
                                Uri.parse("market://details?id=" + lib.getReplacedBy()));
                        startActivity(i);
                    } catch (ActivityNotFoundException e) {
                        Log.i("play", "no market installed");
                    }
                }
            });
        } else if (findViewById(R.id.rlReplaced) != null) {
            findViewById(R.id.rlReplaced).setVisibility(View.GONE);
        }
        try {
            if (!lib.getData().getString("baseurl").contains("https") && findViewById(R.id.no_ssl) != null
                    && lib.isAccountSupported()) {
                findViewById(R.id.no_ssl).setVisibility(View.VISIBLE);
            } else if (findViewById(R.id.no_ssl) != null) {
                findViewById(R.id.no_ssl).setVisibility(View.GONE);
            }
        } catch (Exception e) {

        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        ErrorReporter.handleException(e);
        e.printStackTrace();
    }
}