Example usage for android.content Intent getStringExtra

List of usage examples for android.content Intent getStringExtra

Introduction

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

Prototype

public String getStringExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.phonegap.plugins.discoverscanar.DiscoverScanAR.java

/**
 * Called when the barcode scanner intent completes.
 *
 * @param requestCode The request code originally supplied to startActivityForResult(),
 *                       allowing you to identify who this result came from.
 * @param resultCode  The integer result code returned by the child activity through its setResult().
 * @param intent      An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 *//* w w w  . ja v a2 s  .  co m*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // logging goes to logcat. LOG.d for debug(), LOG.e for error()
    // http://www.vogella.com/tutorials/AndroidLogging/article.html
    //Log.d(LOG_TAG, "#### onActivityResult");

    if (requestCode == REQUEST_SCAN_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, intent.getStringExtra("SCAN_RESULT"));
                obj.put(FORMAT, intent.getStringExtra("SCAN_RESULT_FORMAT"));
                obj.put(CANCELLED, false);
                this.callbackContext.success(obj);
                Log.e(LOG_TAG, "#### Found text: " + intent.getStringExtra("SCAN_RESULT")
                        + " AND Called callback on success");
            } catch (JSONException e) {
                Log.d(LOG_TAG, "This should never happen");
                this.callbackContext.error("Scan intent. Unexpected error: " + e.getMessage());
            }
            //this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
            //this.callbackContext.success(obj);
        } else if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, "");
                obj.put(FORMAT, "");
                obj.put(CANCELLED, true);

                //Log.e(LOG_TAG, "#### Found no text");

                this.callbackContext.success(obj);
            } catch (JSONException e) {
                Log.d(LOG_TAG, "This should never happen");
                this.callbackContext.error("Scan intent. Unexpected error: " + e.getMessage());
            }
            //this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
            //this.callbackContext.success(obj);
        } else {
            //this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
            this.callbackContext.error("Scan intent. Unexpected error");
        }
    }

    else if (requestCode == REQUEST_ARSCAN_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, intent.getStringExtra("ARSCAN_RESULT"));
                obj.put(CANCELLED, false);
                this.callbackContext.success(obj);
            } catch (JSONException e) {
                Log.d(LOG_TAG, "ARScan intent (RESULT_OK) threw an exception: This should never happen");
                this.callbackContext.error("ARScan intent. Unexpected error: " + e.getMessage());
            }
            //this.callbackContext.success(obj);
        } else if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put(TEXT, "");
                obj.put(CANCELLED, true);
                this.callbackContext.success(obj);
            } catch (JSONException e) {
                Log.d(LOG_TAG, "ARScan intent (RESULT_CANCELED) threw an exception. This should never happen");
                this.callbackContext.error("ARScan intent. Unexpected error: " + e.getMessage());
            }
            //this.callbackContext.success(obj);
        } else {
            //this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
            this.callbackContext.error("ARScan intent. Unexpected error");
        }
    }

}

From source file:com.watch.customer.ui.ShopListActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (resultCode) {
    case RESULT_OK:
        String cityStr = data.getStringExtra("city");
        citytext.setText(cityStr);//  w w  w  .j  a  va2  s .  c om
        SearchBySec();
        break;
    default:
        break;
    }
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

/**
* Determine the messages to display during video load and initialization. 
*///from   ww  w. ja  va  2  s  .  c  o m
private void extractMessages() {
    Intent lInvokingIntent = getIntent();
    String lMsgInit = lInvokingIntent.getStringExtra(MSG_INIT);
    if (lMsgInit != null) {
        mMsgInit = lMsgInit;
    }
    String lMsgDetect = lInvokingIntent.getStringExtra(MSG_DETECT);
    if (lMsgDetect != null) {
        mMsgDetect = lMsgDetect;
    }
    String lMsgPlaylist = lInvokingIntent.getStringExtra(MSG_PLAYLIST);
    if (lMsgPlaylist != null) {
        mMsgPlaylist = lMsgPlaylist;
    }
    String lMsgToken = lInvokingIntent.getStringExtra(MSG_TOKEN);
    if (lMsgToken != null) {
        mMsgToken = lMsgToken;
    }
    String lMsgLoBand = lInvokingIntent.getStringExtra(MSG_LO_BAND);
    if (lMsgLoBand != null) {
        mMsgLowBand = lMsgLoBand;
    }
    String lMsgHiBand = lInvokingIntent.getStringExtra(MSG_HI_BAND);
    if (lMsgHiBand != null) {
        mMsgHiBand = lMsgHiBand;
    }
    String lMsgErrTitle = lInvokingIntent.getStringExtra(MSG_ERROR_TITLE);
    if (lMsgErrTitle != null) {
        mMsgErrorTitle = lMsgErrTitle;
    }
    String lMsgErrMsg = lInvokingIntent.getStringExtra(MSG_ERROR_MSG);
    if (lMsgErrMsg != null) {
        mMsgError = lMsgErrMsg;
    }
}

From source file:com.sharky.BillingService.java

