Example usage for android.app Activity startActivityForResult

List of usage examples for android.app Activity startActivityForResult

Introduction

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

Prototype

public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) 

Source Link

Document

Same as calling #startActivityForResult(Intent,int,Bundle) with no options.

Usage

From source file:it.geosolutions.geocollect.android.map.GeoCollectMapActivity.java

/**
 * Display a confirm prompt before logging out the user
 *//* www.  ja v  a 2  s .  c  o m*/
public static void confirmLogout(final Activity act) {
    final Context ctx = act.getBaseContext();
    new AlertDialog.Builder(act).setTitle(R.string.action_logout).setMessage(R.string.button_confirm_logout)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                    //clear user data
                    final Editor ed = PreferenceManager.getDefaultSharedPreferences(ctx).edit();

                    ed.putString(LoginActivity.PREFS_USER_EMAIL, null);
                    ed.putString(LoginActivity.PREFS_USER_FORENAME, null);
                    ed.putString(LoginActivity.PREFS_USER_SURNAME, null);
                    ed.putString(LoginActivity.PREFS_PASSWORD, null);
                    ed.putString(LoginActivity.PREFS_AUTH_KEY, null);
                    ed.putString(LoginActivity.PREFS_USER_ENTE, null);

                    ed.commit();

                    Toast.makeText(ctx, ctx.getString(R.string.logout_logged_out), Toast.LENGTH_LONG).show();

                    if (act != null) {
                        act.startActivityForResult(new Intent(ctx, LoginActivity.class),
                                LoginActivity.REQUEST_LOGIN);
                    }

                }
            }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // do nothing
                }
            }).show();
}

From source file:at.flack.SMSMainActivity.java

public void openMessageActivity(Activity activity, int arg2) {
    if (MainActivity.getContacts() == null)
        return;// w ww . ja v a  2s . c  om
    if (arg2 < 0)
        return;
    Intent smsIntent = new Intent(activity, MessageOverview.class);
    smsIntent.putExtra("CONTACT_NUMBER", MainActivity.getContacts().get(arg2).mAddress);
    smsIntent.putExtra("CONTACT_NAME", MainActivity.getListItems().get(arg2).getTitle());
    smsIntent.putExtra("CONTACT_ID", MainActivity.getContacts().get(arg2).mThreadID);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Bitmap temp = MainActivity.getContacts().get(arg2).fetchThumbnail(activity);
    if (temp != null) {
        temp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] bytes = stream.toByteArray();

        smsIntent.putExtra("profilePicture", bytes);
    }
    try {
        KeyEntity key = KeySafe.getInstance(activity)
                .get(PhoneNumberUtils.formatNumber(MainActivity.getContacts().get(arg2).mAddress));
        if (key != null && key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY)
            smsIntent.putExtra("CONTACT_KEY", key);
    } catch (NullPointerException e) {
    }

    activity.startActivityForResult(smsIntent, 2);
}

From source file:at.flack.activity.NewSMSContactActivity.java

public void openMessageActivity(Activity activity, int arg2) {
    if (arg2 < 0)
        return;//from  ww w .  jav  a  2s  . c o  m
    Intent smsIntent = new Intent(activity, MessageOverview.class);
    ContactAdapter adapter = ((ContactAdapter) ((HeaderViewListAdapter) contactList.getAdapter())
            .getWrappedAdapter());
    smsIntent.putExtra("CONTACT_NUMBER", ((ContactModel) adapter.getItem(arg2)).getLastMessage());
    smsIntent.putExtra("CONTACT_NAME", ((ContactModel) (adapter.getItem(arg2))).getTitle());
    smsIntent.putExtra("CONTACT_ID", ((ContactModel) (adapter.getItem(arg2))).getThreadID());

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Bitmap temp = ((ContactModel) (adapter.getItem(arg2))).getPicture();
    if (temp != null) {
        temp.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] bytes = stream.toByteArray();

        smsIntent.putExtra("profilePicture", bytes);
    }
    try {
        KeyEntity key = KeySafe.getInstance(this)
                .get(PhoneNumberUtils.formatNumber(contacts.get(arg2).getLastMessage()));
        if (key != null)
            smsIntent.putExtra("CONTACT_KEY", key);
    } catch (NullPointerException e) {
    }
    activity.startActivityForResult(smsIntent, 2);
}

From source file:org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationsPlugin.java

