Example usage for android.content Intent toString

List of usage examples for android.content Intent toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.undatech.opaque.RemoteCanvasActivity.java

/**
 * Launches a remote desktop session using a .vv file.
 * @param i/*ww  w. j  a  va  2s  .co  m*/
 * @return the vv file name or NULL if no file was discovered.
 */
private String startSessionFromVvFile(Intent i) {
    final Uri data = i.getData();
    String vvFileName = null;

    android.util.Log.d(TAG, "got intent: " + i.toString());

    if (data != null) {
        android.util.Log.d(TAG, "got data: " + data.toString());

        if (data.toString().startsWith("http")) {
            android.util.Log.d(TAG, "Intent is with http scheme.");
            final String tempVvFile = getFilesDir() + "/tempfile.vv";
            vvFileName = tempVvFile;
            // Spin up a thread to grab the file over the network.
            Thread t = new Thread() {
                @Override
                public void run() {
                    try {
                        URL url = new URL(data.toString());
                        File file = new File(tempVvFile);

                        URLConnection ucon = url.openConnection();
                        InputStream is = ucon.getInputStream();
                        BufferedInputStream bis = new BufferedInputStream(is);

                        ByteArrayBuffer baf = new ByteArrayBuffer(3000);
                        int current = 0;
                        while ((current = bis.read()) != -1) {
                            baf.append((byte) current);
                        }

                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write(baf.toByteArray());
                        fos.close();

                        synchronized (RemoteCanvasActivity.this) {
                            RemoteCanvasActivity.this.notify();
                        }
                    } catch (Exception e) {
                    }
                }
            };
            t.start();

            synchronized (this) {
                try {
                    this.wait(5000);
                } catch (InterruptedException e) {
                    vvFileName = null;
                    e.printStackTrace();
                }
            }
        } else if (data.toString().startsWith("file")) {
            android.util.Log.d(TAG, "Intent is with file scheme.");
            vvFileName = data.getPath();
        } else if (data.toString().startsWith("content")) {
            android.util.Log.d(TAG, "Intent is with content scheme.");

            String[] projection = { MediaStore.MediaColumns.DATA };
            ContentResolver resolver = getApplicationContext().getContentResolver();
            Cursor cursor = resolver.query(data, projection, null, null, null);
            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    vvFileName = cursor.getString(0);
                }
                cursor.close();
            }
        }

        File f = new File(vvFileName);
        android.util.Log.d(TAG, "got filename: " + vvFileName);

        if (f.exists()) {
            android.util.Log.d(TAG, "Initializing session from vv file: " + vvFileName);
            connection = new ConnectionSettings("defaultSettings");
            connection.loadFromSharedPreferences(getApplicationContext());
        } else {
            vvFileName = null;
            // Quit with an error if the file does not exist.
            MessageDialogs.displayMessageAndFinish(this, R.string.vv_file_not_found,
                    R.string.error_dialog_title);
        }
    }
    return vvFileName;
}

