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.networkmanagerapp.JSONBackgroundDownloaderService.java

/**
 * Delegate method to run the specified intent in another thread.
 * @param arg0 The intent to run in the background
 *//*from   ww w .  j av a  2 s .co  m*/
@Override
protected void onHandleIntent(Intent arg0) {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification();
    String filename = arg0.getStringExtra("FILENAME");
    String jsonFile = arg0.getStringExtra("JSONFILE");
    try {
        String password = PreferenceManager.getDefaultSharedPreferences(this).getString("password_preference",
                "");
        Log.d("password", password);
        String ip = PreferenceManager.getDefaultSharedPreferences(this).getString("ip_preference",
                "192.168.1.1");
        String enc = URLEncoder.encode(ip, "UTF-8");
        String scriptUrl = "http://" + enc + ":1080" + filename;

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "utf-8");

        // Set the timeout in milliseconds until a connection is established.
        int timeoutConnection = 3000;
        HttpConnectionParams.setConnectionTimeout(params, timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT) 
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 20000;
        HttpConnectionParams.setSoTimeout(params, timeoutSocket);
        HttpHost targetHost = new HttpHost(enc, 1080, "http");

        DefaultHttpClient client = new DefaultHttpClient(params);
        client.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials("root", password));
        HttpGet request = new HttpGet(scriptUrl);
        HttpResponse response = client.execute(targetHost, request);
        Log.d("JBDS", response.getStatusLine().toString());
        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            str.append(line + "\n");
        }
        in.close();

        if (str.toString().equals("Success\n")) {
            String xmlUrl = "http://" + enc + ":1080/json" + jsonFile;
            request = new HttpGet(xmlUrl);
            HttpResponse jsonData = client.execute(targetHost, request);
            in = jsonData.getEntity().getContent();
            reader = new BufferedReader(new InputStreamReader(in));
            str = new StringBuilder();
            line = null;
            while ((line = reader.readLine()) != null) {
                str.append(line + "\n");
            }
            in.close();

            FileOutputStream fos = openFileOutput(jsonFile.substring(1), Context.MODE_PRIVATE);
            fos.write(str.toString().getBytes());
            fos.close();
        }
    } catch (MalformedURLException ex) {
        Log.e("NETWORKMANAGER_XBD_MUE", ex.getMessage());
    } catch (IOException e) {
        try {
            Log.e("NETWORK_MANAGER_XBD_IOE", e.getMessage());
            StackTraceElement[] st = e.getStackTrace();
            for (int i = 0; i < st.length; i++) {
                Log.e("NETWORK_MANAGER_XBD_IOE", st[i].toString());
            }
        } catch (NullPointerException ex) {
            Log.e("Network_manager_xbd_npe", ex.getLocalizedMessage());
        }

    } finally {
        mNM.cancel(R.string.download_service_started);
        Intent bci = new Intent(NEW_DATA_AVAILABLE);
        sendBroadcast(bci);
        stopSelf();
    }
}

From source file:com.phonegap.plugins.barcodescanner.BarcodeScanner.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").
 */// ww  w. j  a  v a  2  s  .  c  o m
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == REQUEST_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);
            } catch (JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }
            this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            JSONObject obj = new JSONObject();
            try {
                obj.put("text", "");
                obj.put("format", "");
                obj.put("cancelled", true);
            } catch (JSONException e) {
                //Log.d(LOG_TAG, "This should never happen");
            }
            this.success(new PluginResult(PluginResult.Status.OK, obj), this.callback);
        } else {
            this.error(new PluginResult(PluginResult.Status.ERROR), this.callback);
        }
    }
}

