Example usage for android.os Bundle getString

List of usage examples for android.os Bundle getString

Introduction

In this page you can find the example usage for android.os Bundle getString.

Prototype

@Nullable
public String getString(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:net.idlesoft.android.apps.github.activities.Branch.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.branch);/*from ww  w  .j a  v a 2 s . c  om*/

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(Branch.this, Search.class));
        }
    });

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        mBranchName = extras.getString("branch_name");
        mBranchSha = extras.getString("branch_sha");

        final TextView branchName = (TextView) findViewById(R.id.tv_branch_name);
        final TextView branchSha = (TextView) findViewById(R.id.tv_branch_sha);
        final ListView infoList = (ListView) findViewById(R.id.lv_branch_infoList);

        branchName.setText(mBranchName);
        branchSha.setText(mBranchSha);

        infoList.setAdapter(new ArrayAdapter<String>(Branch.this, R.layout.branch_info_item,
                R.id.tv_branchInfoItem_text1, new String[] { "Commit Log", "View Branch's Tree" }));
        infoList.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> parent, final View v, final int position,
                    final long id) {
                if (position == 0) {
                    mIntent = new Intent(Branch.this, CommitsList.class);
                    mIntent.putExtra("repo_owner", mRepositoryOwner);
                    mIntent.putExtra("repo_name", mRepositoryName);
                    mIntent.putExtra("branch_name", mBranchName);
                    startActivity(mIntent);
                } else if (position == 1) {
                    mIntent = new Intent(Branch.this, BranchTree.class);
                    mIntent.putExtra("repo_owner", mRepositoryOwner);
                    mIntent.putExtra("repo_name", mRepositoryName);
                    mIntent.putExtra("branch_name", mBranchName);
                    mIntent.putExtra("branch_sha", mBranchSha);
                    startActivity(mIntent);
                }
            }
        });
    }
}

From source file:foam.jellyfish.StarwispActivity.java

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

    String arg = "none";
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        arg = extras.getString("arg");
    }/*from w  ww.j a va2  s .  c  o  m*/

    String ret = m_Scheme.eval("(activity-callback 'on-start \"" + m_Name + "\" (list \"" + arg + "\"))");
    try {
        m_Builder.UpdateList(this, m_Name, new JSONArray(ret));
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + ret + "] " + e.toString());
    }
}

From source file:co.uk.gauntface.cordova.plugin.gcmbrowserlaunch.PushNotificationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.v(C.TAG, "PushNotificationReceiver: Received Notification");

    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    String messageType = gcm.getMessageType(intent);

    if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
        //sendNotification("Send error: " + intent.getExtras().toString());
        Log.e(C.TAG, "PushNotificationReceiver: MESSAGE_TYPE_SEND_ERROR");
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
        Log.e(C.TAG, "PushNotificationReceiver: MESSAGE_TYPE_DELETED");
    } else {/*  ww w  .  j  a va2 s  .c  o  m*/
        Bundle data = intent.getExtras();
        if (data != null) {
            String url = validateUrl(data.getString("url"));
            String packageName = data.getString("pkg");
            String session = data.getString("session");

            SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
            String lastSession = settings.getString("lastsession", null);
            String lastReceivedUrl = settings.getString("lastreceivedurl", null);

            if (session != null && session.equals(lastSession) && url.equals(lastReceivedUrl)) {
                setResultCode(Activity.RESULT_OK);
                return;
            }

            //Log.v(C.TAG, "PushNotificationReceiver: url = "+url);
            //Log.v(C.TAG, "PushNotificationReceiver: lastsession = "+lastSession);
            //Log.v(C.TAG, "PushNotificationReceiver: lastReceivedUrl = "+lastReceivedUrl);

            if (url != null) {
                launchBrowserTask(context, url, packageName);

                // We need an Editor object to make preference changes.
                // All objects are from android.context.Context
                SharedPreferences.Editor editor = settings.edit();
                editor.putString("lastreceivedurl", url);
                editor.putString("lastsession", session);

                // Commit the edits!
                editor.commit();
            }

        }
    }

    setResultCode(Activity.RESULT_OK);
}

From source file:crow.weibo.kaixin.KaixinWeibo.java

