Example usage for android.app Activity RESULT_CANCELED

List of usage examples for android.app Activity RESULT_CANCELED

Introduction

In this page you can find the example usage for android.app Activity RESULT_CANCELED.

Prototype

int RESULT_CANCELED

To view the source code for android.app Activity RESULT_CANCELED.

Click Source Link

Document

Standard activity result: operation canceled.

Usage

From source file:org.apache.cordova.X5CordovaInterfaceImpl.java

@Override
public void setActivityResultCallback(X5CordovaPlugin plugin) {
    // Cancel any previously pending activity.
    if (activityResultCallback != null) {
        activityResultCallback.onActivityResult(activityResultRequestCode, Activity.RESULT_CANCELED, null);
    }// w  ww .jav a 2 s  .  co  m
    activityResultCallback = plugin;
}

From source file:info.guardianproject.iocipher.camera.StillCameraActivity.java

@Override
public void onPictureTaken(final byte[] data, Camera camera) {
    File fileSecurePicture;//from   www  . java  2s.c o m
    try {

        if (overlayView != null)
            overlayView.setBackgroundResource(R.color.flash);

        notifyUserImageWasSavedSuccessfully();
        long mTime = System.currentTimeMillis();
        fileSecurePicture = new File(mFileBasePath, "secure_image_" + mTime + ".jpg");

        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileSecurePicture));
        out.write(data);
        out.flush();
        out.close();

        mResultList.add(fileSecurePicture.getAbsolutePath());

        Intent intent = new Intent("new-media");
        // You can also include some extra data.
        intent.putExtra("media", fileSecurePicture.getAbsolutePath());
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

        Intent intentResult = new Intent().putExtra(MediaStore.EXTRA_OUTPUT,
                mResultList.toArray(new String[mResultList.size()]));
        setResult(Activity.RESULT_OK, intentResult);

        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                overlayView.setBackgroundColor(Color.TRANSPARENT);

                resumePreview();
            }
        }, 300);

    } catch (Exception e) {
        e.printStackTrace();
        setResult(Activity.RESULT_CANCELED);

    }

}

From source file:ca.rmen.android.networkmonitor.app.dbops.ui.Share.java

/**
 * Prompt a user for the field they want to export to KML, then do the export.
 *///from   w  w w  . ja  va 2 s  . c  om
private static void shareKml(final FragmentActivity activity) {
    Log.v(TAG, "shareKml");

    PreferenceDialog.showKMLExportColumnChoiceDialog(activity,
            new PreferenceDialog.PreferenceChoiceDialogListener() {

                @Override
                public void onPreferenceValueSelected(String value) {
                    KMLExport kmlExport = new KMLExport(activity, value);
                    shareFile(activity, kmlExport);
                }

                @Override
                public void onCancel() {
                    activity.setResult(Activity.RESULT_CANCELED);
                    activity.finish();
                }
            });
}

From source file:org.mifos.androidclient.templates.DownloaderActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case LoginActivity.REQUEST_CODE:
        switch (resultCode) {
        case Activity.RESULT_OK:
            break;
        case Activity.RESULT_CANCELED:
            finish();// w  ww .  j a  v  a  2s .c o m
            break;
        default:
            break;
        }
        break;
    default:
        break;
    }
}

From source file:com.android.gallery3d.gadget.WidgetConfigure.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    if (mAppWidgetId == -1) {
        setResult(Activity.RESULT_CANCELED);
        finish();/*  ww  w .  j  a va  2 s. c o  m*/
        return;
    }

    if (savedState == null) {
        if (ApiHelper.HAS_REMOTE_VIEWS_SERVICE) {
            Intent intent = new Intent(this, WidgetTypeChooser.class);
            startActivityForResult(intent, REQUEST_WIDGET_TYPE);
        } else { // Choose the photo type widget
            setWidgetType(new Intent().putExtra(KEY_WIDGET_TYPE, R.id.widget_type_photo));
        }
    } else {
        mPickedItem = savedState.getParcelable(KEY_PICKED_ITEM);
    }
}

