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:at.vcity.androidimsocket.services.IMService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String myToken = intent.getStringExtra("myToken");

    if (!heartIsBeating) {
        if (myToken != null) {
            username = intent.getStringExtra("username");
            password = intent.getStringExtra("password");
            socketOperator.setToken(myToken);
            Log.i("Wake up now....................!!!!", "");
            startHeartbeat();//from   ww  w  .  j a v  a 2s  .c om
        }
    }
    return START_REDELIVER_INTENT;
}

From source file:com.rainmakerlabs.bleepsample.BleepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");
    String actionName = intent.getStringExtra("actionName");
    if (intent == null || intent.getExtras() == null) {//just removing these checks
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_PROCESS)
            && intent.getExtras().containsKey(BLEepService.INTENT_BLEEP_PASSED_LIST)) {
        ArrayList<Bleep> bleeps = (ArrayList<Bleep>) intent.getExtras()
                .getSerializable(BLEepService.INTENT_BLEEP_PASSED_LIST);
        for (final Bleep bleep : bleeps) {
            String msgType = bleep.getType();
            String atts = bleep.getAtts();
            try {
                JSONObject objMsg = new JSONObject(atts);
                //thisBleepService.addExtraLog(bleep, "FEEDBACK", "good");//use this when you want to send a custom log to BMS. for instance, you could display a feedback dialog, and ask users to give a rating, and BMS will help you collate the information. put this where necessary, it's just here for example
                Log.d(TAG, "Message Received of Type: " + msgType);
                if (msgType.equalsIgnoreCase("image")) {
                    final String strImgUrl = objMsg.optString(APIKeyDefineCommand.MSG_IMG);
                    final String adAspect = objMsg.optString(APIKeyDefineCommand.MSG_IMGASP);
                    String strImgMsgTemp = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    //putting the default message above would only work for missing key, not in case of empty string. empty string will prevent the notification, so fix below
                    if (strImgMsgTemp.equalsIgnoreCase(""))
                        strImgMsgTemp = "No Message";
                    final String strImgMsg = strImgMsgTemp;
                    if (checkIfClosed()) {
                        if (oldcodeon)
                            localNotification("", strImgMsg, 0);
                        continue;
                    }//from  ww w .  ja  va  2s  .  c om
                    if (MainActivity.adlib.get(strImgMsg) == null && !strImgMsg.equalsIgnoreCase("No Message"))
                        Log.d(TAG, "image url start download for key: " + strImgMsg + ", url = " + strImgUrl);
                    else {
                        Log.d(TAG, "Image exists, or no message, not downloading..., key: " + strImgMsg);
                        continue;
                    }

                    if (strImgMsg.equalsIgnoreCase("$28")) {
                        Log.d("Portal", "Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.singtel), strImgMsg);
                        continue;
                    } else if (strImgMsg.equalsIgnoreCase("$4.50")) {
                        Log.d("Portal", "Heineken Image exists, loading from cache");
                        imgShow(BitmapFactory.decodeResource(getResources(), R.drawable.heineken), strImgMsg);
                        continue;
                    }

                    ShutterbugManager.getSharedImageManager(BleepActivity.currentBleepActivity)
                            .download(strImgUrl, new ShutterbugManagerListener() {
                                @Override
                                public void onImageSuccess(ShutterbugManager imageManager, Bitmap bitmap,
                                        String url) {
                                    Log.d(TAG, "image url end download " + strImgUrl);
                                    if (strImgUrl.equalsIgnoreCase(AdDialog.getCurrentAdUrl()))
                                        return;
                                    if (AdDialog.howManyAdDialogsShowing == 1) {
                                        AdDialog.closeOnlyAdDialog();
                                    }
                                    final Bitmap bitmap2 = bitmap;

                                    imgShow(bitmap, strImgMsg);

                                    if (oldcodeon) {
                                        BleepActivity.currentBleepActivity.runOnUiThread(new Runnable() {
                                            public void run() {
                                                if (BleepActivity.isBackground)
                                                    localNotification("", strImgMsg, 0);
                                                AdDialog.showAdsDialog(BleepActivity.currentBleepActivity,
                                                        bitmap2, strImgUrl, adAspect);
                                            }
                                        });
                                    }
                                }

                                @Override
                                public void onImageFailure(ShutterbugManager imageManager, String url) {
                                    thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                                }
                            });
                } else if (oldcodeon == false) {//don't run anything else
                } else if (msgType.equalsIgnoreCase("alert") && oldcodeon) {

                    // show alert message
                    if (checkIfClosed() || BleepActivity.isBackground) {
                        localNotification(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT), 1);
                    } else {
                        showAlert(objMsg.optString(APIKeyDefineCommand.MSG_TITLE),
                                objMsg.optString(APIKeyDefineCommand.MSG_CONTENT));
                    }
                } else if (msgType.equalsIgnoreCase("launch")) {
                    String intentAction = objMsg.optString(APIKeyDefineCommand.MSG_APP_INTENT);
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_APP_URI);
                    String intentType = "";
                    String intentExtras = objMsg.optString(APIKeyDefineCommand.MSG_APP_EXTRAS);
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 2);
                } else if (msgType.equalsIgnoreCase("url")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_CFM);
                    String failMsg = objMsg.optString(APIKeyDefineCommand.MSG_APP_FAIL);
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 3);
                } else if (msgType.equalsIgnoreCase("webview")) {
                    String intentAction = Intent.ACTION_VIEW;
                    String intentUri = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    String intentType = "";
                    String intentExtras = "";
                    String cfmMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (cfmMsg.equalsIgnoreCase(""))
                        cfmMsg = "View webpage?";
                    String failMsg = "";
                    processTypeLaunch(intentAction, intentUri, intentType, intentExtras, cfmMsg, failMsg, 4);
                } else if (msgType.equalsIgnoreCase("video")) {
                    String strVidUrl = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    Intent vidIntent = new Intent(this, VideoActivity.class);
                    vidIntent.putExtra("url", strVidUrl);
                    String notifMsg = objMsg.optString(APIKeyDefineCommand.MSG_NOTIF);
                    if (notifMsg.equalsIgnoreCase(""))
                        notifMsg = "Play video?";
                    if (!checkIfClosed() && BleepActivity.isVideoActivityOpen) {
                        thisBleepService.eraseTriggerLog(bleep);//to cancel trigger log when trigger is cancelled
                    } else if (checkIfClosed() || BleepActivity.isBackground) {
                        vidIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        vidIntent.setAction(Intent.ACTION_MAIN);
                        vidIntent.addCategory(Intent.CATEGORY_LAUNCHER);
                        localNotification("", notifMsg, vidIntent, "Video opening failed!", 5);
                    } else {
                        BleepActivity.currentBleepActivity.startActivity(vidIntent);
                    }
                } else if (msgType.equalsIgnoreCase("audio")) {
                    String url = objMsg.optString(APIKeyDefineCommand.MSG_MEDIA_URL);
                    mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    try {
                        mediaPlayer.setDataSource(url);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    mediaPlayer.prepareAsync();
                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            mp.start();
                        }
                    });
                    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            return false;
                        }
                    });
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        //      } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_EXIT) && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        //         HashMap<String, Object> beaconOutInfo = (HashMap<String, Object>)intent.getSerializableExtra(BLEepService.INTENT_MSG_NAME);   
        //         //Log.d("debug!","debug! this beacon just went out "+beaconOutInfo.get("uuid")+" "+beaconOutInfo.get("major")+" "+beaconOutInfo.get("minor")+" "+beaconOutInfo.get("tag")+" "+beaconOutInfo.get("beaconID"));
    } else if (actionName.equalsIgnoreCase(BLEepService.INTENT_BLEEP_STATE)
            && intent.getExtras().containsKey(BLEepService.INTENT_MSG_NAME)) {
        int beaconState = intent.getIntExtra(BLEepService.INTENT_MSG_NAME, 99);
    }

    return START_NOT_STICKY;
}

