Example usage for android.content Intent getStringArrayListExtra

List of usage examples for android.content Intent getStringArrayListExtra

Introduction

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

Prototype

public ArrayList<String> getStringArrayListExtra(String name) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.wizardsofm.deskclock.alarms.AlarmActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent i) {

    super.onActivityResult(requestCode, resultCode, i);
    switch (requestCode) {
    case 100://  ww  w. j  a  va 2  s . c o  m
        if (resultCode == RESULT_OK && i != null) {
            ArrayList<String> result = i.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            if (result.get(0).toUpperCase().contains("SHUT UP".toUpperCase())) {
                r.stop();
                alarmStopped = true;
            } else {
            }
        }
        break;
    default:
        break;
    }

}

From source file:eu.codeplumbers.cosi.services.CosiFileDownloadService.java

@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiFileDownloadService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    Device device = Device.registeredDevice();

    // cozy register device url
    fileUrl = device.getUrl() + "/ds-api/data/";

    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();/*from  ww  w. j a  v  a2s  .  co m*/

    if (isNetworkAvailable()) {
        try {

            ArrayList<String> fileStrings = intent.getStringArrayListExtra("fileToDownload");

            for (int i = 0; i < fileStrings.size(); i++) {
                File file = File.load(File.class, Long.valueOf(fileStrings.get(i)));
                String binaryRemoteId = file.getRemoteId();

                if (!binaryRemoteId.isEmpty()) {
                    mBuilder.setProgress(100, 0, false);
                    mBuilder.setContentText("Downloading file: " + file.getName());
                    mNotifyManager.notify(notification_id, mBuilder.build());

                    URL urlO = null;
                    try {
                        urlO = new URL(fileUrl + binaryRemoteId + "/binaries/file");
                        HttpURLConnection conn = (HttpURLConnection) urlO.openConnection();
                        conn.setConnectTimeout(5000);
                        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
                        conn.setRequestProperty("Authorization", authHeader);
                        conn.setDoInput(true);
                        conn.setRequestMethod("GET");

                        conn.connect();
                        int lenghtOfFile = conn.getContentLength();

                        // read the response
                        int status = conn.getResponseCode();

                        if (status >= HttpURLConnection.HTTP_BAD_REQUEST) {
                            EventBus.getDefault()
                                    .post(new FileSyncEvent(SERVICE_ERROR, conn.getResponseMessage()));
                            stopSelf();
                        } else {
                            int count = 0;
                            InputStream in = new BufferedInputStream(conn.getInputStream(), 8192);

                            java.io.File newFile = file.getLocalPath();

                            if (!newFile.exists()) {
                                newFile.createNewFile();
                            }

                            // Output stream to write file
                            OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory()
                                    + java.io.File.separator + Constants.APP_DIRECTORY + java.io.File.separator
                                    + "files" + file.getPath() + "/" + file.getName());

                            byte data[] = new byte[1024];
                            long total = 0;
                            while ((count = in.read(data)) != -1) {
                                total += count;

                                mBuilder.setProgress(lenghtOfFile, (int) total, false);
                                mBuilder.setContentText("Downloading file: " + file.getName());
                                mNotifyManager.notify(notification_id, mBuilder.build());

                                // writing data to file
                                output.write(data, 0, count);
                            }

                            // flushing output
                            output.flush();

                            // closing streams
                            output.close();
                            in.close();

                            file.setDownloaded(true);
                            file.save();
                        }
                    } catch (MalformedURLException e) {
                        EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
                        stopSelf();
                    } catch (ProtocolException e) {
                        EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
                        stopSelf();
                    } catch (IOException e) {
                        EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
                        stopSelf();
                    }
                }
            }

            mNotifyManager.cancel(notification_id);
            EventBus.getDefault().post(new FileSyncEvent(REFRESH, "Sync OK"));
        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}

From source file:com.example.michel.facetrack.FaceTrackerActivity.java