From source file:com.ereinecke.eatsafe.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if (intent == null) {
        Logd(LOG_TAG, "in onActivityResult, null intent received");
        Logd(LOG_TAG, "   requestCode: " + requestCode);
        Logd(LOG_TAG, "   resultCode: " + resultCode);
        return;//from www.  j  a  v  a 2s .com
    }
    Logd(LOG_TAG,
            "requestCode: " + requestCode + "; resultCode: " + resultCode + "; intent: " + intent.toString());

    switch (requestCode) {

    case IntentIntegrator.REQUEST_CODE: {
        /* Catching result from barcode scan */
        if (resultCode == RESULT_OK) {
            IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
            Logd(LOG_TAG, "IntentResult: " + result.toString());

            String barcode = result.getContents();
            if (result.getContents() == null) {
                SuperActivityToast.create(this, Utility.errorStyle()).setText(getString(R.string.result_failed))
                        .show();
            } else {
                Logd(LOG_TAG, "Scan result: " + result.toString());
                // Have a (potentially) valid barcode, update text view and fetch product info
                SearchFragment.handleScanResult(barcode);
                // TODO: Need a progress spinner here
                Intent productIntent = new Intent(this, OpenFoodService.class);
                productIntent.putExtra(Constants.BARCODE_KEY, barcode);
                productIntent.setAction(Constants.ACTION_FETCH_PRODUCT);
                startService(productIntent);
            }
        } else {
            Logd(LOG_TAG, "Error scanning barcode: " + resultCode);
        }
        break;
    }

    case Constants.CAMERA_IMAGE_REQUEST: {
        /* Catching result from camera */
        if (resultCode == RESULT_OK) {
            scanMedia(photoReceived.toString());
            UploadFragment.updateImage(photoReceived);
        } else { // capture image request came back with error
            Logd(LOG_TAG, "Error taking photo: " + resultCode);
        }
        break;
    }

    case Constants.GALLERY_IMAGE_REQUEST: {
        /* Catching result from gallery */

        InputStream imageStream;
        if (resultCode == RESULT_OK) {
            final Uri imageUri = intent.getData();
            try {
                // TODO: figure out what imageStream might be needed for?
                imageStream = getContentResolver().openInputStream(imageUri);
                Logd(LOG_TAG, "Gallery image request returned Uri: " + imageUri);
                UploadFragment.updateImageFromGallery(imageUri);
            } catch (FileNotFoundException e) {
                Logd(LOG_TAG, e.getMessage());
            }

        } else {
            Logd(LOG_TAG, "Error picking photo from gallery: " + resultCode);
        }
        break;
    }

    default: {
        Logd(LOG_TAG, "Unexpected requestCode received: " + requestCode);
        // super.onActivityResult(requestCode, resultCode, intent);
    }
    }
}

From source file:com.actionlauncher.api.LiveWallpaperSource.java

private synchronized void publishCurrentState(final ComponentName subscriber) {
    String token = mSubscriptions.get(subscriber);
    if (TextUtils.isEmpty(token)) {
        LOGD("Not active, canceling update, id=" + mName);
        return;/*from www  . jav a  2s .  c  o m*/
    }

    // Publish update
    Intent intent = new Intent(ACTION_PUBLISH_STATE).setComponent(subscriber).putExtra(EXTRA_TOKEN, token)
            .putExtra(EXTRA_STATE, (mCurrentState != null) ? mCurrentState.toBundle() : null);
    try {
        ComponentName returnedSubscriber = startService(intent);
        if (returnedSubscriber == null) {
            LOGE("Update wasn't published because subscriber no longer exists" + ", id=" + mName);
            // Unsubscribe the now-defunct subscriber
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    processSubscribe(subscriber, null);
                }
            });
        } else {
            LOGD("publishCurrentState(): successfully started service " + returnedSubscriber.toString()
                    + " with intent " + intent.toString());
        }
    } catch (SecurityException e) {
        LOGE("Couldn't publish update, id=" + mName, e);
    }
}

From source file:org.csploit.android.services.UpdateService.java

/**
 * if mContentIntent is null delete our notification,
 * else assign it to the notification onClick
 *//*from  w ww.j a v a 2 s .c  o m*/
private void finishNotification() {
    boolean errorOccurred;
    Intent contentIntent;

    errorOccurred = mCurrentTask.errorOccurred;
    contentIntent = mCurrentTask.haveIntent() ? mCurrentTask.buildIntent() : null;

    if (errorOccurred || contentIntent == null) {
        Logger.debug("deleting notifications");
        if (mNotificationManager != null)
            mNotificationManager.cancel(NOTIFICATION_ID);
    } else {
        Logger.debug("assign '" + contentIntent.toString() + "' to notification");
        if (mBuilder != null && mNotificationManager != null) {
            mBuilder.setContentIntent(
                    PendingIntent.getActivity(this, DOWNLOAD_COMPLETE_CODE, contentIntent, 0));
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        }
    }
    if (mReceiver != null)
        unregisterReceiver(mReceiver);
    mReceiver = null;
    mBuilder = null;
    mNotificationManager = null;
}