From source file:com.aware.utils.WebserviceHelper.java

@Override
protected void onHandleIntent(Intent intent) {

    WEBSERVER = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_SERVER);
    DEVICE_ID = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID);
    DEBUG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true");
    DATABASE_TABLE = intent.getStringExtra(EXTRA_TABLE);
    TABLES_FIELDS = intent.getStringExtra(EXTRA_FIELDS);
    CONTENT_URI = Uri.parse(intent.getStringExtra(EXTRA_CONTENT_URI));

    //Fixed: not using webservices
    if (WEBSERVER.length() == 0)
        return;//from   w ww. j  a va2s . c  om

    if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_SYNC_TABLE)) {

        //Check if we should do this only over Wi-Fi
        boolean wifi_only = Aware.getSetting(getApplicationContext(), Aware_Preferences.WEBSERVICE_WIFI_ONLY)
                .equals("true");
        if (wifi_only) {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo active_network = cm.getActiveNetworkInfo();
            if (active_network != null && active_network.getType() != ConnectivityManager.TYPE_WIFI) {
                if (DEBUG) {
                    Log.i("AWARE", "User not connected to Wi-Fi, skipping data sync.");
                }
                return;
            }
        }

        //Check first if we have database table remotely, otherwise create it!
        ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>();
        fields.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
        fields.add(new BasicNameValuePair(EXTRA_FIELDS, TABLES_FIELDS));

        //Create table if doesn't exist on the remote webservice server
        HttpResponse response = new Https(getApplicationContext())
                .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/create_table", fields);
        if (response != null && response.getStatusLine().getStatusCode() == 200) {
            if (DEBUG) {
                HttpResponse copy = response;
                try {
                    if (DEBUG)
                        Log.d(Aware.TAG, EntityUtils.toString(copy.getEntity()));
                } catch (ParseException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            String[] columnsStr = new String[] {};
            Cursor columnsDB = getContentResolver().query(CONTENT_URI, null, null, null, null);
            if (columnsDB != null && columnsDB.moveToFirst()) {
                columnsStr = columnsDB.getColumnNames();
                if (DEBUG)
                    Log.d(Aware.TAG, "Total records on " + DATABASE_TABLE + ": " + columnsDB.getCount());
            }
            if (columnsDB != null && !columnsDB.isClosed())
                columnsDB.close();

            try {
                ArrayList<NameValuePair> request = new ArrayList<NameValuePair>();
                request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));

                //check the latest entry in remote database
                HttpResponse latest = new Https(getApplicationContext())
                        .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/latest", request);
                if (latest == null)
                    return;

                String data = "[]";
                try {
                    data = EntityUtils.toString(latest.getEntity());
                } catch (IllegalStateException e) {
                    Log.d(Aware.TAG, "Unable to connect to webservices...");
                }

                if (DEBUG) {
                    Log.d(Aware.TAG, "Webservice response: " + data);
                }

                //If in a study, get from joined date onwards
                String study_condition = "";
                if (Aware.getSetting(getApplicationContext(), "study_id").length() > 0
                        && Aware.getSetting(getApplicationContext(), "study_start").length() > 0) {
                    String study_start = Aware.getSetting(getApplicationContext(), "study_start");
                    study_condition = " AND timestamp > " + Long.parseLong(study_start);
                }
                if (DATABASE_TABLE.equalsIgnoreCase("aware_device"))
                    study_condition = "";

                JSONArray remoteData = new JSONArray(data);

                Cursor context_data;
                if (remoteData.length() == 0) {
                    if (exists(columnsStr, "double_end_timestamp")) {
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "double_end_timestamp != 0" + study_condition, null, "timestamp ASC");
                    } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) {
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "double_esm_user_answer_timestamp != 0" + study_condition, null,
                                "timestamp ASC");
                    } else {
                        context_data = getContentResolver().query(CONTENT_URI, null, "1" + study_condition,
                                null, "timestamp ASC");
                    }
                } else {
                    long last = 0;
                    if (exists(columnsStr, "double_end_timestamp")) {
                        last = remoteData.getJSONObject(0).getLong("double_end_timestamp");
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "timestamp > " + last + " AND double_end_timestamp != 0" + study_condition,
                                null, "timestamp ASC");
                    } else if (exists(columnsStr, "double_esm_user_answer_timestamp")) {
                        last = remoteData.getJSONObject(0).getLong("double_esm_user_answer_timestamp");
                        context_data = getContentResolver().query(
                                CONTENT_URI, null, "timestamp > " + last
                                        + " AND double_esm_user_answer_timestamp != 0" + study_condition,
                                null, "timestamp ASC");
                    } else {
                        last = remoteData.getJSONObject(0).getLong("timestamp");
                        context_data = getContentResolver().query(CONTENT_URI, null,
                                "timestamp > " + last + study_condition, null, "timestamp ASC");
                    }
                }

                JSONArray context_data_entries = new JSONArray();
                if (context_data != null && context_data.moveToFirst()) {
                    if (DEBUG)
                        Log.d(Aware.TAG, "Uploading " + context_data.getCount() + " from " + DATABASE_TABLE);

                    do {
                        JSONObject entry = new JSONObject();

                        String[] columns = context_data.getColumnNames();
                        for (String c_name : columns) {

                            //Skip local database ID
                            if (c_name.equals("_id"))
                                continue;

                            if (c_name.equals("timestamp") || c_name.contains("double")) {
                                entry.put(c_name, context_data.getDouble(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("float")) {
                                entry.put(c_name, context_data.getFloat(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("long")) {
                                entry.put(c_name, context_data.getLong(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("blob")) {
                                entry.put(c_name, context_data.getBlob(context_data.getColumnIndex(c_name)));
                            } else if (c_name.contains("integer")) {
                                entry.put(c_name, context_data.getInt(context_data.getColumnIndex(c_name)));
                            } else {
                                entry.put(c_name, context_data.getString(context_data.getColumnIndex(c_name)));
                            }
                        }
                        context_data_entries.put(entry);

                        if (context_data_entries.length() == 1000) {
                            request = new ArrayList<NameValuePair>();
                            request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
                            request.add(new BasicNameValuePair("data", context_data_entries.toString()));
                            new Https(getApplicationContext())
                                    .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request);

                            context_data_entries = new JSONArray();
                        }
                    } while (context_data.moveToNext());

                    if (context_data_entries.length() > 0) {
                        request = new ArrayList<NameValuePair>();
                        request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
                        request.add(new BasicNameValuePair("data", context_data_entries.toString()));
                        new Https(getApplicationContext())
                                .dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/insert", request);
                    }
                } else {
                    if (DEBUG)
                        Log.d(Aware.TAG,
                                "Nothing new in " + DATABASE_TABLE + "!" + " URI=" + CONTENT_URI.toString());
                }

                if (context_data != null && !context_data.isClosed())
                    context_data.close();

            } catch (ParseException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    //Clear database table remotely
    if (intent.getAction().equals(ACTION_AWARE_WEBSERVICE_CLEAR_TABLE)) {
        ArrayList<NameValuePair> request = new ArrayList<NameValuePair>();
        request.add(new BasicNameValuePair(Aware_Preferences.DEVICE_ID, DEVICE_ID));
        new Https(getApplicationContext()).dataPOST(WEBSERVER + "/" + DATABASE_TABLE + "/clear_table", request);
    }
}

From source file:com.irccloud.android.RemoteInputService.java

@Override
protected void onHandleIntent(Intent intent) {
    boolean success = false;
    String sk = getSharedPreferences("prefs", 0).getString("session_key", "");
    if (intent != null && sk != null && sk.length() > 0) {
        final String action = intent.getAction();
        if (ACTION_REPLY.equals(action)) {
            Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
            if (remoteInput != null || intent.hasExtra("reply")) {
                Crashlytics.log(Log.INFO, "IRCCloud", "Got reply from RemoteInput");
                String reply = remoteInput != null ? remoteInput.getCharSequence("extra_reply").toString()
                        : intent.getStringExtra("reply");
                if (reply.length() > 0 && !reply.contains("\n/")
                        && (!reply.startsWith("/") || reply.toLowerCase().startsWith("/me ")
                                || reply.toLowerCase().startsWith("/slap "))) {
                    try {
                        JSONObject o = NetworkConnection.getInstance().say(intent.getIntExtra("cid", -1),
                                intent.getStringExtra("to"), reply, sk);
                        success = o.getBoolean("success");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }/*w w  w .  j a va  2 s .c  o  m*/
                }
                NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                        .cancel(intent.getIntExtra("bid", 0));
                if (intent.hasExtra("eids")) {
                    int bid = intent.getIntExtra("bid", -1);
                    long[] eids = intent.getLongArrayExtra("eids");
                    for (int j = 0; j < eids.length; j++) {
                        if (eids[j] > 0) {
                            Notifications.getInstance().dismiss(bid, eids[j]);
                        }
                    }
                }
                if (!success)
                    Notifications.getInstance().alert(intent.getIntExtra("bid", -1), "Sending Failed",
                            reply.startsWith("/") ? "Please launch the IRCCloud app to send this command"
                                    : "Your message was not sent. Please try again shortly.");
            } else {
                Crashlytics.log(Log.ERROR, "IRCCloud", "RemoteInputService received no remoteinput");
            }
        }
    }
}

From source file:chaitanya.im.searchforreddit.LauncherActivity.java

private void receiveIntent(Intent intent) {
    String sharedText = intent.getStringExtra(RedditShare.EXTRA_SHARED_TEXT);
    if (sharedText != null) {
        searchEditText.setText(sharedText);
        UtilMethods.revealView(clearSearchBoxButton);
        clearSearchBoxButtonFlag = true;
        initializeSearch();//from   ww  w. jav  a 2 s.c om
    }

}

From source file:com.sxt.superqq.activity.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CODE_SETNICK) {
            SuperQQApplication.currentUserNick = data.getStringExtra("edittext");

            progressShow = true;/*  w  w w.  ja  v  a  2 s.co  m*/
            final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
            pd.setCanceledOnTouchOutside(false);
            pd.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    progressShow = false;
                }
            });
            pd.setMessage(getString(R.string.Is_landing));
            pd.show();

            final long start = System.currentTimeMillis();
            // sdk??
            EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {

                @Override
                public void onSuccess() {

                    if (!progressShow) {
                        return;
                    }
                    // ?????
                    SuperQQApplication.getInstance().setUserName(currentUsername);
                    SuperQQApplication.getInstance().setPassword(currentPassword);

                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.setMessage(getString(R.string.list_is_for));
                        }
                    });
                    try {
                        // ** ?logout???
                        // ** manually load all local groups and
                        // conversations in case we are auto login
                        EMGroupManager.getInstance().loadAllGroups();
                        EMChatManager.getInstance().loadAllConversations();
                        //??
                        processContactsAndGroups();
                    } catch (Exception e) {
                        e.printStackTrace();
                        //?????
                        runOnUiThread(new Runnable() {
                            public void run() {
                                pd.dismiss();
                                SuperQQApplication.getInstance().logout(null);
                                Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1)
                                        .show();
                            }
                        });
                        return;
                    }
                    //?nickname ios?nick
                    boolean updatenick = EMChatManager.getInstance()
                            .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim());
                    if (!updatenick) {
                        Log.e("LoginActivity", "update current user nick fail");
                    }
                    if (!LoginActivity.this.isFinishing())
                        pd.dismiss();
                    // ?
                    startActivity(new Intent(LoginActivity.this, MainActivity.class));
                    finish();
                }

                @Override
                public void onProgress(int progress, String status) {
                }

                @Override
                public void onError(final int code, final String message) {
                    if (!progressShow) {
                        return;
                    }
                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });

        }
    }
}

From source file:com.grass.caishi.cc.DemoHXSDKHelper.java

/**
 * ? ?UI???UI??????? activityList.size() <= 0 ????????Activity Stack
 *//*  w w w .jav  a  2 s. c o m*/
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) {
                            // TODO Auto-generated method stub
                            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:cc.flydev.launcher.InstallShortcutReceiver.java

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

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    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
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.aibasis.parent.DemoHXSDKHelper.java

/**
 * ?/*from w w w. j a v a2s  .  com*/
 * ?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) {
                            // TODO Auto-generated method stub
                            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:cn.hbm.superwechat.DemoHXSDKHelper.java

/**
 * ?//from   ww w  . java  2s  .c o 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) {
                            // TODO Auto-generated method stub
                            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);

        }

    });
}