public KaixinAccessToken getAccessToken(String requestToken, String requestTokenSecret, String verifier)
        throws WeiboException {
    List<PostParameter> params = new ArrayList<PostParameter>();
    params.add(new PostParameter(OUATH_TOKEN, requestToken));
    params.add(new PostParameter(OUATH_TOKEN_VERIFIER, verifier));

    // ?//from w ww  . j a v  a2  s  .c  o  m
    String timestamp = WeiboUtil.generateTimeStamp();
    String onceMd5 = Util.md5(WeiboUtil.generateNonce());
    params.add(new PostParameter("oauth_consumer_key", getApiKey()));
    params.add(new PostParameter("oauth_signature_method", "HMAC-SHA1"));
    params.add(new PostParameter("oauth_timestamp", timestamp));
    params.add(new PostParameter("oauth_nonce", onceMd5));
    // ??
    String signature = makeSign(params, KX_ACCESS_TOKEN_URL, GET_METHOD, getApiSecret(), requestTokenSecret);
    params.add(new PostParameter("oauth_signature", signature));

    String url = KX_ACCESS_TOKEN_URL + "?" + WeiboUtil.encodeParameters(params, "&", false);

    try {
        String result = Util.urlGet(url);
        Bundle bundle = WeiboUtil.parseToken(result);
        String token = bundle.getString(OUATH_TOKEN);
        String tokenSecret = bundle.getString(OUATH_TOKEN_SECRET);
        if (token != null && tokenSecret != null) {
            SharedPreferences pref = context.getSharedPreferences(Weibo.PREF_WEIBO, Context.MODE_PRIVATE);
            pref.edit().putString(PREF_ACCESSTOKEN, token).putString(PREF_ACCESSTOKEN_SECRET, tokenSecret)
                    .commit();
            return new KaixinAccessToken(this, token, tokenSecret);
        } else {
            throw new WeiboException("??");
        }
    } catch (Exception e) {
        throw new WeiboException(e);
    }
}

From source file:net.idlesoft.android.apps.github.activities.tabs.Followers.java

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

    final SharedPreferences prefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);
    mGapi.authenticate(prefs.getString("username", ""), prefs.getString("password", ""));

    mListView = (ListView) getLayoutInflater().inflate(R.layout.tab_listview, null);
    mListView.setOnItemClickListener(mOnListItemClick);

    setContentView(mListView);/*from   www. ja  v a 2 s .  c  om*/

    mAdapter = new FollowersFollowingListAdapter(Followers.this, mListView);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mTarget = extras.getString("target");
    }
    if ((mTarget == null) || mTarget.equals("")) {
        mTarget = prefs.getString("username", "");
    }

    mTask = (FollowersTask) getLastNonConfigurationInstance();
    if ((mTask == null) || (mTask.getStatus() == AsyncTask.Status.FINISHED)) {
        mTask = new FollowersTask();
    }
    mTask.activity = this;
    if (mTask.getStatus() == AsyncTask.Status.PENDING) {
        mTask.execute();
    }
}

From source file:net.idlesoft.android.apps.github.activities.tabs.Following.java

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

    final SharedPreferences prefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);
    mGapi.authenticate(prefs.getString("username", ""), prefs.getString("password", ""));

    mListView = (ListView) getLayoutInflater().inflate(R.layout.tab_listview, null);
    mListView.setOnItemClickListener(mOnListItemClick);

    setContentView(mListView);/*  w ww  .j av a2s. c om*/

    mAdapter = new FollowersFollowingListAdapter(Following.this, mListView);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mTarget = extras.getString("target");
    }
    if ((mTarget == null) || mTarget.equals("")) {
        mTarget = prefs.getString("username", "");
    }

    mTask = (FollowingTask) getLastNonConfigurationInstance();
    if ((mTask == null) || (mTask.getStatus() == AsyncTask.Status.FINISHED)) {
        mTask = new FollowingTask();
    }
    mTask.activity = this;
    if (mTask.getStatus() == AsyncTask.Status.PENDING) {
        mTask.execute();
    }
}

From source file:com.NotifyMe.GcmIntentService.java