From source file:com.java2s.intents4.IntentsDemo4Activity.java

private Intent createIntentFromEditTextFields() {
    String theAction = actionText.getText().toString().trim();
    String theUri = uriText.getText().toString().trim();
    String theMimeType = mimeTypeText.getText().toString().trim();

    Intent intent = new Intent();
    if (theAction.length() != 0) {
        intent.setAction(theAction);/*  w  ww .jav  a  2  s .c om*/
    }
    intentHasBothUriAndType = false;
    if (theUri.length() != 0 && theMimeType.length() != 0) {
        intentHasBothUriAndType = true;
        intent.setDataAndType(Uri.parse(theUri), theMimeType);
    } else if (theUri.length() != 0) {
        intent.setData(Uri.parse(theUri));
    } else if (theMimeType.length() != 0) {
        intent.setType(theMimeType);
    }

    if (intentCategoriesLayout != null) {
        int count = intentCategoriesLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            String cat = ((EditText) ((ViewGroup) intentCategoriesLayout.getChildAt(i)).getChildAt(1)).getText()
                    .toString().trim();
            if (cat.length() != 0) {
                intent.addCategory(cat);
            }
        }
    }
    Log.i(CLASSNAME, intent.toString());
    return intent;
}

From source file:com.android.calendar.AllInOneActivity.java

@Override
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();
    if (DEBUG)//  w  ww .  java  2  s. c  o  m
        Log.d(TAG, "New intent received " + intent.toString());
    // Don't change the date if we're just returning to the app's home
    if (Intent.ACTION_VIEW.equals(action) && !intent.getBooleanExtra(Utils.INTENT_KEY_HOME, false)) {
        long millis = parseViewAction(intent);
        if (millis == -1) {
            millis = Utils.timeFromIntentInMillis(intent);
        }
        if (millis != -1 && mViewEventId == -1 && mController != null) {
            Time time = new Time(mTimeZone);
            time.set(millis);
            time.normalize(true);
            mController.sendEvent(this, EventType.GO_TO, time, time, -1, ViewType.CURRENT);
        }
    }
}

From source file:com.i2max.i2smartwork.common.work.WorkDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {
    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || filesList.size() <= 0) {
        targetLayout.setVisibility(View.GONE);
    } else {/*from   www  .j a va  2 s. c  o  m*/
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = null;
                    if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                        //i2viewer ? ( conv_yn='Y')
                        intent = IntentUtil.getI2ViewerIntent(
                                FormatUtil.getStringValidate(fileMap.get("file_id")),
                                FormatUtil.getStringValidate(fileMap.get("file_nm")));
                        getActivity().startActivity(intent);
                    } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                            || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                        intent = IntentUtil.getVideoPlayIntent(downloadURL);
                    } else {
                        //? ??
                        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                        Bundle bundle = new Bundle();
                        bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                        intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                        Log.d(TAG, "intent:" + intent.toString());
                    }
                    getActivity().startActivity(intent);

                }
            });

            targetLayout.addView(fileView);
        }

    }
}

From source file:org.sigimera.app.android.GCMIntentService.java