@Override
public AlertDialog getErrorDialog(final Activity deviceActivity) {

    if (Build.VERSION.SDK_INT < 18) {
        return new AlertDialog.Builder(deviceActivity).setTitle(R.string.pref_plugin_notifications)
                .setMessage(R.string.plugin_not_available)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override//from w w  w .ja  v  a2 s.  c o m
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                }).create();
    } else {
        return new AlertDialog.Builder(deviceActivity).setTitle(R.string.pref_plugin_notifications)
                .setMessage(R.string.no_permissions)
                .setPositiveButton(R.string.open_settings, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
                        deviceActivity.startActivityForResult(intent, MaterialActivity.RESULT_NEEDS_RELOAD);
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //Do nothing
                    }
                }).create();
    }
}

From source file:org.gateshipone.odyssey.views.NowPlayingView.java

/**
 * Menu click listener. This method gets called when the user selects an item of the popup menu (right top corner).
 *
 * @param item MenuItem that was clicked.
 * @return Returns true if the item was handled by this method. False otherwise.
 *//*from  w w  w .  j ava  2  s  .  co  m*/
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.view_nowplaying_action_shuffleplaylist:
        try {
            mServiceConnection.getPBS().shufflePlaylist();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;
    case R.id.view_nowplaying_action_clearplaylist:
        try {
            mServiceConnection.getPBS().clearPlaylist();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;
    case R.id.view_nowplaying_action_saveplaylist:
        // open dialog in order to save the current playlist as a playlist in the mediastore
        ChoosePlaylistDialog choosePlaylistDialog = new ChoosePlaylistDialog();
        choosePlaylistDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(),
                "ChoosePlaylistDialog");
        return true;
    case R.id.view_nowplaying_action_createbookmark:
        // open dialog in order to save the current playlist as a bookmark in the odyssey db
        ChooseBookmarkDialog chooseBookmarkDialog = new ChooseBookmarkDialog();
        chooseBookmarkDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(),
                "ChooseBookmarkDialog");
        return true;
    case R.id.view_nowplaying_action_startequalizer:
        // start the audio equalizer
        Activity activity = (Activity) getContext();
        if (activity != null) {
            Intent startEqualizerIntent = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);

            try {
                activity.startActivityForResult(startEqualizerIntent, 0);
            } catch (ActivityNotFoundException e) {
                ErrorDialog equalizerNotFoundDlg = ErrorDialog.newInstance(
                        R.string.dialog_equalizer_not_found_title, R.string.dialog_equalizer_not_found_message);
                equalizerNotFoundDlg.show(((AppCompatActivity) getContext()).getSupportFragmentManager(),
                        "EqualizerNotFoundDialog");
            }
        }
        return true;
    default:
        return false;
    }
}

From source file:org.onepf.oms.appstore.SamsungAppsBillingService.java

@Override
public void launchPurchaseFlow(Activity activity, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    String itemGroupId = getItemGroupId(sku);
    String itemId = getItemId(sku);

    Bundle bundle = new Bundle();
    bundle.putString(KEY_NAME_THIRD_PARTY_NAME, activity.getPackageName());
    bundle.putString(KEY_NAME_ITEM_GROUP_ID, itemGroupId);
    bundle.putString(KEY_NAME_ITEM_ID, itemId);
    if (isDebugLog())
        Log.d(TAG, "launchPurchase: itemGroupId = " + itemGroupId + ", itemId = " + itemId);
    ComponentName cmpName = new ComponentName(SamsungApps.IAP_PACKAGE_NAME, PAYMENT_ACTIVITY_NAME);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setComponent(cmpName);//from www  . java 2  s.  c o m
    intent.putExtras(bundle);
    mRequestCode = requestCode;
    mPurchaseListener = listener;
    purchasingItemType = itemType;
    mItemGroupId = itemGroupId;
    mExtraData = extraData;
    if (isDebugLog())
        Log.d(TAG, "Request code: " + requestCode);
    activity.startActivityForResult(intent, requestCode);
}

From source file:org.cryptsecure.Utility.java

/**
 * Select attachment./*from ww w.j  a  va  2s .  co m*/
 * 
 * @param activity
 *            the activity
 */
public static void selectFromGallery(Activity activity) {
    Intent intent = new Intent();
    if (Build.VERSION.SDK_INT >= 19) {
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        activity.startActivityForResult(Intent.createChooser(intent, "Select Attachment"),
                Utility.SELECT_PICTURE);

    } else {
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);
        activity.startActivityForResult(Intent.createChooser(intent, "Select Attachment"),
                Utility.SELECT_PICTURE);
    }
}