private void sendNotificationWithExtras(Bundle extras) {
    String message = extras.getString("message");
    String service = extras.getString("service");
    String type = extras.getString("type");
    String title = "NotifyMe [" + service + "]";

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent;//from ww w. j ava  2 s  .  c o  m
    if (service.equals("Reddit")) {
        Intent resultIntent = new Intent(Intent.ACTION_VIEW);
        String url = "http://reddit.com";
        if (type.equals("reddit-front-page")) {
            if (Integer.parseInt(extras.getString("count")) == 1) {
                try {
                    JSONArray posts = new JSONArray(extras.getString("links"));
                    url = posts.getJSONObject(0).getString("url");
                    message = posts.getJSONObject(0).getString("title");
                } catch (JSONException e) {
                    url = "http://reddit.com";
                }
            } else {
                url = "http://reddit.com";
            }
        } else if (type.equals("user-comment") || type.equals("user-submission")) {
            url = extras.getString("link");
        }
        resultIntent.setData(Uri.parse(url));
        contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    } else if (service.equals("weather")) {
        Intent resultIntent;
        Intent weatherIntent = getWeatherAppIntent();
        if (weatherIntent != null) {
            resultIntent = weatherIntent;
        } else {
            resultIntent = new Intent(Intent.ACTION_VIEW);
            String url = "http://weather.com/";
            resultIntent.setData(Uri.parse(url));
        }
        contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    } else if (service.equals("poly")) {
        Intent resultIntent = new Intent(Intent.ACTION_VIEW);
        String url = "https://www4.polymtl.ca/poly/poly.html";
        resultIntent.setData(Uri.parse(url));
        contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    } else if (service.equals("github")) {
        Intent resultIntent = new Intent(Intent.ACTION_VIEW);
        String url = extras.getString("link");
        resultIntent.setData(Uri.parse(url));
        contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {
        contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title).setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setDefaults(Notification.DEFAULT_VIBRATE).setOnlyAlertOnce(true);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:crow.weibo.kaixin.KaixinWeibo.java

@Override
public RequestToken getOAuthRequestToken(String callbackUrl) throws WeiboException {
    List<PostParameter> params = new ArrayList<PostParameter>();

    // //from  w ww  . j a v a  2  s  . co  m
    params.add(new PostParameter("oauth_callback", callbackUrl));
    // ??
    params.add(new PostParameter("scope", "basic create_records"));

    // ?
    String timestamp = WeiboUtil.generateTimeStamp();
    String onceMd5 = Util.md5(WeiboUtil.generateNonce());
    params.add(new PostParameter("oauth_consumer_key", getApiKey()));
    params.add(new PostParameter("oauth_signature_method", "HMAC-SHA1"));
    params.add(new PostParameter("oauth_timestamp", timestamp));
    params.add(new PostParameter("oauth_nonce", onceMd5));
    // ??
    String signature = makeSign(params, KX_REQUEST_TOKEN_URL, GET_METHOD, getApiSecret(), null);
    params.add(new PostParameter("oauth_signature", signature));

    // url
    String url = KX_REQUEST_TOKEN_URL + "?" + WeiboUtil.encodeParameters(params, "&", false);
    try {
        String result = Util.urlGet(url);
        Bundle token = WeiboUtil.parseToken(result);
        String tokenKey = token.getString(OUATH_TOKEN);
        String tokenSecret = token.getString(OUATH_TOKEN_SECRET);
        if (tokenKey != null && tokenSecret != null) {
            return new KaixinRequestToken(this, callbackUrl, tokenKey, tokenSecret);
        } else {
            throw new WeiboException("??");
        }
    } catch (Exception e) {
        throw new WeiboException(e);
    }
}

From source file:foam.jellyfish.StarwispActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from  w ww  .ja  v  a  2 s .  c  o m*/
    OuyaController.init(this);

    String arg = "none";
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        arg = extras.getString("arg");
    }

    String json = m_Scheme.eval("(activity-callback 'on-create \"" + m_Name + "\" (list \"" + arg + "\"))");
    View root = findViewById(R.id.main);

    m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/Pfennig.ttf");
    //m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/grstylus.ttf");

    try {
        m_Builder.Build(this, m_Name, new JSONArray(json), (ViewGroup) root);
    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + json + "] " + e.toString());
    }
}

From source file:com.apptentive.android.sdk.Apptentive.java

