Пример #1
0
 public static boolean a(
     Context context, AdLauncherIntentInfoParcel adlauncherintentinfoparcel, n n1) {
   if (adlauncherintentinfoparcel == null) {
     b.a(5);
     return false;
   }
   Intent intent = new Intent();
   if (TextUtils.isEmpty(adlauncherintentinfoparcel.c)) {
     b.a(5);
     return false;
   }
   if (!TextUtils.isEmpty(adlauncherintentinfoparcel.d)) {
     intent.setDataAndType(Uri.parse(adlauncherintentinfoparcel.c), adlauncherintentinfoparcel.d);
   } else {
     intent.setData(Uri.parse(adlauncherintentinfoparcel.c));
   }
   intent.setAction("android.intent.action.VIEW");
   if (!TextUtils.isEmpty(adlauncherintentinfoparcel.e)) {
     intent.setPackage(adlauncherintentinfoparcel.e);
   }
   if (!TextUtils.isEmpty(adlauncherintentinfoparcel.f)) {
     String as[] = adlauncherintentinfoparcel.f.split("/", 2);
     if (as.length < 2) {
       (new StringBuilder("Could not parse component name from open GMSG: "))
           .append(adlauncherintentinfoparcel.f);
       b.a(5);
       return false;
     }
     intent.setClassName(as[0], as[1]);
   }
   adlauncherintentinfoparcel = adlauncherintentinfoparcel.g;
   if (!TextUtils.isEmpty(adlauncherintentinfoparcel)) {
     int i;
     try {
       i = Integer.parseInt(adlauncherintentinfoparcel);
     }
     // Misplaced declaration of an exception variable
     catch (AdLauncherIntentInfoParcel adlauncherintentinfoparcel) {
       b.a(5);
       i = 0;
     }
     intent.addFlags(i);
   }
   try {
     (new StringBuilder("Launching an intent: ")).append(intent.toURI());
     b.a(2);
     context.startActivity(intent);
   }
   // Misplaced declaration of an exception variable
   catch (Context context) {
     context.getMessage();
     b.a(5);
     return false;
   }
   if (n1 == null) {
     break MISSING_BLOCK_LABEL_231;
   }
   n1.l();
   return true;
 }