From source file:at.flack.MailMainActivity.java

public void openMessageActivity(Activity activity, int arg2) {
    if (arg2 < 0 || MainActivity.getMailcontacts() == null || MainActivity.getMailcontacts().size() == 0)
        return;//from w w w  . j  a  v  a2 s . c om

    Intent mailIntent = new Intent(activity, MailOverview.class);
    mailIntent.putExtra("CONTACT_MAIL", MainActivity.getMailItems().get(arg2).getFromMail());
    mailIntent.putExtra("CONTACT_NAME", MainActivity.getMailItems().get(arg2).getFromName());
    mailIntent.putExtra("MY_MAIL", MainActivity.getMailItems().get(arg2).getToMail());

    mailIntent.putExtra("profilePicture", MainActivity.getMailItems().get(arg2).getPicture());

    mailIntent.putExtra("MAIL_TEXT", MainActivity.getMailItems().get(arg2).getLastMessage());
    mailIntent.putExtra("MAIL_TITLE", MainActivity.getMailItems().get(arg2).getTitle());
    mailIntent.putExtra("MAIL_DATE", MainActivity.getMailItems().get(arg2).getDate().toString());

    try {
        KeyEntity key = KeySafe.getInstance(activity).get(MainActivity.getMailItems().get(arg2).getFromMail());
        if (key != null && key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY)
            mailIntent.putExtra("CONTACT_KEY", key);
    } catch (NullPointerException e) {
    }

    activity.startActivityForResult(mailIntent, 2);
}

From source file:org.ubicompforall.cityexplorer.CityExplorer.java

/***
 * Ping Google/* w ww  .j a  v  a 2 s  .co m*/
 * Start a browser if the page contains a (log-in) "redirect="
 */
public static boolean pingConnection(Activity context, String url) {
    boolean urlAvailable = false;
    if (ensureConnected(context)) {
        showProgressDialog(context);
        HttpClient httpclient = new DefaultHttpClient();
        try {
            HttpResponse response = httpclient.execute(new HttpGet(url));
            StatusLine statusLine = response.getStatusLine();
            debug(2, "statusLine is " + statusLine);

            // HTTP status is OK even if not logged in to NTNU
            //Toast.makeText( context, "Status-line is "+statusLine, Toast.LENGTH_LONG).show();
            if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                String responseString = out.toString();
                if (responseString.contains("redirect=")) { // Connection to url should be checked.
                    debug(2, "Redirect detected for url: " + url);
                    //Toast.makeText( context, "Mismatched url: "+url, Toast.LENGTH_LONG).show();
                } else {
                    urlAvailable = true;
                } // if redirect page, else probably OK
            } else {//if status OK, else: Closes the connection on failure
                response.getEntity().getContent().close();
            } //if httpStatus OK, else close

            //Start browser to log in
            if (!urlAvailable) {
                //throw new IOException( statusLine.getReasonPhrase() );

                //String activity = Thread.currentThread().getStackTrace()[3].getClassName();
                Toast.makeText(context, "Web access needed! Are you logged in?", Toast.LENGTH_LONG).show();
                //Uri uri = Uri.parse( url +"#"+ context.getClass().getCanonicalName() );
                Uri uri = Uri.parse(url + "?activity=" + context.getClass().getCanonicalName());
                debug(0, "Pinging magic url: " + uri);
                debug(0, " Need the web for uri: " + uri);
                context.startActivityForResult(new Intent(Intent.ACTION_VIEW, uri), REQUEST_KILL_BROWSER);
                //urlAvailable=true;
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) { // Caused by bad url for example, missing http:// etc. Can still use cached maps...
            urlAvailable = false;
            debug(0, "Missing http:// in " + url + " ?");
        } catch (IOException e) { // e.g. UnknownHostException // try downloading db's from the Web, catch (and print) exceptions
            e.printStackTrace();
            urlAvailable = false;
        }
    } // if not already loaded once before
    return urlAvailable;
}

From source file:org.cryptsecure.Utility.java

/**
 * Take photo./*from w  w w  .jav  a 2 s .  c  o m*/
 * 
 * @param activity
 *            the activity
 */
public static void takePhoto(Activity activity) {
    if (!Utility.isCameraAvailable(activity)) {
        Utility.showToastAsync(activity, "No camera available.");
        return;
    }
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    activity.startActivityForResult(cameraIntent, TAKE_PHOTO);
}