public void handleCommand(Intent intent, int startId) {
    String action = intent.getAction();
    if (Consts.ACTION_CONFIRM_NOTIFICATION.equals(action)) {
        String[] notifyIds = intent.getStringArrayExtra(Consts.NOTIFICATION_ID);
        confirmNotifications(startId, notifyIds);
    } else if (Consts.ACTION_GET_PURCHASE_INFORMATION.equals(action)) {
        String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID);
        getPurchaseInformation(startId, new String[] { notifyId });
    } else if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
        String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA);
        String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE);
        purchaseStateChanged(startId, signedData, signature);
    } else if (Consts.ACTION_RESPONSE_CODE.equals(action)) {
        long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1);
        int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE,
                ResponseCode.RESULT_ERROR.ordinal());
        ResponseCode responseCode = ResponseCode.valueOf(responseCodeIndex);
        checkResponseCode(requestId, responseCode);
    }/*from   www  .  j  av  a2s  .  c om*/
}

From source file:com.shengtao.chat.chatUI.DemoHXSDKHelper.java

/**
 * ?/*w w w.ja v a  2  s .co  m*/
 * ?UI???UI???????
 * activityList.size() <= 0 ????????Activity Stack
 */
protected void initEventListener() {
    eventListener = new EMEventListener() {
        private BroadcastReceiver broadCastReceiver = null;

        @Override
        public void onEvent(EMNotifierEvent event) {
            EMMessage message = null;
            if (event.getData() instanceof EMMessage) {
                message = (EMMessage) event.getData();
                EMLog.d(TAG, "receive the event : " + event.getEvent() + ",id : " + message.getMsgId());
            }

            switch (event.getEvent()) {
            case EventNewMessage:
                //????UI,????
                if (activityList.size() <= 0) {
                    HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
                }
                break;
            case EventOfflineMessage:
                if (activityList.size() <= 0) {
                    EMLog.d(TAG, "received offline messages");
                    List<EMMessage> messages = (List<EMMessage>) event.getData();
                    HXSDKHelper.getInstance().getNotifier().onNewMesg(messages);
                }
                break;
            // below is just giving a example to show a cmd toast, the app should not follow this
            // so be careful of this
            case EventNewCMDMessage: {

                EMLog.d(TAG, "??");
                //??body
                CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
                final String action = cmdMsgBody.action;//?action

                //? ?
                //message.getStringAttribute("");
                EMLog.d(TAG, String.format("??action:%s,message:%s", action, message.toString()));
                final String str = appContext.getString(R.string.receive_the_passthrough);

                final String CMD_TOAST_BROADCAST = "easemob.demo.cmd.toast";
                IntentFilter cmdFilter = new IntentFilter(CMD_TOAST_BROADCAST);

                if (broadCastReceiver == null) {
                    broadCastReceiver = new BroadcastReceiver() {

                        @Override
                        public void onReceive(Context context, Intent intent) {
                            Toast.makeText(appContext, intent.getStringExtra("cmd_value"), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    };

                    //
                    appContext.registerReceiver(broadCastReceiver, cmdFilter);
                }

                Intent broadcastIntent = new Intent(CMD_TOAST_BROADCAST);
                broadcastIntent.putExtra("cmd_value", str + action);
                appContext.sendBroadcast(broadcastIntent, null);

                break;
            }
            case EventDeliveryAck:
                message.setDelivered(true);
                break;
            case EventReadAck:
                message.setAcked(true);
                break;
            // add other events in case you are interested in
            default:
                break;
            }

        }
    };

    EMChatManager.getInstance().registerEventListener(eventListener);

    EMChatManager.getInstance().addChatRoomChangeListener(new EMChatRoomChangeListener() {
        private final static String ROOM_CHANGE_BROADCAST = "easemob.demo.chatroom.changeevent.toast";
        private final IntentFilter filter = new IntentFilter(ROOM_CHANGE_BROADCAST);
        private boolean registered = false;

        private void showToast(String value) {
            if (!registered) {
                //
                appContext.registerReceiver(new BroadcastReceiver() {

                    @Override
                    public void onReceive(Context context, Intent intent) {
                        Toast.makeText(appContext, intent.getStringExtra("value"), Toast.LENGTH_SHORT).show();
                    }

                }, filter);

                registered = true;
            }

            Intent broadcastIntent = new Intent(ROOM_CHANGE_BROADCAST);
            broadcastIntent.putExtra("value", value);
            appContext.sendBroadcast(broadcastIntent, null);
        }

        @Override
        public void onChatRoomDestroyed(String roomId, String roomName) {
            showToast(" room : " + roomId + " with room name : " + roomName + " was destroyed");
            Log.i("info", "onChatRoomDestroyed=" + roomName);
        }

        @Override
        public void onMemberJoined(String roomId, String participant) {
            showToast("member : " + participant + " join the room : " + roomId);
            Log.i("info", "onmemberjoined=" + participant);

        }

        @Override
        public void onMemberExited(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " leave the room : " + roomId + " room name : " + roomName);
            Log.i("info", "onMemberExited=" + participant);

        }

        @Override
        public void onMemberKicked(String roomId, String roomName, String participant) {
            showToast("member : " + participant + " was kicked from the room : " + roomId + " room name : "
                    + roomName);
            Log.i("info", "onMemberKicked=" + participant);

        }

    });
}

From source file:com.hybris.mobile.app.commerce.fragment.CatalogContentFragmentBase.java

@Override
public void onResume() {
    super.onResume();

    // Coming from a search request
    if (isSearchRequest()) {
        resetData();//  w w  w  .  ja v a2s.  co m

        Intent intent = getActivity().getIntent();

        mCurrentSearchText = intent.getStringExtra(SearchManager.QUERY);
    }

    // Updating product list
    updateProductList();
}

From source file:com.arisprung.tailgate.GCMIntentService.java

@Override
protected void onMessage(Context context, Intent intent) {
    Log.i(TAG, "Received message");

    if (mTailgateSharedPreferences == null)
        mTailgateSharedPreferences = TailGateSharedPreferences.getInstance(getApplicationContext());
    // String message = getString(R.string.gcm_message);
    // displayMessage(context, message);
    // notifies user

    // May return null if a EasyTracker has not yet been initialized with a
    // property ID.

    String strJson = intent.getStringExtra("json_message");
    JSONObject jObj = null;//from   w  ww .j  a va2 s  .c  o m
    try {
        jObj = new JSONObject(strJson);
    } catch (JSONException e) {

        e.printStackTrace();
    }

    MessageBean message = JsonUtil.parseJsonToMessageBean(jObj);

    //      EasyTracker easyTracker = EasyTracker.getInstance(context);
    //      if (easyTracker != null)
    //      {
    //         // MapBuilder.createEvent().build() returns a Map of event fields and values
    //         // that are set and sent with the hit.
    //         easyTracker.send(MapBuilder.createEvent("backround_service", // Event category (required)
    //               "OnMessage", // Event action (required)
    //               "message_recieved", // Event label
    //               Long.valueOf(message.getFaceID())) // Event value
    //               .build());
    //      }

    if (!message.getFaceID().equals(
            mTailgateSharedPreferences.getStringSharedPreferences(TailGateSharedPreferences.FACEBOOK_ID, ""))) {
        TailGateUtility.addMessageDB(message, context);

        SharedPreferences mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        boolean notify_checkbox_preference = mySharedPreferences.getBoolean("notification_preference", true);
        if (notify_checkbox_preference) {
            generateNotification(context, message);
        }

    }

    if (jObj.has("json_array_location")) {
        parseLocationJSON(jObj);
    }

}

From source file:cm.aptoide.pt.webservices.login.Login.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case CreateUser.REQUEST_CODE:
        switch (resultCode) {
        case RESULT_OK:
            if (!Login.isLoggedIn(context)) {
                try {
                    username_box.setText(data.getStringExtra("username"));
                    password_box.setText(data.getStringExtra("password"));
                    new CheckUserCredentials().execute(data.getStringExtra("username"),
                            Algorithms.computeSHA1sum(data.getStringExtra("password")), "true");
                } catch (NoSuchAlgorithmException e) {
                    e.printStackTrace();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }//from   w w w .  ja  v a2s .  co  m
            }
            break;

        default:
            break;
        }
        break;

    default:
        break;
    }
}