@Override
protected final void onMessage(final Context context, final Intent message) {
    final Intent msg = message;
    this.mainThreadHandler.post(new Runnable() {
        public void run() {
            ApplicationController controller = ApplicationController.getInstance();
            controller.init(getApplicationContext(), getSharedPreferences(Constants.PREFS_NAME, 0), null);
            String authToken = controller.getSharedPreferences().getString("auth_token", null);
            final String type = msg.getStringExtra("sig_message_type");
            if (type.equalsIgnoreCase("NEW_CRISIS")) {
                /**//from   w w  w  .  ja  v  a 2 s.c o m
                 * XXX: Blocks UI: Shift this code into a separate
                 * background thread
                 */
                Crisis crisis = PersistanceController.getInstance().getCrisis(authToken,
                        msg.getStringExtra("crisis_id"));

                StringBuffer message = new StringBuffer();
                if (crisis != null) {
                    message.append(crisis.getID());
                    message.append(" was stored successfully!");
                } else {
                    message.append("Not able to get crisis!");
                }
                Toast.makeText(getApplicationContext(), message.toString(), Toast.LENGTH_LONG).show();
            } else if (type.equalsIgnoreCase("PING")) {
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

                Intent notificationIntent = new Intent();
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

                Notification notification = new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("Sigimera PING!")
                        .setContentText("Congratulations, push notifcation received!")
                        .setSmallIcon(R.drawable.sigimera_logo).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build();

                mNotificationManager.notify(Constants.PING_ID, notification);
            } else if (type.equalsIgnoreCase("CRISIS_ALERT")) {
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

                /**
                 * XXX: Not working with random ID. That makes always the
                 * latest notification clickable, but not the older ones.
                 */
                int notificationID = new Random().nextInt();
                Intent notificationIntent = new Intent(getApplicationContext(), CrisisAlertActivity.class);
                notificationIntent.putExtra("notification_id", notificationID);
                notificationIntent.putExtra("crisis_id", msg.getStringExtra("crisis_id"));
                notificationIntent.putExtra("crisis_type", msg.getStringExtra("crisis_type"));
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

                Notification notification = new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("CRISIS ALERT!")
                        .setContentText("Crisis found: " + msg.getStringExtra("crisis_id"))
                        .setSmallIcon(R.drawable.alert_red).setOngoing(true).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build();

                mNotificationManager.notify(notificationID, notification);
            } else if (type.equalsIgnoreCase("SHARED_CRISIS")) {
                Intent intent = new Intent(GCMIntentService.this, CrisisActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Constants.CRISIS_ID, msg.getStringExtra("crisis_id"));
                intent.putExtra(Constants.WINDOW_TYPE, Constants.WINDOW_TYPE_SHARED_CRISIS);
                startActivity(intent);
            } else if (type.equalsIgnoreCase("UNREGISTER_DEVICE")) {
                GCMRegistrar.unregister(ApplicationController.getInstance().getApplicationContext());
            } else if (type.equalsIgnoreCase("REFRESH")) {
                LocationUpdaterHttpHelper locUpdater = new LocationUpdaterHttpHelper();
                Location loc = LocationController.getInstance().getLastKnownLocation();
                if (loc != null) {
                    String latitude = loc.getLatitude() + "";
                    String longitude = loc.getLongitude() + "";
                    if (authToken != null) {
                        locUpdater.execute(authToken, latitude, longitude);
                    }
                } else {
                    // TODO: Notify the user that the update location flow
                    // has not worked.
                }
            }
        }
    });
}

From source file:com.i2max.i2smartwork.common.conference.ConferenceDetailViewFragment.java