/**
 * Callback for speech recognition activity
 * *//* www  . j  a  v  a  2s  .  com*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.out.println("hello #");
    switch (requestCode) {
    case SPEECH_RECOGNITION_CODE: {
        if (resultCode == RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            updateState(result.get(0));
        } else {
            updateState("");
        }
        break;
    }
    }
}

From source file:com.example.android.cardreader.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_OK && resultCode == RESULT_OK) {
        System.out.println("Going into results");
        ArrayList<String> thingsYouSaid = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        String result = thingsYouSaid.get(0);
        System.out.println("Android Heard: " + result);
    }//  w ww  .  j a  v  a2  s .c o  m
}

From source file:ir.occc.android.irc.activity.ConversationActivity.java

/**
 * On activity result/*ww w. j  a  va2s.c  o  m*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        // ignore other result codes
        return;
    }

    switch (requestCode) {
    case REQUEST_CODE_SPEECH:
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            ((EditText) findViewById(R.id.input)).setText(matches.get(0));
        }
        break;
    case REQUEST_CODE_JOIN:
        joinChannelBuffer = data.getExtras().getString("channel");
        break;
    case REQUEST_CODE_USERS:
        Intent intent = new Intent(this, UserActivity.class);
        intent.putExtra(Extra.USER, data.getStringExtra(Extra.USER));
        startActivityForResult(intent, REQUEST_CODE_USER);
        break;
    case REQUEST_CODE_NICK_COMPLETION:
        insertNickCompletion((EditText) findViewById(R.id.input), data.getExtras().getString(Extra.USER));
        break;
    case REQUEST_CODE_USER:
        final int actionId = data.getExtras().getInt(Extra.ACTION);
        final String nickname = data.getExtras().getString(Extra.USER);
        final IRCConnection connection = binder.getService().getConnection(server.getId());
        final String conversation = server.getSelectedConversation();
        final Handler handler = new Handler();

        // XXX: Implement me - The action should be handled after onResume()
        //                     to catch the broadcasts... now we just wait a second
        // Yes .. that's very ugly - we need some kind of queue that is handled after onResume()

        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    // Do nothing
                }

                String nicknameWithoutPrefix = nickname;

                while (nicknameWithoutPrefix.startsWith("@") || nicknameWithoutPrefix.startsWith("+")
                        || nicknameWithoutPrefix.startsWith(".") || nicknameWithoutPrefix.startsWith("%")) {
                    // Strip prefix(es) now
                    nicknameWithoutPrefix = nicknameWithoutPrefix.substring(1);
                }

                switch (actionId) {
                case User.ACTION_REPLY:
                    final String replyText = nicknameWithoutPrefix + ": ";
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            EditText input = (EditText) findViewById(R.id.input);
                            input.setText(replyText);
                            input.setSelection(replyText.length());
                        }
                    });
                    break;
                case User.ACTION_QUERY:
                    Conversation query = server.getConversation(nicknameWithoutPrefix);
                    if (query == null) {
                        // Open a query if there's none yet
                        query = new Query(nicknameWithoutPrefix);
                        query.setHistorySize(binder.getService().getSettings().getHistorySize());
                        server.addConversation(query);

                        Intent intent = Broadcast.createConversationIntent(Broadcast.CONVERSATION_NEW,
                                server.getId(), nicknameWithoutPrefix);
                        binder.getService().sendBroadcast(intent);
                    }
                    break;
                case User.ACTION_OP:
                    connection.op(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_DEOP:
                    connection.deOp(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_VOICE:
                    connection.voice(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_DEVOICE:
                    connection.deVoice(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_KICK:
                    connection.kick(conversation, nicknameWithoutPrefix);
                    break;
                case User.ACTION_BAN:
                    connection.ban(conversation, nicknameWithoutPrefix + "!*@*");
                    break;
                }
            }
        }.start();

        break;
    }
}

From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("requestcode", requestCode + "");
    if (data.getExtras() == null)
        return;//w w  w  . j  av  a 2s  .c  o  m
    Object bundle = data.getExtras().get("data");
    Log.d("HELO", bundle.getClass().toString());
    switch (requestCode) {
    case 1:
        super.onActivityResult(requestCode, resultCode, data);
        ArrayList<String> imageIds = data.getStringArrayListExtra("data");
        if (imageIds != null)
            Log.d("Ids!", imageIds.toString());
        AddImagesToAlbumAsync imageAsync = new AddImagesToAlbumAsync(imageIds,
                ((ImgurHoloActivity) getActivity()).getApiCall(), albumId);
        imageAsync.execute();
        break;
    }
}

From source file:com.hang.exoplayer.PlayService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        boolean playOrPauseAction = intent.getBooleanExtra(ACTION_PLAY_PAUSE, false);
        boolean loadAction = intent.getBooleanExtra(ACTION_LOAD, false);
        boolean exitAction = intent.getBooleanExtra(ACTION_EXIT, false);
        boolean previousAction = intent.getBooleanExtra(ACTION_PREVIOUS, false);
        boolean nextAction = intent.getBooleanExtra(ACTION_NEXT, false);
        if (playOrPauseAction) {
            boolean isPlaying = SimplePlayer.getInstance().isPlaying();
            if (isPlaying) {
                pause();//  ww w .j a  v  a2 s.c  om
            } else {
                play();
            }
        } else if (loadAction) {
            ArrayList<String> audioList = intent.getStringArrayListExtra(KEY_LIST);
            int currentPosition = intent.getIntExtra(KEY_POS, 0);
            if (playAddresses.containsAll(audioList) && mCurrentPosition == currentPosition) {
            } else {
                mCurrentPosition = currentPosition;
                playAddresses.clear();
                playAddresses.addAll(audioList);
            }
            play();
        } else if (exitAction) {
            Log.d(TAG, "start exitAction");
            stopForeground(true);
            pause();
            if (playStatusReceiver != null) {
                LocalBroadcastManager.getInstance(this).unregisterReceiver(playStatusReceiver);
                playStatusReceiver = null;
                Log.d(TAG, "unregisterReceiver exitAction");
            }
            dismissNotification();
            stopSelf();
            Log.d(TAG, "end exitAction");
        } else if (previousAction) {
            if (mCurrentPosition > 0) {
                --mCurrentPosition;
                play();
            } else {
                Toast.makeText(this, "?~", Toast.LENGTH_SHORT).show();
            }
        } else if (nextAction) {
            if (mCurrentPosition < playAddresses.size() - 1) {
                ++mCurrentPosition;
                play();
            } else {
                Toast.makeText(this, "??~", Toast.LENGTH_SHORT).show();
            }
        }
    }
    return super.onStartCommand(intent, flags, startId);

}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private void handleSpeechRecognitionActivityResult(int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && null != data) {
        ArrayList<String> guesses = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        notifySpeechRecognitionListeners(guesses);
    }/*from  w ww  .j a  v a  2s. c o  m*/
}