From source file:com.examples.gg.twitchplayers.VideoBuffer.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;//from  w  ww.j  a  v a  2  s .c  o m
    setContentView(R.layout.videobuffer);
    mVideoView = (VideoView) findViewById(R.id.buffer);
    qualityView = (ImageView) findViewById(R.id.qualitySwitch);
    mMsgView = (TextView) findViewById(R.id.load_msg);
    pb = (ProgressBar) findViewById(R.id.probar);

    downloadRateView = (TextView) findViewById(R.id.download_rate);
    loadRateView = (TextView) findViewById(R.id.load_rate);

    mInfoListener = this;
    mBufferListener = this;

    // Initialize variables
    globalPath = null;
    responseString = null;
    videoSources = new ArrayList<String>();

    mContext = this;

    // Getting the prefs
    // prefs = this.getSharedPreferences("com.examples.gg",
    // Context.MODE_PRIVATE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    Intent intent = getIntent();
    channelName = intent.getStringExtra("video");
    // try {
    // popup = new PopupMenu(VideoBuffer.this, qualityView);
    // } catch (Exception e) {
    // }

    // Getting twitch sources
    try {
        channelName = URLEncoder.encode(channelName.toLowerCase(Locale.ENGLISH), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // new MyAsyncTask().execute("http://usher.twitch.tv/select/"
    // + channelName + ".json?nauthsig=&nauth=&allow_source=true");
    String token_api = String.format("http://api.twitch.tv/api/channels/%s/access_token",
            new Object[] { channelName });
    new MyAsyncTask().execute(token_api);

    mMsgView.setText("Loading channel data...");
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from   w  ww .jav  a  2 s  . c o m*/
    }

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    boolean launcherNotLoaded = LauncherModel.getCellCountX() <= 0 || LauncherModel.getCellCountY() <= 0;

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;
    if (mUseInstallQueue || launcherNotLoaded) {
        String spKey = LauncherApplication.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        addToInstallQueue(sp, info);
    } else {
        processInstallShortcut(context, info);
    }
}