public void setFilesLayout(String title, LinearLayout targetLayout, Object object) {

    final List<LinkedTreeMap<String, String>> filesList = (List<LinkedTreeMap<String, String>>) object;
    if (filesList == null || (filesList != null && filesList.size() <= 0)) {
        targetLayout.setVisibility(View.GONE);
    } else {/*w w w . j  a  va 2  s .  co m*/
        Log.e(TAG, "fileList size =" + filesList.size());
        targetLayout.setVisibility(View.VISIBLE);
        targetLayout.removeAllViews();
        //addTitleView
        LinearLayout.LayoutParams tvParam = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvParam.setMargins(0, DisplayUtil.dip2px(getActivity(), 12), 0, DisplayUtil.dip2px(getActivity(), 10));

        TextView tvTitle = new TextView(getActivity());
        tvTitle.setLayoutParams(tvParam);
        if (Build.VERSION.SDK_INT < 23) {
            tvTitle.setTextAppearance(getActivity(), android.R.style.TextAppearance_Material_Medium);
        } else {
            tvTitle.setTextAppearance(android.R.style.TextAppearance_Material_Medium);
        }
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
        tvTitle.setTextColor(getResources().getColor(R.color.text_color_black));
        tvTitle.setText(title);

        targetLayout.addView(tvTitle);

        //addFilesView
        for (int i = 0; i < filesList.size(); i++) {
            final LinkedTreeMap<String, String> fileMap = filesList.get(i);
            LayoutInflater inflater = (LayoutInflater) getActivity()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View fileView = inflater.inflate(R.layout.view_item_file, null);

            ImageView ivIcFileExt = (ImageView) fileView.findViewById(R.id.iv_ic_file_ext);
            TextView tvFileNm = (TextView) fileView.findViewById(R.id.tv_file_nm);

            //??  ? 
            ivIcFileExt.setImageResource(R.drawable.ic_file_doc);
            String fileNm = FormatUtil.getStringValidate(fileMap.get("file_nm"));
            tvFileNm.setText(fileNm);
            FileUtil.setFileExtIcon(ivIcFileExt, fileNm);
            final String fileExt = FileUtil.getFileExtsion(fileNm);
            final String downloadURL = I2UrlHelper.File
                    .getDownloadFile(FormatUtil.getStringValidate(fileMap.get("file_id")));

            fileView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    try {
                        Intent intent = null;
                        if ("Y".equals(FormatUtil.getStringValidate(fileMap.get("conv_yn")))) {
                            //i2viewer ? ( conv_yn='Y')
                            intent = IntentUtil.getI2ViewerIntent(
                                    FormatUtil.getStringValidate(fileMap.get("file_id")),
                                    FormatUtil.getStringValidate(fileMap.get("file_nm")));
                            getActivity().startActivity(intent);
                        } else if ("mp4".equalsIgnoreCase(fileExt) || "fla".equalsIgnoreCase(fileExt)
                                || "wmv".equalsIgnoreCase(fileExt) || "avi".equalsIgnoreCase(fileExt)) { //video
                            intent = IntentUtil.getVideoPlayIntent(downloadURL);
                        } else {
                            //? ??
                            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadURL));
                            Bundle bundle = new Bundle();
                            bundle.putString("Authorization", I2UrlHelper.getTokenAuthorization());
                            intent.putExtra(Browser.EXTRA_HEADERS, bundle);
                            Log.d(TAG, "intent:" + intent.toString());
                        }
                        getActivity().startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getActivity(),
                                "I2Viewer? ?  .\n  ? ?.",
                                Toast.LENGTH_LONG).show();
                        //TODO ? ? ?   URL
                    }
                }
            });

            targetLayout.addView(fileView);
        }

    }
}

From source file:org.csploit.android.core.UpdateService.java

/**
 * if mContentIntent is null delete our notification,
 * else assign it to the notification onClick
 *///from  ww  w.  j av a  2  s .  co  m
private void finishNotification() {
    boolean errorOccurred;
    Intent contentIntent;

    synchronized (mCurrentTask) {
        errorOccurred = mCurrentTask.errorOccurred;
        contentIntent = mCurrentTask.contentIntent;
    }

    if (errorOccurred || contentIntent == null) {
        Logger.debug("deleting notifications");
        if (mNotificationManager != null)
            mNotificationManager.cancel(NOTIFICATION_ID);
    } else {
        Logger.debug("assign '" + contentIntent.toString() + "' to notification");
        if (mBuilder != null && mNotificationManager != null) {
            mBuilder.setContentIntent(
                    PendingIntent.getActivity(this, DOWNLOAD_COMPLETE_CODE, contentIntent, 0));
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        }
    }
    if (mReceiver != null)
        unregisterReceiver(mReceiver);
    mReceiver = null;
    mBuilder = null;
    mNotificationManager = null;
}