From source file:radu.pidroid.Controller.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == SPEECH_RECOGNITION_REQUEST_CODE && intent != null) {
        ArrayList<String> predictions = intent.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        mRecogniser.recogniseExecuteCommand(predictions);
    } // if//from  w  w w  . j av  a  2  s  .co m

    super.onActivityResult(requestCode, resultCode, intent);
}

From source file:com.amaze.carbonfilemanager.services.ExtractService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
    Bundle b = new Bundle();
    String file = intent.getStringExtra(KEY_PATH_ZIP);
    String extractPath = intent.getStringExtra(KEY_PATH_EXTRACT);

    if (extractPath != null) {
        // a custom dynamic path to extract files to
        epath = extractPath;/*from w ww.j  a va 2s  . c  o  m*/
    } else {

        epath = PreferenceManager.getDefaultSharedPreferences(this).getString(KEY_PATH_EXTRACT, file);
    }
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    entries = intent.getStringArrayListExtra(KEY_ENTRIES_ZIP);

    b.putString(KEY_PATH_ZIP, file);

    totalSize = getTotalSize(file);
    progressHandler = new ProgressHandler(1, totalSize);

    progressHandler.setProgressListener(new ProgressHandler.ProgressListener() {
        @Override
        public void onProgressed(String fileName, int sourceFiles, int sourceProgress, long totalSize,
                long writtenSize, int speed) {
            publishResults(startId, fileName, sourceFiles, sourceProgress, totalSize, writtenSize, speed,
                    false);
        }
    });

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mBuilder = new NotificationCompat.Builder(cd);
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setContentTitle(getResources().getString(R.string.extracting))
            .setContentText(new File(file).getName()).setSmallIcon(R.drawable.ic_zip_box_grey600_36dp);
    startForeground(Integer.parseInt("123" + startId), mBuilder.build());

    new DoWork().execute(b);
    return START_STICKY;
}