From source file:com.android.browser.UploadHandler.java

private Uri[] parseResult(int resultCode, Intent intent) {
    if (resultCode == Activity.RESULT_CANCELED) {
        return null;
    }//from   ww w  . j av a  2 s. com
    Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();

    // As we ask the camera to save the result of the user taking
    // a picture, the camera application does not return anything other
    // than RESULT_OK. So we need to check whether the file we expected
    // was written to disk in the in the case that we
    // did not get an intent returned but did get a RESULT_OK. If it was,
    // we assume that this result has came back from the camera.
    if (result == null && intent == null && resultCode == Activity.RESULT_OK && mCapturedMedia != null) {
        result = mCapturedMedia;
    }

    Uri[] uris = null;
    if (result != null) {
        uris = new Uri[1];
        uris[0] = result;
    }
    return uris;
}

From source file:com.money.manager.ex.common.MmxBaseFragmentActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // home click can be handled in the manifest by setting up the parent activity.
    case android.R.id.home:
        // This is used to handle the <- Home arrow button in the toolbar.
        //                NavUtils.navigateUpFromSameTask(this);
        //                return true;
        if (mDisplayHomeAsUpEnabled) {
            setResult(Activity.RESULT_CANCELED);
            finish();/*from w ww.j  a v a 2 s . co  m*/
            return true;
        }

        //            case R.id.menu_cancel:
        //                if (isDialogMode()) {
        //                    onActionCancelClick();
        //                    return true;
        //                }
        //            case R.id.menu_done:
        //                if (isDialogMode()) {
        //                    onActionDoneClick();
        //                    return true;
        //                }
        //
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.opendatakit.survey.android.activities.MediaChooseAudioActivity.java

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

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        appName = extras.getString(APP_NAME);
        uriFragmentNewFileBase = extras.getString(URI_FRAGMENT_NEW_FILE_BASE);
    }//from w  ww. j  a v a  2s  .  c  o  m

    if (savedInstanceState != null) {
        appName = savedInstanceState.getString(APP_NAME);
        uriFragmentNewFileBase = savedInstanceState.getString(URI_FRAGMENT_NEW_FILE_BASE);
    }

    if (appName == null) {
        throw new IllegalArgumentException("Expected " + APP_NAME + " key in intent bundle. Not found.");
    }

    if (uriFragmentNewFileBase == null) {
        throw new IllegalArgumentException(
                "Expected " + URI_FRAGMENT_NEW_FILE_BASE + " key in intent bundle. Not found.");
    }

    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType(MEDIA_CLASS + "*");
    try {
        startActivityForResult(i, ACTION_CODE);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this,
                getString(R.string.activity_not_found, Intent.ACTION_GET_CONTENT + " " + MEDIA_CLASS),
                Toast.LENGTH_SHORT).show();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }
}

From source file:com.sip.pwc.sipphone.service.Downloader.java