private static void init(Activity activity) {

    ///*from   w  ww  . ja va2  s. c o m*/
    // First, initialize data relies on synchronous reads from local resources.
    //

    final Context appContext = activity.getApplicationContext();

    if (!GlobalInfo.initialized) {
        SharedPreferences prefs = appContext.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);

        // First, Get the api key, and figure out if app is debuggable.
        GlobalInfo.isAppDebuggable = false;
        String apiKey = null;
        boolean apptentiveDebug = false;
        String logLevelOverride = null;
        try {
            ApplicationInfo ai = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(),
                    PackageManager.GET_META_DATA);
            Bundle metaData = ai.metaData;
            if (metaData != null) {
                apiKey = metaData.getString(Constants.MANIFEST_KEY_APPTENTIVE_API_KEY);
                logLevelOverride = metaData.getString(Constants.MANIFEST_KEY_APPTENTIVE_LOG_LEVEL);
                apptentiveDebug = metaData.getBoolean(Constants.MANIFEST_KEY_APPTENTIVE_DEBUG);
                ApptentiveClient.useStagingServer = metaData
                        .getBoolean(Constants.MANIFEST_KEY_USE_STAGING_SERVER);
            }
            if (apptentiveDebug) {
                Log.i("Apptentive debug logging set to VERBOSE.");
                ApptentiveInternal.setMinimumLogLevel(Log.Level.VERBOSE);
            } else if (logLevelOverride != null) {
                Log.i("Overriding log level: %s", logLevelOverride);
                ApptentiveInternal.setMinimumLogLevel(Log.Level.parse(logLevelOverride));
            } else {
                GlobalInfo.isAppDebuggable = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
                if (GlobalInfo.isAppDebuggable) {
                    ApptentiveInternal.setMinimumLogLevel(Log.Level.VERBOSE);
                }
            }
        } catch (Exception e) {
            Log.e("Unexpected error while reading application info.", e);
        }

        Log.i("Debug mode enabled? %b", GlobalInfo.isAppDebuggable);

        // If we are in debug mode, but no api key is found, throw an exception. Otherwise, just assert log. We don't want to crash a production app.
        String errorString = "No Apptentive api key specified. Please make sure you have specified your api key in your AndroidManifest.xml";
        if ((Util.isEmpty(apiKey))) {
            if (GlobalInfo.isAppDebuggable) {
                AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle("Error")
                        .setMessage(errorString).setPositiveButton("OK", null).create();
                alertDialog.setCanceledOnTouchOutside(false);
                alertDialog.show();
            }
            Log.e(errorString);
        }
        GlobalInfo.apiKey = apiKey;

        Log.i("API Key: %s", GlobalInfo.apiKey);

        // Grab app info we need to access later on.
        GlobalInfo.appPackage = appContext.getPackageName();
        GlobalInfo.androidId = Settings.Secure.getString(appContext.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);

        // Check the host app version, and notify modules if it's changed.
        try {
            PackageManager packageManager = appContext.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(appContext.getPackageName(), 0);

            Integer currentVersionCode = packageInfo.versionCode;
            String currentVersionName = packageInfo.versionName;
            VersionHistoryStore.VersionHistoryEntry lastVersionEntrySeen = VersionHistoryStore
                    .getLastVersionSeen(appContext);
            if (lastVersionEntrySeen == null) {
                onVersionChanged(appContext, null, currentVersionCode, null, currentVersionName);
            } else {
                if (!currentVersionCode.equals(lastVersionEntrySeen.versionCode)
                        || !currentVersionName.equals(lastVersionEntrySeen.versionName)) {
                    onVersionChanged(appContext, lastVersionEntrySeen.versionCode, currentVersionCode,
                            lastVersionEntrySeen.versionName, currentVersionName);
                }
            }

            GlobalInfo.appDisplayName = packageManager
                    .getApplicationLabel(packageManager.getApplicationInfo(packageInfo.packageName, 0))
                    .toString();
        } catch (PackageManager.NameNotFoundException e) {
            // Nothing we can do then.
            GlobalInfo.appDisplayName = "this app";
        }

        // Grab the conversation token from shared preferences.
        if (prefs.contains(Constants.PREF_KEY_CONVERSATION_TOKEN)
                && prefs.contains(Constants.PREF_KEY_PERSON_ID)) {
            GlobalInfo.conversationToken = prefs.getString(Constants.PREF_KEY_CONVERSATION_TOKEN, null);
            GlobalInfo.personId = prefs.getString(Constants.PREF_KEY_PERSON_ID, null);
        }

        GlobalInfo.initialized = true;
        Log.v("Done initializing...");
    } else {
        Log.v("Already initialized...");
    }

    // Initialize the Conversation Token, or fetch if needed. Fetch config it the token is available.
    if (GlobalInfo.conversationToken == null || GlobalInfo.personId == null) {
        asyncFetchConversationToken(appContext.getApplicationContext());
    } else {
        asyncFetchAppConfiguration(appContext.getApplicationContext());
        InteractionManager.asyncFetchAndStoreInteractions(appContext.getApplicationContext());
    }

    // TODO: Do this on a dedicated thread if it takes too long. Some devices are slow to read device data.
    syncDevice(appContext);
    syncSdk(appContext);
    syncPerson(appContext);

    Log.d("Default Locale: %s", Locale.getDefault().toString());
    SharedPreferences prefs = appContext.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE);
    Log.d("Conversation id: %s", prefs.getString(Constants.PREF_KEY_CONVERSATION_ID, "null"));
}