Пример #2
0
  /**
   * @param context
   * @param intent
   * @param appPath
   * @return
   */
  public static String resolvePhotoFromIntent(Context context, Intent intent, String appPath) {
    if (context == null || intent == null || appPath == null) {
      LogUtil.e(
          LogUtil.getLogUtilsTag(DemoUtils.class), "resolvePhotoFromIntent fail, invalid argument");
      return null;
    }
    Uri uri = Uri.parse(intent.toURI());
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
    try {

      String pathFromUri = null;
      if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
        // if it is a picasa image on newer devices with OS 3.0 and up
        if (uri.toString().startsWith("content://com.google.android.gallery3d")) {
          // Do this in a background thread, since we are fetching a
          // large image from the web
          pathFromUri = saveBitmapToLocal(appPath, createChattingImageByUri(intent.getData()));
        } else {
          // it is a regular local image file
          pathFromUri = cursor.getString(columnIndex);
        }
        cursor.close();
        LogUtil.d(TAG, "photo from resolver, path: " + pathFromUri);
        return pathFromUri;
      } else {

        if (intent.getData() != null) {
          pathFromUri = intent.getData().getPath();
          if (new File(pathFromUri).exists()) {
            LogUtil.d(TAG, "photo from resolver, path: " + pathFromUri);
            return pathFromUri;
          }
        }

        // some devices (OS versions return an URI of com.android
        // instead of com.google.android
        if ((intent.getAction() != null) && (!(intent.getAction().equals("inline-data")))) {
          // use the com.google provider, not the com.android
          // provider.
          // Uri.parse(intent.getData().toString().replace("com.android.gallery3d","com.google.android.gallery3d"));
          pathFromUri = saveBitmapToLocal(appPath, (Bitmap) intent.getExtras().get("data"));
          LogUtil.d(TAG, "photo from resolver, path: " + pathFromUri);
          return pathFromUri;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }

    LogUtil.e(TAG, "resolve photo from intent failed ");
    return null;
  }
  void updateResult() {
    Intent intent = new Intent();

    long id = mSpinnerAction.getSelectedItemId();
    if (id == 0) {
      intent.putExtra(ShoppingListIntents.EXTRA_ACTION, ShoppingListIntents.TASK_CLEAN_UP_LIST);
    }
    intent.putExtra(ShoppingListIntents.EXTRA_DATA, mUri.toString());

    String description = mDescriptionAction + ": " + mDescriptionShoppingList;
    intent.putExtra(AutomationIntents.EXTRA_DESCRIPTION, description);

    if (debug) {
      Log.i(TAG, "Created intent (URI)   : " + intent.toURI());
    }
    if (debug) {
      Log.i(TAG, "Created intent (String): " + intent.toString());
    }

    setResult(RESULT_OK, intent);
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    // Need to enable logging here since this callback gets called when the app is installed, not
    // launched.
    // TapjoyLog.enableLogging(true);

    TapjoyLog.i(REFERRAL_TRACKING, "----------------------------------------");
    TapjoyLog.i(REFERRAL_TRACKING, "RECEIVED REFERRAL INFO");

    String uri = intent.toURI();

    TapjoyLog.i(REFERRAL_TRACKING, "referrer: [" + uri + "]");

    if (uri != null && uri.length() > 0) {
      int index = uri.indexOf("referrer=");

      if (index > -1) {
        // The last 4 characters are ";end" so remove them.
        String referrerURL = uri.substring(index, uri.length() - 4);

        TapjoyLog.i(REFERRAL_TRACKING, "Referral URI: [" + referrerURL + "]");

        // referralURL contains both referrer parameter and its value
        // ex: referralURL="referrer=com.package.app"
        SharedPreferences settings =
            context.getSharedPreferences(TapjoyConstants.TJC_PREFERENCE, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(TapjoyConstants.PREF_REFERRAL_URL, referrerURL);

        // For debugging the entire referrer data.
        editor.putString(TapjoyConstants.PREF_REFERRER_DEBUG, uri);

        editor.commit();
      } else {
        TapjoyLog.i(REFERRAL_TRACKING, "No Referral URL.");
      }
    }

    TapjoyLog.i(REFERRAL_TRACKING, "----------------------------------------");
  }
Пример #5
0
 @Test
 public void setUri_setsUri() throws Exception {
   Intent intent = new Intent();
   shadowOf(intent).setURI("http://foo");
   assertThat(intent.toURI(), is("http://foo"));
 }
Пример #6
0
  public static String resolvePhotoFromIntent(
      final Context ctx, final Intent data, final String dir) {
    if (ctx == null || data == null || dir == null) {
      Log.e(TAG, "resolvePhotoFromIntent fail, invalid argument");
      return null;
    }

    String filePath = null;

    final Uri uri = Uri.parse(data.toURI());
    Cursor cu = ctx.getContentResolver().query(uri, null, null, null, null);
    if (cu != null && cu.getCount() > 0) {
      try {
        cu.moveToFirst();
        final int pathIndex = cu.getColumnIndex(MediaColumns.DATA);
        Log.e(
            TAG,
            "orition: "
                + cu.getString(cu.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION)));
        filePath = cu.getString(pathIndex);
        Log.d(TAG, "photo from resolver, path:" + filePath);

      } catch (Exception e) {
        e.printStackTrace();
      }

    } else if (data.getData() != null) {
      filePath = data.getData().getPath();
      if (!(new File(filePath)).exists()) {
        filePath = null;
      }
      Log.d(TAG, "photo file from data, path:" + filePath);

    } else if (data.getAction() != null && data.getAction().equals("inline-data")) {

      try {
        final String fileName =
            MD5.getMessageDigest(
                    DateFormat.format("yyyy-MM-dd-HH-mm-ss", System.currentTimeMillis())
                        .toString()
                        .getBytes())
                + Util.PHOTO_DEFAULT_EXT;
        filePath = dir + fileName;

        final Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        final File file = new File(filePath);
        if (!file.exists()) {
          file.createNewFile();
        }

        BufferedOutputStream out;
        out = new BufferedOutputStream(new FileOutputStream(file));
        final int cQuality = 100;
        bitmap.compress(Bitmap.CompressFormat.PNG, cQuality, out);
        out.close();
        Log.d(TAG, "photo image from data, path:" + filePath);

      } catch (final Exception e) {
        e.printStackTrace();
      }

    } else {
      if (cu != null) {
        cu.close();
        cu = null;
      }
      Log.e(TAG, "resolve photo from intent failed");
      return null;
    }
    if (cu != null) {
      cu.close();
      cu = null;
    }
    return filePath;
  }