@Override
protected void onHandleIntent(Intent intent) {
    HttpGet getMethod = new HttpGet(intent.getData().toString());
    int result = Activity.RESULT_CANCELED;
    String outPath = intent.getStringExtra(EXTRA_OUTPATH);
    boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false);
    int icon = intent.getIntExtra(EXTRA_ICON, 0);
    String title = intent.getStringExtra(EXTRA_TITLE);
    boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title));

    // Build notification
    Builder nb = new Builder(this);
    nb.setWhen(System.currentTimeMillis());
    nb.setContentTitle(title);/*from   w  w  w . j av a2s  .c o m*/
    nb.setSmallIcon(android.R.drawable.stat_sys_download);
    nb.setOngoing(true);
    Intent i = new Intent(this, SipHome.class);
    nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.download_notif);
    contentView.setImageViewResource(R.id.status_icon, icon);
    contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text));
    contentView.setProgressBar(R.id.status_progress, 50, 0, false);
    contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE);
    nb.setContent(contentView);

    final Notification notification = showNotif ? nb.build() : null;
    notification.contentView = contentView;
    if (!TextUtils.isEmpty(outPath)) {
        try {
            File output = new File(outPath);
            if (output.exists()) {
                output.delete();
            }

            if (notification != null) {
                notificationManager.notify(NOTIF_DOWNLOAD, notification);
            }
            ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() {
                private int oldState = 0;

                @Override
                public void run(long progress, long total) {
                    //Log.d(THIS_FILE, "Progress is "+progress+" on "+total);
                    int newState = (int) Math.round(progress * 50.0f / total);
                    if (oldState != newState) {

                        notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false);
                        notificationManager.notify(NOTIF_DOWNLOAD, notification);
                        oldState = newState;
                    }

                }
            });
            boolean hasReply = client.execute(getMethod, responseHandler);

            if (hasReply) {

                if (checkMd5) {
                    URL url = new URL(intent.getData().toString().concat(".md5sum"));
                    InputStream content = (InputStream) url.getContent();
                    if (content != null) {
                        BufferedReader br = new BufferedReader(new InputStreamReader(content));
                        String downloadedMD5 = "";
                        try {
                            downloadedMD5 = br.readLine().split("  ")[0];
                        } catch (NullPointerException e) {
                            throw new IOException("md5_verification : no sum on server");
                        }
                        if (!MD5.checkMD5(downloadedMD5, output)) {
                            throw new IOException("md5_verification : incorrect");
                        }
                    }
                }
                PendingIntent pendingIntent = (PendingIntent) intent
                        .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT);

                try {
                    Runtime.getRuntime().exec("chmod 644 " + outPath);
                } catch (IOException e) {
                    Log.e(THIS_FILE, "Unable to make the apk file readable", e);
                }

                Log.d(THIS_FILE, "Download finished of : " + outPath);
                if (pendingIntent != null) {

                    notification.contentIntent = pendingIntent;
                    notification.flags = Notification.FLAG_AUTO_CANCEL;
                    notification.icon = android.R.drawable.stat_sys_download_done;
                    notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE);
                    notification.contentView.setTextViewText(R.id.status_text,
                            getResources().getString(R.string.done)
                                    // TODO should be a parameter of this class
                                    + " - Click to install");
                    notificationManager.notify(NOTIF_DOWNLOAD, notification);

                    /*
                    try {
                       pendingIntent.send();
                         notificationManager.cancel(NOTIF_DOWNLOAD);
                    } catch (CanceledException e) {
                       Log.e(THIS_FILE, "Impossible to start pending intent for download finish");
                    }
                    */
                } else {
                    Log.w(THIS_FILE, "Invalid pending intent for finish !!!");
                }

                result = Activity.RESULT_OK;
            }
        } catch (IOException e) {
            Log.e(THIS_FILE, "Exception in download", e);
        }
    }

    if (result == Activity.RESULT_CANCELED) {
        notificationManager.cancel(NOTIF_DOWNLOAD);
    }
}

From source file:com.sonetel.service.Downloader.java