From source file:com.example.administrator.myapplication2._4_Detail.RightFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout._2_fragment_map, container, false);

    Intent myIntent = getActivity().getIntent();
    if (myIntent != null) {
        seq = myIntent.getStringExtra("seq");
    }//w w  w  .  j ava 2  s  .  co m

    SharedPreferences myPrefs = this.getActivity().getSharedPreferences("login", Context.MODE_PRIVATE);
    if ((myPrefs != null) && (myPrefs.contains("id"))) {
        id = myPrefs.getString("id", "");
    }

    // ? ? 
    map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map2)).getMap();

    // Setting a custom info window adapter for the google map
    map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        // Use default InfoWindow frame
        @Override
        public View getInfoWindow(Marker arg0) {
            return null;
        }

        // Defines the contents of the InfoWindow
        @Override
        public View getInfoContents(Marker arg0) {

            return null;

        }
    });

    map.setMyLocationEnabled(true);

    arrayPoints = new ArrayList<LatLng>();

    getRecentData();

    /*
            
    if(arrayPoints.size()>0){ showExrLocation(arrayPoints);}                           //Gps
    //if(arrayPoints_network.size()>0){ showExrLocation_network(arrayPoints_network); } //? Gps
    else{Log.i("boogil","? 0?");}
    */

    return rootView;
}

From source file:au.com.micropacific.cordova.DataReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // If intent of the Intent_SOFTTRIGGER_DATA string is received
    if (intent.getAction().equals(GeneralString.Intent_SOFTTRIGGER_DATA)) {

        // fetch the data within the intent
        String data = intent.getStringExtra(GeneralString.BcReaderData);

        // display the fetched data
        //e1.setText(data);
        Log.v("CipherlabRS30Plugin", "got data, 1: " + data);
        this.plugin.receieveScan(data);
    } else if (intent.getAction().equals(GeneralString.Intent_PASS_TO_APP)) {

        // fetch the data within the intent
        String data = intent.getStringExtra(GeneralString.BcReaderData);

        // display the fetched data
        //e1.setText(data);
        Log.v("CipherlabRS30Plugin", "got data, 2: " + data);
        this.plugin.receieveScan(data);

    } else if (intent.getAction().equals(GeneralString.Intent_READERSERVICE_CONNECTED)) {

        BcReaderType myReaderType = mReaderManager.GetReaderType();
        //e1.setText(myReaderType.toString());

        ReaderOutputConfiguration settings = new ReaderOutputConfiguration();
        mReaderManager.Get_ReaderOutputConfiguration(settings);
        settings.enableKeyboardEmulation = KeyboardEmulationType.None;
        mReaderManager.Set_ReaderOutputConfiguration(settings);

        Log.v("CipherlabRS30Plugin", "got data, 3");

        /*NotificationParams settings = new NotificationParams();
        mReaderManager.Get_NotificationParams(settings);
                   //  w w w  .  ja v a  2  s.c  o  m
        ReaderOutputConfiguration settings2 = new ReaderOutputConfiguration();
        mReaderManager.Get_ReaderOutputConfiguration(settings2);
        */
    }

}

From source file:com.polyvi.xface.extension.zbar.XZBarExt.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    mLock = false;/*from  ww w.j a  va  2s.  c o  m*/
    if (requestCode == ZBAR_REQUEST_CODE && mCallbackCtx != null && this.webView.getContext() != null) {
        if (resultCode == Activity.RESULT_OK && intent != null) {
            //???
            String code = intent.getStringExtra("Code");
            mCallbackCtx.success(code);
            PluginResult result = new PluginResult(PluginResult.Status.OK);
            mCallbackCtx.sendPluginResult(result);
        } else {
            mCallbackCtx.error("Error");
        }
    }
}

From source file:com.hybris.mobile.activity.AddressDetailActivity.java

