Exemplo n.º 1
1
 @Override
 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
   Uri uri = intent.getData();
   if (uri != null && CALLBACK_URL.getScheme().equals(uri.getScheme())) {
     String oauth_verifier = uri.getQueryParameter("oauth_verifier");
     try {
       acToken = twitter.getOAuthAccessToken(rqToken, oauth_verifier);
       accountdb.insert_twitter(token, token, stoken);
     } catch (TwitterException e) {
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 2
0
  public static boolean matchesContentUri(Uri uri, Uri baseContentUri) {
    if (uri == null) {
      return false;
    }

    // Check that scheme and authority are the same.
    if (!uri.getScheme().equals(baseContentUri.getScheme())
        || !uri.getAuthority().equals(baseContentUri.getAuthority())) {
      return false;
    }

    // Checks that all the base path components are in the URI.
    List<String> uriPathSegments = uri.getPathSegments();
    List<String> basePathSegments = baseContentUri.getPathSegments();
    if (basePathSegments.size() > uriPathSegments.size()) {
      return false;
    }
    for (int i = 0; i < basePathSegments.size(); i++) {
      if (!uriPathSegments.get(i).equals(basePathSegments.get(i))) {
        return false;
      }
    }

    return true;
  }
Exemplo n.º 3
0
  @Override
  protected void processImport() throws SudokuInvalidFormatException {
    try {
      InputStreamReader streamReader;
      if (mUri.getScheme().equals("content")) {
        ContentResolver contentResolver = mContext.getContentResolver();
        streamReader = new InputStreamReader(contentResolver.openInputStream(mUri));
      } else {
        java.net.URI juri;
        juri = new java.net.URI(mUri.getScheme(), mUri.getSchemeSpecificPart(), mUri.getFragment());
        streamReader = new InputStreamReader(juri.toURL().openStream());
      }

      try {
        importXml(streamReader);
      } finally {
        streamReader.close();
      }
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }
  }
 private Integer getResourceForMedia(Resources resources, Uri uri) {
   int drawable = 0;
   if (uri.getScheme().equals("file")) {
     if (uri.getLastPathSegment().endsWith("3gp")) {
       drawable = R.drawable.media_film;
     } else if (uri.getLastPathSegment().endsWith("jpg")) {
       drawable = R.drawable.media_camera;
     } else if (uri.getLastPathSegment().endsWith("txt")) {
       drawable = R.drawable.media_notepad;
     }
   } else if (uri.getScheme().equals("content")) {
     if (uri.getAuthority().equals(GPStracking.AUTHORITY + ".string")) {
       drawable = R.drawable.media_mark;
     } else if (uri.getAuthority().equals("media")) {
       drawable = R.drawable.media_speech;
     }
   }
   Bitmap bitmap = null;
   Integer bitmapKey = new Integer(drawable);
   synchronized (sBitmapCache) {
     if (!sBitmapCache.containsKey(bitmapKey)) {
       bitmap = BitmapFactory.decodeResource(resources, drawable);
       sBitmapCache.put(bitmapKey, bitmap);
     }
     bitmap = sBitmapCache.get(bitmapKey);
   }
   return bitmapKey;
 }
Exemplo n.º 5
0
  public static String getPath(Activity activity, Uri uri) {

    if ("content".equalsIgnoreCase(uri.getScheme())) {

      String[] projection = {"_data"};

      Cursor cursor = null;

      try {

        cursor = activity.getContentResolver().query(uri, projection, null, null, null);

        int column_index = cursor.getColumnIndexOrThrow("_data");

        if (cursor.moveToFirst()) {
          String path = cursor.getString(column_index);
          return path;
        }

      } catch (Exception e) {

        e.printStackTrace();
      }

    } else if ("file".equalsIgnoreCase(uri.getScheme())) {

      return uri.getPath();
    }

    return null;
  }
  /**
   * 根据uri发送文件
   *
   * @param uri
   */
  protected void sendFileByUri(Uri uri) {
    String filePath = null;
    if ("content".equalsIgnoreCase(uri.getScheme())) {
      String[] filePathColumn = {MediaStore.Images.Media.DATA};
      Cursor cursor = null;

      try {
        cursor = getActivity().getContentResolver().query(uri, filePathColumn, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow("_data");
        if (cursor.moveToFirst()) {
          filePath = cursor.getString(column_index);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
      filePath = uri.getPath();
    }
    File file = new File(filePath);
    if (file == null || !file.exists()) {
      Toast.makeText(getActivity(), R.string.File_does_not_exist, 0).show();
      return;
    }
    // 大于10M不让发送
    if (file.length() > 10 * 1024 * 1024) {
      Toast.makeText(getActivity(), R.string.The_file_is_not_greater_than_10_m, 0).show();
      return;
    }
    sendFileMessage(filePath);
  }
 private Attachment(UUID uuid, Bitmap bitmap, Uri uri) {
   String attachmentUrl;
   boolean z = true;
   this.callId = uuid;
   this.bitmap = bitmap;
   this.originalUri = uri;
   if (uri != null) {
     String scheme = uri.getScheme();
     if ("content".equalsIgnoreCase(scheme)) {
       this.isContentUri = true;
       if (uri.getAuthority() == null || uri.getAuthority().startsWith("media")) {
         z = false;
       }
       this.shouldCreateFile = z;
     } else if ("file".equalsIgnoreCase(uri.getScheme())) {
       this.shouldCreateFile = true;
     } else if (!Utility.isWebUri(uri)) {
       throw new FacebookException("Unsupported scheme for media Uri : " + scheme);
     }
   } else if (bitmap != null) {
     this.shouldCreateFile = true;
   } else {
     throw new FacebookException("Cannot share media without a bitmap or Uri set");
   }
   this.attachmentName = !this.shouldCreateFile ? null : UUID.randomUUID().toString();
   if (this.shouldCreateFile) {
     attachmentUrl =
         FacebookContentProvider.getAttachmentUrl(
             FacebookSdk.getApplicationId(), uuid, this.attachmentName);
   } else {
     attachmentUrl = this.originalUri.toString();
   }
   this.attachmentUrl = attachmentUrl;
 }
  public static boolean checkForKeyImport(Intent intent, Activity activity) {
    boolean doKeyStoreImport = false;

    // if otr_keystore.ofcaes is in the SDCard root, import it
    File otrKeystoreAES =
        new File(Environment.getExternalStorageDirectory(), "otr_keystore.ofcaes");
    if (otrKeystoreAES.exists()) {
      // Log.i(TAG, "found " + otrKeystoreAES + "to import");
      doKeyStoreImport = true;
      importOtrKeyStore(otrKeystoreAES, activity);
    } else if (intent.getData() != null) {
      Uri uriData = intent.getData();
      String path = null;

      if (uriData.getScheme() != null && uriData.getScheme().equals("file")) {
        path = uriData.toString().replace("file://", "");

        File file = new File(path);

        doKeyStoreImport = true;

        importOtrKeyStore(file, activity);
      }
    } else {
      Toast.makeText(activity, R.string.otr_keysync_warning_message, Toast.LENGTH_LONG).show();
    }

    return doKeyStoreImport;
  }
Exemplo n.º 9
0
  public static String getPath(final Context context, final Uri uri) {

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
      // ExternalStorageProvider
      if (isExternalStorageDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        if ("primary".equalsIgnoreCase(type)) {
          return Environment.getExternalStorageDirectory() + "/" + split[1];
        }

        // TODO handle non-primary volumes
      }
      // DownloadsProvider
      else if (isDownloadsDocument(uri)) {

        final String id = DocumentsContract.getDocumentId(uri);
        final Uri contentUri =
            ContentUris.withAppendedId(
                Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

        return getDataColumn(context, contentUri, null, null);
      }
      // MediaProvider
      else if (isMediaDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        Uri contentUri = null;
        if ("image".equals(type)) {
          contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        } else if ("video".equals(type)) {
          contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        } else if ("audio".equals(type)) {
          contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        }

        final String selection = "_id=?";
        final String[] selectionArgs = new String[] {split[1]};

        return getDataColumn(context, contentUri, selection, selectionArgs);
      }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {
      return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
      return uri.getPath();
    }

    return null;
  }
Exemplo n.º 10
0
 private int getResourceForMedia(Resources resources, Uri uri) {
   int drawable = 0;
   if (uri.getScheme().equals("file")) {
     if (uri.getLastPathSegment().endsWith("3gp")) {
       drawable = R.drawable.media_film;
     } else if (uri.getLastPathSegment().endsWith("jpg")) {
       drawable = R.drawable.media_camera;
     } else if (uri.getLastPathSegment().endsWith("txt")) {
       drawable = R.drawable.media_notepad;
     }
   } else if (uri.getScheme().equals("content")) {
     if (uri.getAuthority().equals(GPStracking.AUTHORITY + ".string")) {
       drawable = R.drawable.media_mark;
     } else if (uri.getAuthority().equals("media")) {
       drawable = R.drawable.media_speech;
     }
   }
   synchronized (sBitmapCache) {
     if (sBitmapCache.get(drawable) == null) {
       Bitmap bitmap = BitmapFactory.decodeResource(resources, drawable);
       sBitmapCache.put(drawable, bitmap);
     }
   }
   return drawable;
 }
Exemplo n.º 11
0
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   HideImaShow();
   File file = null;
   if (resultCode == Activity.RESULT_OK) {
     if (requestCode == R.id.resource_take) {
       file = temFile;
       imgList.add(file);
     } else if (requestCode == R.id.resource_pick) {
       Uri uri = data.getData();
       if (uri.getScheme().equals("content")) {
         file = new File(SystemMethodUtil.changeURItoPath(uri, context));
         if (file.getAbsolutePath().toLowerCase().endsWith(".jpg")) {
           imgList.add(file);
         } else {
           Toast.makeText(context, "不支持的图片格式", Toast.LENGTH_SHORT).show();
         }
       } else if (uri.getScheme().equals("file")) {
         file = new File(uri.getEncodedPath());
         if (file.getAbsolutePath().toLowerCase().endsWith(".jpg")) {
           imgList.add(file);
         } else {
           Toast.makeText(context, "不支持的图片格式", Toast.LENGTH_SHORT).show();
         }
       }
     }
   }
   notifyAdapter();
 }
Exemplo n.º 12
0
 private void initModelFromUri(Uri uri) throws MmsException {
   String scheme = uri.getScheme();
   if (scheme.equals("content")) {
     initFromContentUri(uri);
   } else if (uri.getScheme().equals("file")) {
     initFromFile(uri);
   }
   initMediaDuration();
 }
Exemplo n.º 13
0
  /**
   * Get the file path for a uri. This is a convoluted way to get the path for an Uri created using
   * the StorageAccessFramework. This in no way is the official way to do this but there does not
   * seem to be a better way to do this at this point. It is taken from
   * https://github.com/iPaulPro/aFileChooser.
   *
   * @param context The context of the application
   * @param uri The uri of the saved file
   * @return The file with path pointing to the saved file. It can return null if we can't resolve
   *     the uri properly.
   */
  public static File getFileForUri(final Context context, final Uri uri) {
    String path = null;

    // DocumentProvider
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
        && DocumentsContract.isDocumentUri(context, uri)) {
      // ExternalStorageProvider
      if (isExternalStorageDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        if ("primary".equalsIgnoreCase(type)) {
          path = Environment.getExternalStorageDirectory() + "/" + split[1];
        }
      } else if (isDownloadsDocument(uri)) {
        // DownloadsProvider
        final String id = DocumentsContract.getDocumentId(uri);
        final Uri contentUri =
            ContentUris.withAppendedId(
                Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

        path = getDataColumn(context, contentUri, null, null);
      } else if (isMediaDocument(uri)) {
        // MediaProvider
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        Uri contentUri = null;
        if ("image".equals(type)) {
          contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        } else if ("video".equals(type)) {
          contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        } else if ("audio".equals(type)) {
          contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        }

        final String selection = "_id=?";
        final String[] selectionArgs = new String[] {split[1]};

        path = getDataColumn(context, contentUri, selection, selectionArgs);
      }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
      // MediaStore (and general)
      path = getDataColumn(context, uri, null, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
      // File
      path = uri.getPath();
    }

    if (path != null) {
      return new File(path);
    }
    return null;
  }
Exemplo n.º 14
0
 private boolean isChildImageUri(Uri uri) {
   // Sometimes, the URI of an image contains a query string with key
   // "bucketId" inorder to restore the image list. However, the query
   // string is not part of the mBaseUri. So, we check only other parts
   // of the two Uri to see if they are the same.
   Uri base = mBaseUri;
   return Util.equals(base.getScheme(), uri.getScheme())
       && Util.equals(base.getHost(), uri.getHost())
       && Util.equals(base.getAuthority(), uri.getAuthority())
       && Util.equals(base.getPath(), getPathWithoutId(uri));
 }
Exemplo n.º 15
0
 private void setFileName() {
   if (mUri != null) {
     String name = null;
     if (mUri.getScheme() == null || mUri.getScheme().equals("file"))
       name = getName(mUri.toString());
     else name = mUri.getLastPathSegment();
     if (name == null) name = "null";
     if (mDisplayName == null) mDisplayName = name;
     mMediaController.setFileName(mDisplayName);
   }
 }
  public static boolean isAppStoreURI(Uri uri) {

    return uri.getAuthority().contains("play.google.com")
        || // play store
        uri.getScheme().equals("market")
        || // play store scheme
        uri.getScheme().equals("amzn")
        || // amazon store
        uri.toString().contains("www.amazon.com/gp/mas/dl/android")
        || // amazon store http
        uri.getScheme().equals("samsungapps"); // samsung app store
  }
Exemplo n.º 17
0
 protected Query(
     @NonNull Inquiry inquiry,
     @NonNull Uri contentUri,
     @QueryType int type,
     @Nullable Class<RowType> mClass) {
   mInquiry = inquiry;
   mContentUri = contentUri;
   if (mContentUri.getScheme() == null || !mContentUri.getScheme().equals("content"))
     throw new IllegalStateException("You can only use content:// URIs for content providers.");
   mQueryType = type;
   mRowClass = mClass;
 }
Exemplo n.º 18
0
  public static String getPath(final Uri uri) {
    try {
      final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
      if (isKitKat && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) {
        if (isExternalStorageDocument(uri)) {
          final String docId = DocumentsContract.getDocumentId(uri);
          final String[] split = docId.split(":");
          final String type = split[0];
          if ("primary".equalsIgnoreCase(type)) {
            return Environment.getExternalStorageDirectory() + "/" + split[1];
          }
        } else if (isDownloadsDocument(uri)) {
          final String id = DocumentsContract.getDocumentId(uri);
          final Uri contentUri =
              ContentUris.withAppendedId(
                  Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
          return getDataColumn(ApplicationLoader.applicationContext, contentUri, null, null);
        } else if (isMediaDocument(uri)) {
          final String docId = DocumentsContract.getDocumentId(uri);
          final String[] split = docId.split(":");
          final String type = split[0];

          Uri contentUri = null;
          switch (type) {
            case "image":
              contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
              break;
            case "video":
              contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
              break;
            case "audio":
              contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
              break;
          }

          final String selection = "_id=?";
          final String[] selectionArgs = new String[] {split[1]};

          return getDataColumn(
              ApplicationLoader.applicationContext, contentUri, selection, selectionArgs);
        }
      } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        return getDataColumn(ApplicationLoader.applicationContext, uri, null, null);
      } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
      }
    } catch (Exception e) {
      FileLog.e("tmessages", e);
    }
    return null;
  }
Exemplo n.º 19
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   // This activity is never shown to the user.
   setContentView(new RelativeLayout(this));
   Intent receivedIntent = getIntent();
   if (receivedIntent != null) {
     Uri uri = receivedIntent.getData();
     source = uri;
     if (uri.getScheme().equals("file")) processFile(uri);
     else if (uri.getScheme().equals("content")) processContent(uri);
   } else {
     Toast.makeText(this, R.string.saveas_no_file_picked, Toast.LENGTH_SHORT).show();
   }
 }
Exemplo n.º 20
0
 @Override
 protected Bitmap decode(BitmapFactory.Options options) {
   try {
     InputStream inputStream;
     if (mUri.getScheme().startsWith("http") || mUri.getScheme().startsWith("https")) {
       inputStream = new URL(mUri.toString()).openStream();
     } else {
       inputStream = mContext.getContentResolver().openInputStream(mUri);
     }
     return BitmapFactory.decodeStream(inputStream, null, options);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
 /*
  * Gets the file path of the given Uri.
  */
 @SuppressLint("NewApi")
 private String getPath(Uri uri) throws URISyntaxException {
   final boolean needToCheckUri = Build.VERSION.SDK_INT >= 19;
   String selection = null;
   String[] selectionArgs = null;
   // Uri is different in versions after KITKAT (Android 4.4), we need to
   // deal with different Uris.
   if (needToCheckUri && DocumentsContract.isDocumentUri(getApplicationContext(), uri)) {
     if (isExternalStorageDocument(uri)) {
       final String docId = DocumentsContract.getDocumentId(uri);
       final String[] split = docId.split(":");
       return Environment.getExternalStorageDirectory() + "/" + split[1];
     } else if (isDownloadsDocument(uri)) {
       final String id = DocumentsContract.getDocumentId(uri);
       uri =
           ContentUris.withAppendedId(
               Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
     } else if (isMediaDocument(uri)) {
       final String docId = DocumentsContract.getDocumentId(uri);
       final String[] split = docId.split(":");
       final String type = split[0];
       if ("image".equals(type)) {
         uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
       } else if ("video".equals(type)) {
         uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
       } else if ("audio".equals(type)) {
         uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
       }
       selection = "_id=?";
       selectionArgs = new String[] {split[1]};
     }
   }
   if ("content".equalsIgnoreCase(uri.getScheme())) {
     String[] projection = {MediaStore.Images.Media.DATA};
     Cursor cursor = null;
     try {
       cursor = getContentResolver().query(uri, projection, selection, selectionArgs, null);
       int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       if (cursor.moveToFirst()) {
         return cursor.getString(column_index);
       }
     } catch (Exception e) {
     }
   } else if ("file".equalsIgnoreCase(uri.getScheme())) {
     return uri.getPath();
   }
   return null;
 }
Exemplo n.º 22
0
  public void uploadFiles() {
    try {
      WebdavClient wdc =
          OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());

      // create last directory in path if necessary
      if (mCreateDir) {
        wdc.createDirectory(mUploadPath);
      }

      String[] local = new String[mStreamsToUpload.size()],
          remote = new String[mStreamsToUpload.size()];

      for (int i = 0; i < mStreamsToUpload.size(); ++i) {
        Uri uri = (Uri) mStreamsToUpload.get(i);
        if (uri.getScheme().equals("content")) {
          Cursor c =
              getContentResolver()
                  .query((Uri) mStreamsToUpload.get(i), CONTENT_PROJECTION, null, null, null);

          if (!c.moveToFirst()) continue;

          final String display_name = c.getString(c.getColumnIndex(Media.DISPLAY_NAME)),
              data = c.getString(c.getColumnIndex(Media.DATA));
          local[i] = data;
          remote[i] = mUploadPath + display_name;
        } else if (uri.getScheme().equals("file")) {
          final File file =
              new File(Uri.decode(uri.toString()).replace(uri.getScheme() + "://", ""));
          local[i] = file.getAbsolutePath();
          remote[i] = mUploadPath + file.getName();
        }
      }
      Intent intent = new Intent(getApplicationContext(), FileUploader.class);
      intent.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_MULTIPLE_FILES);
      intent.putExtra(FileUploader.KEY_LOCAL_FILE, local);
      intent.putExtra(FileUploader.KEY_REMOTE_FILE, remote);
      intent.putExtra(FileUploader.KEY_ACCOUNT, mAccount);
      startService(intent);
      finish();

    } catch (SecurityException e) {
      String message =
          String.format(
              getString(R.string.uploader_error_forbidden_content), getString(R.string.app_name));
      Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
  }
  /**
   * Handle the specified CALL or CALL_* intent on a non-voice-capable device.
   *
   * <p>This method may launch a different intent (if there's some useful alternative action to
   * take), or otherwise display an error dialog, and in either case will finish() the current
   * activity when done.
   */
  private void handleNonVoiceCapable(Intent intent) {
    if (DBG)
      Log.v(TAG, "handleNonVoiceCapable: handling " + intent + " on non-voice-capable device...");
    String action = intent.getAction();
    Uri uri = intent.getData();
    String scheme = uri.getScheme();

    // Handle one special case: If this is a regular CALL to a tel: URI,
    // bring up a UI letting you do something useful with the phone number
    // (like "Add to contacts" if it isn't a contact yet.)
    //
    // This UI is provided by the contacts app in response to a DIAL
    // intent, so we bring it up here by demoting this CALL to a DIAL and
    // relaunching.
    //
    // TODO: it's strange and unintuitive to manually launch a DIAL intent
    // to do this; it would be cleaner to have some shared UI component
    // that we could bring up directly.  (But for now at least, since both
    // Contacts and Phone are built-in apps, this implementation is fine.)

    if (Intent.ACTION_CALL.equals(action) && (Constants.SCHEME_TEL.equals(scheme))) {
      Intent newIntent = new Intent(Intent.ACTION_DIAL, uri);
      if (DBG) Log.v(TAG, "- relaunching as a DIAL intent: " + newIntent);
      startActivity(newIntent);
      finish();
      return;
    }

    // In all other cases, just show a generic "voice calling not
    // supported" dialog.
    showDialog(DIALOG_NOT_VOICE_CAPABLE);
    // ...and we'll eventually finish() when the user dismisses
    // or cancels the dialog.
  }
 /**
  * Constructs a new UriBuilder from the given Uri.
  *
  * @return a new Uri Builder based off the given Uri.
  */
 public static UriBuilder newInstance(Uri uri) {
   return new UriBuilder()
       .scheme(uri.getScheme())
       .host(uri.getHost())
       .path(uri.getPath())
       .query(uri.getQuery());
 }
  /**
   * Handles the redirect response from the social login flow
   *
   * @param intent the new received intent
   */
  private void handleSocialResult(Intent intent) {
    Uri data = intent.getData();
    if (data != null && data.getScheme().equals(DEEPLINK_SCHEME)) {
      // coming from a social redirect
      String fragment = data.getFragment();
      if (fragment == null) {
        Log.e(TAG, "Missing response data.");
        sendBackResult(null);
        return;
      }

      int tokenStart = fragment.indexOf(HASH_ACCESS_TOKEN) + HASH_ACCESS_TOKEN.length();
      int tokenEnd = fragment.indexOf("&", tokenStart);
      if (tokenEnd == -1) {
        tokenEnd = fragment.length();
      }
      String resultToken = fragment.substring(tokenStart, tokenEnd);
      int stateStart = fragment.indexOf(HASH_STATE) + HASH_STATE.length();
      int stateEnd = fragment.indexOf("&", stateStart);
      if (stateEnd == -1) {
        stateEnd = fragment.length();
      }
      String resultState = fragment.substring(stateStart, stateEnd);
      String lastState = getLastState();
      boolean stateIsOK = lastState.equals(resultState);
      Log.d(
          TAG,
          String.format("Social login result: %s, %s, %b", resultToken, resultState, stateIsOK));
      sendBackResult(resultToken);
    }
  }
  private void fillData(@Nullable Intent intent, @NonNull TextView textView) {
    Uri data = intent == null ? null : intent.getData();
    if (data == null) {
      textView.setText(Printer.EMPTY);
      return;
    }

    Truss truss = new Truss();
    Printer.append(truss, "raw", data);
    Printer.append(truss, "scheme", data.getScheme());
    Printer.append(truss, "host", data.getHost());
    Printer.append(truss, "port", data.getPort());
    Printer.append(truss, "path", data.getPath());
    Printer.appendKey(truss, "query");
    boolean query = false;
    if (data.isHierarchical()) {
      for (String queryParameterName : data.getQueryParameterNames()) {
        Printer.appendSecondary(
            truss, queryParameterName, data.getQueryParameter(queryParameterName));
        query = true;
      }
    }
    if (!query) {
      Printer.appendValue(truss, null);
    }
    Printer.append(truss, "fragment", data.getFragment());
    textView.setText(truss.build());
  }
Exemplo n.º 27
0
 protected void parseLaunchIntentLocation() {
   Intent intent = getIntent();
   if (intent != null && intent.getData() != null) {
     Uri data = intent.getData();
     if ("http".equalsIgnoreCase(data.getScheme())
         && "download.osmand.net".equals(data.getHost())
         && "/go".equals(data.getPath())) {
       String lat = data.getQueryParameter("lat");
       String lon = data.getQueryParameter("lon");
       if (lat != null && lon != null) {
         try {
           double lt = Double.parseDouble(lat);
           double ln = Double.parseDouble(lon);
           String zoom = data.getQueryParameter("z");
           int z = settings.getLastKnownMapZoom();
           if (zoom != null) {
             z = Integer.parseInt(zoom);
           }
           settings.setMapLocationToShow(lt, ln, z, getString(R.string.shared_location));
         } catch (NumberFormatException e) {
         }
       }
     }
   }
 }
Exemplo n.º 28
0
  @Override
  public boolean imageShowSuccess(Uri uri) {
    if (uri != null) {
      if (DEBUG) {
        Log.d(
            "imageShowSuccess",
            "[[imageShowSuccess]] uri : "
                + uri.getScheme()
                + " uri path : "
                + uri.getPath()
                + " uri title : "
                + uri.getHost()
                + " encode path = "
                + uri.getEncodedPath()
                + " toString : "
                + uri.toString());
      }
      String checkUrl = uri.getPath();
      if (!TextUtils.isEmpty(checkUrl) && checkUrl.toLowerCase().startsWith("http")) {
        // do nothing
      } else if (!TextUtils.isEmpty(checkUrl) && checkUrl.toLowerCase().startsWith(FILE_CONTENT)) {
        checkUrl = checkUrl.substring(FILE_CONTENT.length());
      }
      if (!TextUtils.isEmpty(checkUrl) && checkUrl.equals(mUrl)) {
        return mCurrentBtLoadSuccess;
      }
    }

    return false;
  }
Exemplo n.º 29
0
 static BitmapHunter forRequest(
     Context context,
     Picasso picasso,
     Dispatcher dispatcher,
     Cache cache,
     Stats stats,
     Action action,
     Downloader downloader) {
   if (action.getData().resourceId != 0) {
     return new ResourceBitmapHunter(context, picasso, dispatcher, cache, stats, action);
   }
   Uri uri = action.getData().uri;
   String scheme = uri.getScheme();
   if (SCHEME_CONTENT.equals(scheme)) {
     if (Contacts.CONTENT_URI.getHost().equals(uri.getHost()) //
         && !uri.getPathSegments().contains(Contacts.Photo.CONTENT_DIRECTORY)) {
       return new ContactsPhotoBitmapHunter(context, picasso, dispatcher, cache, stats, action);
     } else {
       return new ContentProviderBitmapHunter(context, picasso, dispatcher, cache, stats, action);
     }
   } else if (SCHEME_FILE.equals(scheme)) {
     if (!uri.getPathSegments().isEmpty() && ANDROID_ASSET.equals(uri.getPathSegments().get(0))) {
       return new AssetBitmapHunter(context, picasso, dispatcher, cache, stats, action);
     }
     return new FileBitmapHunter(context, picasso, dispatcher, cache, stats, action);
   } else if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
     return new ResourceBitmapHunter(context, picasso, dispatcher, cache, stats, action);
   } else {
     return new NetworkBitmapHunter(picasso, dispatcher, cache, stats, action, downloader);
   }
 }
 private void saveImage(int index) {
   String dest = AcApp.getPreferenceImageSaveDir();
   String path = mList.get(index);
   Uri uri = Uri.parse(path);
   File saveFile;
   if (uri.getScheme().equals("http")) {
     // FIXME: volley 的缓存任务还没有被执行的时候是会获取不到数据的
     byte[] diskCache = AcApp.getDataInDiskCache(path);
     if (diskCache != null) {
       saveFile = new File(dest + "/" + FileUtil.getHashName(path));
       if (!FileUtil.save(diskCache, saveFile.getAbsolutePath())) {
         saveFile = null;
       }
     } else {
       File cache = FileUtil.generateImageCacheFile(path);
       saveFile = FileUtil.copy(cache, dest);
     }
   } else {
     File cache = new File(uri.getPath());
     saveFile = FileUtil.copy(cache, dest);
   }
   if (saveFile != null && saveFile.exists()) {
     MobclickAgent.onEvent(this, "save_pic");
     Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(saveFile));
     sendBroadcast(intent);
     AcApp.showToast(getString(R.string.save_success) + ":" + saveFile.getAbsolutePath());
   } else AcApp.showToast(getString(R.string.save_failed));
 }