@Override
protected void onHandleIntent(Intent intent) {
    HttpGet getMethod = new HttpGet(intent.getData().toString());
    int result = Activity.RESULT_CANCELED;
    String outPath = intent.getStringExtra(EXTRA_OUTPATH);
    boolean checkMd5 = intent.getBooleanExtra(EXTRA_CHECK_MD5, false);
    int icon = intent.getIntExtra(EXTRA_ICON, 0);
    String title = intent.getStringExtra(EXTRA_TITLE);
    boolean showNotif = (icon > 0 && !TextUtils.isEmpty(title));

    // Build notification
    Builder nb = new NotificationCompat.Builder(this);
    nb.setWhen(System.currentTimeMillis());
    nb.setContentTitle(title);//from w  ww . j a va 2  s  .co m
    nb.setSmallIcon(android.R.drawable.stat_sys_download);
    nb.setOngoing(true);
    Intent i = new Intent(this, SipHome.class);
    nb.setContentIntent(PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT));

    RemoteViews contentView = new RemoteViews(getApplicationContext().getPackageName(),
            R.layout.download_notif);
    contentView.setImageViewResource(R.id.status_icon, icon);
    contentView.setTextViewText(R.id.status_text, getResources().getString(R.string.downloading_text));
    contentView.setProgressBar(R.id.status_progress, 50, 0, false);
    contentView.setViewVisibility(R.id.status_progress_wrapper, View.VISIBLE);
    nb.setContent(contentView);

    final Notification notification = showNotif ? nb.getNotification() : null;
    notification.contentView = contentView;
    if (!TextUtils.isEmpty(outPath)) {
        try {
            File output = new File(outPath);
            if (output.exists()) {
                output.delete();
            }

            if (notification != null) {
                notificationManager.notify(NOTIF_DOWNLOAD, notification);
            }
            ResponseHandler<Boolean> responseHandler = new FileStreamResponseHandler(output, new Progress() {
                private int oldState = 0;

                @Override
                public void run(long progress, long total) {
                    //Log.d(THIS_FILE, "Progress is "+progress+" on "+total);
                    int newState = (int) Math.round(progress * 50.0f / total);
                    if (oldState != newState) {

                        notification.contentView.setProgressBar(R.id.status_progress, 50, newState, false);
                        notificationManager.notify(NOTIF_DOWNLOAD, notification);
                        oldState = newState;
                    }

                }
            });
            boolean hasReply = client.execute(getMethod, responseHandler);

            if (hasReply) {

                if (checkMd5) {
                    URL url = new URL(intent.getData().toString().concat(".md5sum"));
                    InputStream content = (InputStream) url.getContent();
                    if (content != null) {
                        BufferedReader br = new BufferedReader(new InputStreamReader(content));
                        String downloadedMD5 = "";
                        try {
                            downloadedMD5 = br.readLine().split("  ")[0];
                        } catch (NullPointerException e) {
                            throw new IOException("md5_verification : no sum on server");
                        }
                        if (!MD5.checkMD5(downloadedMD5, output)) {
                            throw new IOException("md5_verification : incorrect");
                        }
                    }
                }
                PendingIntent pendingIntent = (PendingIntent) intent
                        .getParcelableExtra(EXTRA_PENDING_FINISH_INTENT);

                try {
                    Runtime.getRuntime().exec("chmod 644 " + outPath);
                } catch (IOException e) {
                    Log.e(THIS_FILE, "Unable to make the apk file readable", e);
                }

                Log.d(THIS_FILE, "Download finished of : " + outPath);
                if (pendingIntent != null) {

                    notification.contentIntent = pendingIntent;
                    notification.flags = Notification.FLAG_AUTO_CANCEL;
                    notification.icon = android.R.drawable.stat_sys_download_done;
                    notification.contentView.setViewVisibility(R.id.status_progress_wrapper, View.GONE);
                    notification.contentView.setTextViewText(R.id.status_text,
                            getResources().getString(R.string.done)
                                    // TODO should be a parameter of this class
                                    + " - Click to install");
                    notificationManager.notify(NOTIF_DOWNLOAD, notification);

                    /*
                    try {
                       pendingIntent.send();
                         notificationManager.cancel(NOTIF_DOWNLOAD);
                    } catch (CanceledException e) {
                       Log.e(THIS_FILE, "Impossible to start pending intent for download finish");
                    }
                    */
                } else {
                    Log.w(THIS_FILE, "Invalid pending intent for finish !!!");
                }

                result = Activity.RESULT_OK;
            }
        } catch (IOException e) {
            Log.e(THIS_FILE, "Exception in download", e);
        }
    }

    if (result == Activity.RESULT_CANCELED) {
        notificationManager.cancel(NOTIF_DOWNLOAD);
    }
}