@SuppressWarnings("unchecked")
private void handleIntent(Intent intent) {
    if (intent.hasExtra("value")) {

        try {// w w  w  .j  av  a 2s . c om
            JSONObject address = new JSONObject(intent.getStringExtra("value"));

            mAddressID = address.getString("id");
            for (int i = 0; i < entries.size(); i++) {
                Hashtable<String, Object> dict = (Hashtable<String, Object>) entries.get(i);
                String path = "$." + dict.get("property").toString();
                String value = "";
                try {
                    // We append a String a the end to handle the non String objects
                    value = JsonPath.read(address.toString(), path) + "";
                } catch (Exception exp) {
                    value = "";
                }
                dict.put("value", value);
            }
        } catch (JSONException e) {
            LoggingUtils.e(LOG_TAG, "Error parsing Json. " + e.getLocalizedMessage(), Hybris.getAppContext());
        }

    }
}

From source file:com.scigames.slidegame.MenuActivity.java

/** Called with the activity is first created. */
@Override//from   w ww  .j a  v  a2s.  co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    Log.d(TAG, "super.OnCreate");
    Intent i = getIntent();
    Log.d(TAG, "getIntent");
    //if(!debug){
    firstNameIn = i.getStringExtra("fName");
    lastNameIn = i.getStringExtra("lName");
    ;
    studentIdIn = i.getStringExtra("studentId");
    visitIdIn = i.getStringExtra("visitId");
    rfidIn = i.getStringExtra("rfid");
    photoUrl = i.getStringExtra("photo");
    photoUrl = baseDbURL + "/" + photoUrl;
    slideLevelIn = i.getStringExtra("slideLevel");
    massIn = i.getStringExtra("mass");
    Log.d(TAG, "slideLevelIn: " + slideLevelIn);
    Log.d(TAG, "...getStringExtra");
    //}
    // Inflate our UI from its XML layout description.
    setContentView(R.layout.menu_page);
    Log.d(TAG, "...setContentView");

    ExistenceLightOtf = Typeface.createFromAsset(getAssets(), "fonts/Existence-Light.ttf");
    //Typeface Museo300Regular = Typeface.createFromAsset(getAssets(),"fonts/Museo300-Regular.otf");
    Museo500Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo500-Regular.otf");
    Museo700Regular = Typeface.createFromAsset(getAssets(), "fonts/Museo700-Regular.otf");

    displayProfile();
}

From source file:com.hybris.mobile.activity.ProfileDetailActivity.java

@SuppressWarnings("unchecked")
private void handleIntent(Intent intent) {
    if (intent.hasExtra("value")) {
        try {/*from   w  w  w  .j  ava2  s .  c om*/
            JSONObject profile = new JSONObject(intent.getStringExtra("value"));
            for (int i = 0; i < entries.size(); i++) {
                Hashtable<String, Object> dict = (Hashtable<String, Object>) entries.get(i);
                String path = "$." + dict.get("property").toString();
                String value = "";
                try {
                    // We append a String a the end to handle the non String objects
                    value = JsonPath.read(profile.toString(), path) + "";
                } catch (Exception exp) {
                    value = "";
                }
                dict.put("value", value);
            }
        } catch (JSONException e) {
            LoggingUtils.e(LOG_TAG, "Error parsing json. " + e.getLocalizedMessage(), Hybris.getAppContext());
        }
    }
}

From source file:com.google.ipc.invalidation.ticl.android.c2dm.C2DMObserver.java

/**
 * Returns {@code true} if the provided intent matches the selection criteria for this
 * observer.// w ww  . ja  v  a 2s  .  c o m
 */
boolean matches(Intent intent) {
    if (selectKey == null) {
        return true;
    }
    if (intent.hasExtra(selectKey)) {
        return selectValue == null || selectValue.equals(intent.getStringExtra(selectKey));
    }
    return false;
}

From source file:org.openplans.rcavl.LocationService.java

public void realStart(Intent intent) {
    String url = intent.getStringExtra("pingUrl");
    String email = intent.getStringExtra("email");
    String password = intent.getStringExtra("password");
    pingInterval = intent.getIntExtra("pingInterval", 60);

    Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile",
            System.currentTimeMillis());
    Intent appIntent = new Intent(this, RCAVL.class);

    appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0);

    notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(66786, notification);

    thread = new LocationServiceThread(url, email, password);
    new Thread(thread).start();
}