Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

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

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:com.galois.qrstream.lib.DecodeThread.java

private Intent buildIntent(Job message) throws IOException {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_SEND);//from   w  w w.  j ava2 s .co m
    i.addCategory(Intent.CATEGORY_DEFAULT);
    String mimeType = message.getMimeType();
    i.setType(mimeType);

    if (mimeType.equals("text/plain")) {
        String msg = new String(message.getData());
        i.putExtra(Intent.EXTRA_TEXT, msg);
    } else {
        // content that is not text uses the filesystem to store the data
        // (when sharing with a new local app)
        File dataLoc = storeData(message);

        if (mimeType.startsWith("image/")) {
            String path = Images.Media.insertImage(context.getContentResolver(), dataLoc.getPath(),
                    message.getTitle(), null);
            Uri imageUri = Uri.parse(path);
            i.putExtra(Intent.EXTRA_STREAM, imageUri);

            // we can delete the temporary location in this case, since the file has been saved
            // to the media store.
            // In the other cases, the receiver has to handle the content of the temp file before
            // it can be deleted -- but we will never know if/when that happens.
            dataLoc.delete();
        } else if (mimeType.equals(Constants.MIME_TYPE_TEXT_NOTE)) {
            String json = new String(message.getData());
            try {
                JSONObject note = new JSONObject(json);
                i.putExtra(Intent.EXTRA_TEXT, note.getString(Intent.EXTRA_TEXT));
                i.putExtra(Intent.EXTRA_SUBJECT, note.getString(Intent.EXTRA_SUBJECT));
                i.setType("text/plain");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            i.putExtra(Intent.EXTRA_STREAM, dataLoc.toURI());
        }
    }
    return i;
}

From source file:com.partypoker.poker.engagement.reach.EngagementAnnouncement.java

@Override
Intent buildIntent() {//from w  ww  . j a v  a2 s.c  om
    Intent intent = new Intent(INTENT_ACTION);
    intent.setType(getType());
    String category = getCategory();
    if (category != null)
        intent.addCategory(category);
    return intent;
}

From source file:com.oakesville.mythling.MainActivity.java

public void onBackPressed() {
    if (EpgActivity.class.getName().equals(backTo) || FireTvEpgActivity.class.getName().equals(backTo)) {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);//  w w w.  java  2  s  .  co  m
    } else {
        super.onBackPressed();
    }
}

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

private void showFilerChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {/* w  w  w  .  j a  v  a2 s  .c o m*/
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(getActivity(), R.string.fail_file_chooser, Toast.LENGTH_LONG).show();
    }
}

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherService.java

private void patchFile(Bundle data) {
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resultIntent.setAction(Intent.ACTION_MAIN);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);

    final Notification.Builder builder = new Notification.Builder(this);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setOngoing(true);/*from  ww w.j  a  v a 2 s  . co m*/
    builder.setContentTitle(getString(R.string.overall_progress));
    builder.setContentIntent(pendingIntent);
    builder.setProgress(0, 0, true);

    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(1, builder.build());

    Patcher.ProgressListener listener = new Patcher.ProgressListener() {
        @Override
        public void onProgressUpdated(long bytes, long maxBytes) {
            updateProgress(bytes, maxBytes);
        }

        @Override
        public void onFilesUpdated(long files, long maxFiles) {
            builder.setContentText(String.format(getString(R.string.overall_progress_files), files, maxFiles));
            builder.setProgress((int) maxFiles, (int) files, false);
            nm.notify(1, builder.build());

            updateFiles(files, maxFiles);
        }

        @Override
        public void onDetailsUpdated(String text) {
            updateDetails(text);
        }
    };

    Bundle result = PatcherUtils.patchFile(this, data, listener);

    if (result != null) {
        String newFile = result.getString(PatcherUtils.RESULT_PATCH_FILE_NEW_FILE);
        int errorCode = result.getInt(PatcherUtils.RESULT_PATCH_FILE_ERROR_CODE);
        boolean failed = result.getBoolean(PatcherUtils.RESULT_PATCH_FILE_FAILED);
        onPatchedFile(failed, errorCode, newFile);
    }

    nm.cancel(1);
}

From source file:com.jingle.zxing.plugin.BarcodeScanner.java

/**
 * Starts an intent to scan and decode a barcode.
 *//*  w  w w .  jav a  2s  .  c om*/
public void scan(String mode) {
    Intent intentScan = new Intent();
    intentScan.setClass(this.cordova.getActivity(), CaptureActivity.class);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);
    intentScan.putExtra(MODE, mode);

    this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, REQUEST_CODE);
}

From source file:com.google.zxing.client.android.plugin.BarcodeScanner.java

/**
 * Starts an intent to scan and decode a barcode.
 * @param mode  PRODUCT_MODE | ONE_D_MODE | QR_CODE_MODE | DATA_MATRIX_MODE 
 *//*from ww  w .j  a  v  a2s .c o  m*/
public void scan(String mode) {
    Intent intentScan = new Intent();
    intentScan.setClass(this.cordova.getActivity(), CaptureActivity.class);
    intentScan.addCategory(Intent.CATEGORY_DEFAULT);
    if (!mode.equals("")) {
        intentScan.putExtra(Intents.Scan.MODE, mode);
    }

    this.cordova.startActivityForResult((CordovaPlugin) this, intentScan, REQUEST_CODE);
}

From source file:com.github.jobs.ui.fragment.JobDetailsFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.company_url:
        Intent companyUrl = new Intent(Intent.ACTION_VIEW);
        companyUrl.addCategory(Intent.CATEGORY_BROWSABLE);
        companyUrl.setData(Uri.parse(mJob.getCompanyUrl()));
        startActivity(companyUrl);/*from  w w w .j  a  va2 s.c o  m*/
        break;
    }
}

From source file:cn.ieclipse.af.demo.MainActivity.java

@Override
public void onCheckSuccess(final CheckUpdateController.CheckResponse info) {
    if (info != null) {
        DialogUtils.showAlert(this, android.R.drawable.ic_dialog_info, "?",
                TextUtils.isEmpty(info.description) ? "???" : info.description,
                new DialogInterface.OnClickListener() {
                    @Override/*from  ww w.ja va 2 s  .co  m*/
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Intent intent = new Intent(Intent.ACTION_VIEW);
                            intent.addCategory(Intent.CATEGORY_BROWSABLE);
                            intent.addCategory(Intent.CATEGORY_DEFAULT);
                            if (info.force) {
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            }
                            intent.setData(Uri.parse(info.downloadLink));
                            startActivityForResult(Intent.createChooser(intent, null), 0x01);
                        } catch (Exception e) {
                            DialogUtils.showToast(getApplicationContext(), "?");
                        } finally {

                        }
                    }
                }, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (info.force) {
                            finish();
                        }
                    }
                });
    }
}

From source file:com.deadpixels.light.clipper.Settings.java

private void showSourceCode() {
    Intent showSourceIntent = new Intent();
    showSourceIntent.setAction(Intent.ACTION_VIEW);
    showSourceIntent.addCategory(Intent.CATEGORY_DEFAULT);
    showSourceIntent.setData(Uri.parse(SOURCE_URL));
    startActivity(showSourceIntent);/*  w  ww .j a  va2 s  . c o m*/
}