static void activateTab(Activity a, int id) {
   Intent intent = new Intent(Intent.ACTION_PICK);
   switch (id) {
     case R.id.artisttab:
       intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/artistalbum");
       break;
     case R.id.albumtab:
       intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
       break;
     case R.id.songtab:
       intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
       break;
     case R.id.playlisttab:
       intent.setDataAndType(Uri.EMPTY, MediaStore.Audio.Playlists.CONTENT_TYPE);
       break;
     case R.id.nowplayingtab:
       intent = new Intent(a, MediaPlaybackActivity.class);
       a.startActivity(intent);
       // fall through and return
     default:
       return;
   }
   intent.putExtra("withtabs", true);
   intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
   a.startActivity(intent);
   a.finish();
   a.overridePendingTransition(0, 0);
 }
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    // Dialog doesn't allow us to wait for a result, so we need to store
    // the info we need for when the dialog posts its result
    mQueryCursor.moveToPosition(position);
    if (mQueryCursor.isBeforeFirst() || mQueryCursor.isAfterLast()) {
      return;
    }
    String selectedType =
        mQueryCursor.getString(
            mQueryCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));

    if ("artist".equals(selectedType)) {
      Intent intent = new Intent(Intent.ACTION_PICK);
      intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
      intent.putExtra("artist", Long.valueOf(id).toString());
      startActivity(intent);
    } else if ("album".equals(selectedType)) {
      Intent intent = new Intent(Intent.ACTION_PICK);
      intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
      intent.putExtra("album", Long.valueOf(id).toString());
      startActivity(intent);
    } else if (position >= 0 && id >= 0) {
      int[] list = new int[] {(int) id};
      MusicUtils.playAll(this, list, 0);
    } else {
      Log.e("QueryBrowser", "invalid position/id: " + position + "/" + id);
    }
  }
Beispiel #3
1
  private void playVideo(String url) throws IOException {
    if (url.contains("bit.ly/")
        || url.contains("goo.gl/")
        || url.contains("tinyurl.com/")
        || url.contains("youtu.be/")) {
      // support for google / bitly / tinyurl / youtube shortens
      URLConnection con = new URL(url).openConnection();
      con.connect();
      InputStream is = con.getInputStream();
      // new redirected url
      url = con.getURL().toString();
      is.close();
    }

    // Create URI
    Uri uri = Uri.parse(url);

    Intent intent = null;
    // Check to see if someone is trying to play a YouTube page.
    if (url.contains(YOU_TUBE)) {
      // If we don't do it this way you don't have the option for youtube
      uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
      if (isYouTubeInstalled()) {
        intent = new Intent(Intent.ACTION_VIEW, uri);
      } else {
        intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=com.google.android.youtube"));
      }
    } else if (url.contains(ASSETS)) {
      // get file path in assets folder
      String filepath = url.replace(ASSETS, "");
      // get actual filename from path as command to write to internal storage doesn't like folders
      String filename = filepath.substring(filepath.lastIndexOf("/") + 1, filepath.length());

      // Don't copy the file if it already exists
      File fp = new File(this.cordova.getActivity().getFilesDir() + "/" + filename);
      if (!fp.exists()) {
        this.copy(filepath, filename);
      }

      // change uri to be to the new file in internal storage
      uri = Uri.parse("file://" + this.cordova.getActivity().getFilesDir() + "/" + filename);

      // Display video player
      intent = new Intent(Intent.ACTION_VIEW);
      intent.setDataAndType(uri, "video/*");
    } else {
      // Display video player
      intent = new Intent(Intent.ACTION_VIEW);
      intent.setDataAndType(uri, "video/*");
    }

    this.cordova.getActivity().startActivity(intent);
  }
Beispiel #4
1
  /**
   * @param context
   * @param c
   * @param castMediaUri
   */
  public static void showMedia(Context context, Cursor c, Uri castMediaUri) {
    final String mediaString = c.getString(c.getColumnIndex(CastMedia._MEDIA_URL));
    final String locMediaString = c.getString(c.getColumnIndex(CastMedia._LOCAL_URI));
    String mimeType = null;

    Uri media;

    if (locMediaString != null) {
      media = Uri.parse(locMediaString);
      if ("file".equals(media.getScheme())) {
        mimeType = c.getString(c.getColumnIndex(CastMedia._MIME_TYPE));
      }

    } else if (mediaString != null) {
      media = Uri.parse(mediaString);
      mimeType = c.getString(c.getColumnIndex(CastMedia._MIME_TYPE));

      // we strip this because we don't really want to force them to go to the browser.
      if ("text/html".equals(mimeType)) {
        mimeType = null;
      }
    } else {
      Log.e(TAG, "asked to show media for " + castMediaUri + " but there was nothing to show");
      return;
    }

    final Intent i = new Intent(Intent.ACTION_VIEW);
    i.setDataAndType(media, mimeType);

    if (mimeType != null && mimeType.startsWith("video/")) {
      context.startActivity(
          new Intent(
              Intent.ACTION_VIEW,
              ContentUris.withAppendedId(
                  castMediaUri, c.getLong(c.getColumnIndex(CastMedia._ID)))));
    } else {
      // setting the MIME type for URLs doesn't work.
      try {
        context.startActivity(i);
      } catch (final ActivityNotFoundException e) {
        // try it again, but without a mime type.
        if (mimeType != null) {
          i.setDataAndType(media, null);
        }
        try {
          context.startActivity(i);
        } catch (final ActivityNotFoundException e2) {
          Toast.makeText(context, R.string.error_cast_media_no_activities, Toast.LENGTH_LONG)
              .show();
        }
      }
    }
  }
Beispiel #5
1
 /**
  * 启动需要安装的APK
  *
  * @param ac 传入activity
  * @param str apk名称,格式(***.apk)
  */
 public static void startInstal(Activity ac, String str) {
   String fileName = Environment.getExternalStorageDirectory() + "/" + str;
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(
       Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
   ac.startActivity(intent);
 }
Beispiel #6
1
  public static void startCropImageActivityForResult(
      Activity context,
      Uri imageUri,
      boolean defaultSizeWithSource,
      int requestCode,
      String cropImageFileName,
      int aspectX,
      int aspectY) {
    try {
      Intent intent = new Intent();
      // this will open all images
      intent.setDataAndType(imageUri, "image/*");
      intent.putExtra("aspectX", aspectX);
      intent.putExtra("aspectY", aspectY);
      intent.putExtra("crop", "true");
      // true to return a Bitmap, false to directly save the cropped iamge
      intent.putExtra("return-data", true);
      if (defaultSizeWithSource) {
        intent.putExtra("defaultCropRectangleSize", "same-with-same-image");
      }
      if (cropImageFileName != null) {
        intent.putExtra("return-data-file-name", cropImageFileName);
      }
      context.startActivityForResult(intent, requestCode);
    } catch (Throwable tr) {

    }
  }
Beispiel #7
0
 /**
  * 描述:打开并安装文件.
  *
  * @param context the context
  * @param file apk文件路径
  */
 public static void installApk(Context context, File file) {
   Intent intent = new Intent();
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   intent.setAction(android.content.Intent.ACTION_VIEW);
   intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
   context.startActivity(intent);
 }
  /**
   * 剪裁图片
   *
   * @param activity 操作所在的Activity
   * @param uri 需要剪裁的图片所在的资源Uri
   * @param cuttedImagePath 剪裁完成的图片的地址
   * @param aspectX 宽(比例),若无比例设定为-1
   * @param aspectY 高(比例),若无比例设定为-1
   * @param outputX 宽的长度,若无要求设定为-1
   * @param outputY 高的长度,若无要求设定为-1
   * @param outputFormat 输出格式
   */
  @Override
  public void cutTheImage(
      Activity activity,
      Uri uri,
      String cuttedImagePath,
      int aspectX,
      int aspectY,
      int outputX,
      int outputY,
      String outputFormat) {
    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uri, IMAGE_CONTENT_TYPE);
    intent.putExtra("crop", "true");

    // aspectX aspectY 宽高的比例
    if (aspectX > 0) intent.putExtra("aspectX", aspectX);
    if (aspectY > 0) intent.putExtra("aspectY", aspectY);

    // outputX outputY 裁剪图片宽高
    if (outputX > 0) intent.putExtra("outputX", outputX);
    if (outputY > 0) intent.putExtra("outputY", outputY);

    intent.putExtra("outputFormat", FORMAT_IN_STRING_JPEG);
    intent.putExtra("return-data", false);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(cuttedImagePath)));

    activity.startActivityForResult(intent, ReqCode.CUTTED);
  }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   boolean handled = false;
   Intent intent;
   switch (item.getItemId()) {
     case MENU_GRAPHTYPE:
       showDialog(DIALOG_GRAPHTYPE);
       handled = true;
       break;
     case MENU_TRACKLIST:
       intent = new Intent(this, TrackList.class);
       intent.putExtra(Tracks._ID, mTrackUri.getLastPathSegment());
       startActivityForResult(intent, MENU_TRACKLIST);
       break;
     case MENU_SHARE:
       intent = new Intent(Intent.ACTION_RUN);
       intent.setDataAndType(mTrackUri, Tracks.CONTENT_ITEM_TYPE);
       intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
       Bitmap bm = mViewFlipper.getDrawingCache();
       Uri screenStreamUri = ShareTrack.storeScreenBitmap(bm);
       intent.putExtra(Intent.EXTRA_STREAM, screenStreamUri);
       startActivityForResult(
           Intent.createChooser(intent, getString(R.string.share_track)), MENU_SHARE);
       handled = true;
       break;
     default:
       handled = super.onOptionsItemSelected(item);
   }
   return handled;
 }
  @Override
  protected void onPostExecute(SaveImageInBackgroundData params) {
    if (params.result > 0) {
      // Show a message that we've failed to save the image to disk
      GlobalScreenshot.notifyScreenshotError(params.context, mNotificationManager);
    } else {
      // Show the final notification to indicate screenshot saved
      Resources r = params.context.getResources();

      // Create the intent to show the screenshot in gallery
      Intent launchIntent = new Intent(Intent.ACTION_VIEW);
      launchIntent.setDataAndType(params.imageUri, "image/png");
      launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      mNotificationBuilder
          .setContentTitle(r.getString(R.string.screenshot_saved_title))
          .setContentText(r.getString(R.string.screenshot_saved_text))
          .setContentIntent(PendingIntent.getActivity(params.context, 0, launchIntent, 0))
          .setWhen(System.currentTimeMillis())
          .setAutoCancel(true);

      Notification n = mNotificationBuilder.getNotification();
      n.flags &= ~Notification.FLAG_NO_CLEAR;
      mNotificationManager.notify(mNotificationId, n);
    }
    params.finisher.run();
  }
Beispiel #11
0
 /** 安装APK */
 private void installApk(File file) {
   Intent intent = new Intent();
   intent.setAction(Intent.ACTION_VIEW);
   intent.addCategory(Intent.CATEGORY_DEFAULT);
   intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
   startActivityForResult(intent, 0);
 }
Beispiel #12
0
 // 安装下载后的apk文件
 private void Instanll(File file, Context context) {
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   intent.setAction(android.content.Intent.ACTION_VIEW);
   intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
   context.startActivity(intent);
 }
Beispiel #13
0
  /**
   * Creates a home screen shortcut.
   *
   * @param fileHolder The {@link File} to create the shortcut to.
   */
  public static void createShortcut(FileHolder fileHolder, Context context) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, fileHolder.getName());
    try {
      shortcutIntent.putExtra(
          Intent.EXTRA_SHORTCUT_ICON,
          bitmapFrom(context.getResources().getDisplayMetrics(), fileHolder.getBestIcon()));
    } catch (Exception ex) {
      Logger.log(ex);
      Parcelable icon =
          Intent.ShortcutIconResource.fromContext(
              context.getApplicationContext(), R.drawable.ic_launcher);
      shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    } finally {
      Intent onClickIntent = new Intent(Intent.ACTION_VIEW);
      if (fileHolder.getFile().isDirectory())
        onClickIntent.setData(Uri.fromFile(fileHolder.getFile()));
      else
        onClickIntent.setDataAndType(Uri.fromFile(fileHolder.getFile()), fileHolder.getMimeType());
      onClickIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

      shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, onClickIntent);
      context.sendBroadcast(shortcutIntent);
    }
  }
Beispiel #14
0
  @Override
  public void onCreate(Bundle theSavedInstanceState) {
    super.onCreate(theSavedInstanceState);

    // create folder for external storage
    myContext = new ContextWrapper(this);
    myContext.getExternalFilesDir(null);

    Intent anIntent = getIntent();
    String aDataType = anIntent != null ? anIntent.getType() : "";
    Uri aDataUrl = anIntent != null ? anIntent.getData() : null;
    String aDataPath = aDataUrl != null ? aDataUrl.getEncodedPath() : "";

    myTextView = new TextView(this);
    myTextView.setMovementMethod(new ScrollingMovementMethod());
    myTextView.setText(
        "sView loader in progress...\n  URL: " + aDataPath + "\n  Type: " + aDataType);
    setContentView(myTextView);

    StringBuilder anInfo = new StringBuilder();
    if (!StActivity.loadNatives(this, anInfo)) {
      // StActivity.exitWithError(this, "Broken apk?\n" + anInfo);
      return;
    }
    myTextView.append("\n\n" + anInfo);

    Intent anImgViewer = new Intent(this, StActivity.class);
    anImgViewer.setDataAndType(aDataUrl, aDataType);
    startActivityForResult(anImgViewer, 0);
  }
 /** 安装应用 */
 public static void update() {
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(
       Uri.fromFile(new File(Environment.getExternalStorageDirectory(), UPDATE_SERVERAPK)),
       "application/vnd.android.package-archive");
   mContent.startActivity(intent);
 }
Beispiel #16
0
        @Override
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case MessageId.UPDATE_CLIENT_ID_FAIL:
              {
                BaseUtil.innerComm.webappclient.updateClientId(
                    BaseUtil.getSelfUserInfo().getUserId(), clientId);
                break;
              }
            case MessageId.APK_DOWN_LOAD_DONE:
              {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(
                    Uri.fromFile(
                        new File(
                            FileUtil.APK_PATH + BaseUtil.getSystemInfo().getLatestClientName())),
                    "application/vnd.android.package-archive");
                InnerCommAdapter.ct.startActivity(intent);
                break;
              }

            default:
              {
                if (!innerCommQue.isEmpty()) {
                  Log.i(
                      "InnerCommAdapter",
                      "baseutil send msg:" + msg.what + "to->" + innerCommQue.getLast());
                  innerCommQue.getLast().processMessage(msg);
                } else {
                  Log.e("BaseUtil", "UI activity innerCommQue is empty,drop msgid:!!" + msg.what);
                }
                break;
              }
          }
        }
Beispiel #17
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   switch (requestCode) {
     case TAKE_PHOTO:
       if (resultCode == RESULT_OK) {
         Intent intent = new Intent("com.android.camera.action.CROP");
         intent.setDataAndType(imageUri, "image/*");
         intent.putExtra("scale", true);
         intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
         startActivityForResult(intent, CROP_PHOTO);
       }
       break;
     case CROP_PHOTO:
       if (resultCode == RESULT_OK) {
         Bitmap bitmap = null;
         try {
           bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
         } catch (FileNotFoundException e) {
           e.printStackTrace();
         }
         picture.setImageBitmap(bitmap);
         //                    picture.setBackgroundResource(R.drawable.ic_launcher);
       }
       break;
     default:
       break;
   }
 }
Beispiel #18
0
 /**
  * 获取裁切intent
  *
  * @param uri
  * @param outputX
  * @param outputY
  * @param aspectX
  * @param aspectY
  * @param outputFormat
  * @return
  */
 public static Intent getCropIntent(
     Intent intent,
     Uri uri,
     int outputX,
     int outputY,
     float aspectX,
     float aspectY,
     String outputFormat) {
   if (intent == null) intent = new Intent();
   intent.setAction("com.android.camera.action.CROP");
   intent.setDataAndType(uri, "image/*");
   intent.putExtra("crop", "true");
   // intent.putExtra( "circleCrop", "of course" ); // circleCrop不为空则进行圆形裁切
   intent.putExtra("aspectX", (int) (aspectX + .5));
   intent.putExtra("aspectY", (int) (aspectY + .5));
   intent.putExtra("outputX", outputX);
   intent.putExtra("outputY", outputY);
   intent.putExtra("scale", true); // 黑边
   intent.putExtra("scaleUpIfNeeded", true); // 黑边
   if (uri != null) {
     intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
     intent.putExtra("return-data", false);
     //			intent.putExtra( "return-data", true );
   } else intent.putExtra("return-data", true);
   if (TextUtils.isEmpty(outputFormat))
     intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
   else intent.putExtra("outputFormat", outputFormat);
   intent.putExtra("noFaceDetection", true);
   return intent;
 }
  public static void viewSimpleSlideshow(Context context, SlideshowModel slideshow) {
    if (!slideshow.isSimple()) {
      throw new IllegalArgumentException("viewSimpleSlideshow() called on a non-simple slideshow");
    }
    SlideModel slide = slideshow.get(0);
    MediaModel mm = null;
    if (slide.hasImage()) {
      mm = slide.getImage();
    } else if (slide.hasVideo()) {
      mm = slide.getVideo();
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.putExtra("SingleItemOnly", true); // So we don't see "surrounding" images in Gallery

    String contentType;
    if (mm.isDrmProtected()) {
      contentType = mm.getDrmObject().getContentType();
    } else {
      contentType = mm.getContentType();
    }
    intent.setDataAndType(mm.getUri(), contentType);
    context.startActivity(intent);
  }
 protected void startJob(PutlockerDownloadJob job) {
   File f = new File(job.getFileLocation());
   Intent openIntent = new Intent();
   openIntent.setAction(android.content.Intent.ACTION_VIEW);
   openIntent.setDataAndType(Uri.fromFile(f), getMimeTypeForFilename(job._fileName));
   startActivity(Intent.createChooser(openIntent, "Open with:"));
 }
  public static void openFile(Activity activity, File file) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // 设置intent的Action属性
    intent.setAction(Intent.ACTION_VIEW);
    // 获取文件file的MIME类型

    Uri uri = Uri.fromFile(file);
    // ContentResolver cR = getContentResolver();
    // String mime = cR.getType(uri);

    MimeTypeMap mime = MimeTypeMap.getSingleton();
    int index = file.getName().lastIndexOf('.') + 1;
    String ext = file.getName().substring(index).toLowerCase();
    String type = mime.getMimeTypeFromExtension(ext);

    // 设置intent的data和Type属性。
    intent.setDataAndType(uri, type);
    // 跳转
    try {
      activity.startActivity(intent);
      return;
    } catch (android.content.ActivityNotFoundException ex) {
    }
    Toast.makeText(activity, "没有能打开这个文件的应用", Toast.LENGTH_SHORT).show();
  }
        public void onClick(View v) {
          menuWindow.dismiss();
          Intent intent;
          switch (v.getId()) {
            case R.id.btn_take_photo:
              // 点击了拍照按钮
              File dir = new File(SeventhConstants.MyAvatarDir);
              if (!dir.exists()) {
                dir.mkdirs();
              }
              // 原图
              File file =
                  new File(dir, new SimpleDateFormat("yyMMddHHmmss").format(new Date()) + ".jpg");
              filePath = file.getAbsolutePath(); // 获取相片的保存路径
              Uri imageUri = Uri.fromFile(file);
              intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
              intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
              startActivityForResult(intent, SeventhConstants.REQUESTCODE_UPLOADAVATAR_CAMERA);
              break;

            case R.id.btn_pick_photo:
              intent = new Intent(Intent.ACTION_PICK, null);
              intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
              startActivityForResult(intent, SeventhConstants.REQUESTCODE_UPLOADAVATAR_LOCATION);
              break;

            default:
              break;
          }
        }
    @Override
    public void onDownloadFinished(Context context, DownloadsUtil.DownloadInfo info) {
      File localFile = new File(info.localFilename);
      if (!localFile.isFile()) return;

      if (moduleVersion.md5sum != null && !moduleVersion.md5sum.isEmpty()) {
        try {
          String actualMd5Sum = HashUtil.md5(localFile);
          if (!moduleVersion.md5sum.equals(actualMd5Sum)) {
            Toast.makeText(
                    context,
                    context.getString(
                        R.string.download_md5sum_incorrect, actualMd5Sum, moduleVersion.md5sum),
                    Toast.LENGTH_LONG)
                .show();
            DownloadsUtil.removeById(context, info.id);
            return;
          }
        } catch (Exception e) {
          Toast.makeText(
                  context,
                  context.getString(R.string.download_could_not_read_file, e.getMessage()),
                  Toast.LENGTH_LONG)
              .show();
          DownloadsUtil.removeById(context, info.id);
          return;
        }
      }

      PackageManager pm = context.getPackageManager();
      PackageInfo packageInfo = pm.getPackageArchiveInfo(info.localFilename, 0);

      if (packageInfo == null) {
        Toast.makeText(context, R.string.download_no_valid_apk, Toast.LENGTH_LONG).show();
        DownloadsUtil.removeById(context, info.id);
        return;
      }

      if (!packageInfo.packageName.equals(moduleVersion.module.packageName)) {
        Toast.makeText(
                context,
                context.getString(
                    R.string.download_incorrect_package_name,
                    packageInfo.packageName,
                    moduleVersion.module.packageName),
                Toast.LENGTH_LONG)
            .show();
        DownloadsUtil.removeById(context, info.id);
        return;
      }

      Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
      installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      installIntent.setDataAndType(Uri.fromFile(localFile), DownloadsUtil.MIME_TYPE_APK);
      // installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
      // installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
      installIntent.putExtra(
          Intent.EXTRA_INSTALLER_PACKAGE_NAME, context.getApplicationInfo().packageName);
      context.startActivity(installIntent);
    }
 // 裁剪图片
 private void startImageAction(
     Uri uri, int outputX, int outputY, int requestCode, boolean isCrop) {
   Intent intent = null;
   if (isCrop) {
     intent = new Intent("com.android.camera.action.CROP");
   } else {
     intent = new Intent(Intent.ACTION_GET_CONTENT, null);
   }
   intent.setDataAndType(uri, "image/*");
   intent.putExtra("crop", "true");
   intent.putExtra("aspectX", 1);
   intent.putExtra("aspectY", 1);
   intent.putExtra("outputX", outputX);
   intent.putExtra("outputY", outputY);
   intent.putExtra("scale", true);
   if (requestCode == SeventhConstants.REQUESTCODE_UPLOADAVATAR_GALLERY_CROP) {
     // 若是相册传来的数据我们需要对url处理,将裁剪后的url保存到心得地方去
     File dir = new File(SeventhConstants.MyAvatarDir);
     if (!dir.exists()) {
       dir.mkdirs();
     }
     // 原图
     File file = new File(dir, new SimpleDateFormat("yyMMddHHmmss").format(new Date()) + ".jpg");
     Uri uri2 = Uri.fromFile(file);
     filePath = file.getAbsolutePath();
     intent.putExtra(MediaStore.EXTRA_OUTPUT, uri2);
   } else {
     // 用裁剪之后的相机图片覆盖了原图
     intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
   }
   intent.putExtra("return-data", true);
   intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
   intent.putExtra("noFaceDetection", true); // no face detection
   startActivityForResult(intent, requestCode);
 }
  private void CopyAssets() {

    AssetManager assetManager = getAssets();

    InputStream in = null;
    OutputStream out = null;
    File file = new File(getFilesDir(), fileName);
    try {
      in = assetManager.open(fileName);
      out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

      copyFile(in, out);
      in.close();
      in = null;
      out.flush();
      out.close();
      out = null;
    } catch (Exception e) {
      Log.e("tag", e.getMessage());
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/" + fileName), "application/pdf");

    startActivity(intent);
  }
Beispiel #26
0
  private void InstallFile(File f) {
    mProgress.dismiss();
    if (f.length() < fileLength) {
      return;
    }
    try {
      String command = "chmod " + 777 + " " + f.getPath();
      Runtime runtime = Runtime.getRuntime();
      runtime.exec(command);
    } catch (IOException e) {
      e.printStackTrace();
    }
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);

    intent.setDataAndType(Uri.fromFile(f), "application/vnd.android.package-archive");
    myActivity.startActivity(intent);

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //
    // 部分机型,安装过程中,要先退出自身进程,才能安装成功。
    //		BaseHelper.exitProcessSilently(myActivity);

    // 防止下载后安装,但用户单击取消情况下的问题
    //        application.destroy();
    //        myActivity.finish();
    android.os.Process.killProcess(android.os.Process.myPid());
  }
Beispiel #27
0
 public static void playEpisodeFromFile(Activity parentActivity, File file) {
   Intent intent = new Intent();
   intent.setAction(android.content.Intent.ACTION_VIEW);
   intent.setDataAndType(Uri.fromFile(file), "audio/*");
   if (parentActivity != null) startActivity(parentActivity, intent, Bundle.EMPTY);
   Log.i("Podcast|playfile", "No context or activity.");
 }
  protected void onListItemClick(ListView l, View v, int position, long id) {
    ProfilerAudioAdapter profileAudioAdapter = (ProfilerAudioAdapter) getListAdapter();
    String selectedValue = profileAudioAdapter.getItem(position);
    Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();

    GetFile task = new GetFile();
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    File folder = new File(extStorageDirectory, "Audio");
    folder.mkdir();
    ArrayList<String> params = new ArrayList<String>();
    params.add(fileLocation[position]);
    params.add(fileName[position]);
    params.add(String.valueOf(folder));
    task.execute(new ArrayList[] {params});

    try {
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_VIEW);
      File fileToRead = new File(folder + "/" + fileName[position]);
      Uri uri = Uri.fromFile(fileToRead.getAbsoluteFile());
      intent.setDataAndType(uri, "audio/mp3");
      startActivity(intent);
    } catch (ActivityNotFoundException activityNotFoundException) {
      activityNotFoundException.printStackTrace();
      Toast.makeText(this, "There doesn't seem to be an Audio player installed.", Toast.LENGTH_LONG)
          .show();
    } catch (Exception ex) {
      ex.printStackTrace();
      Toast.makeText(this, "Cannot open the selected file.", Toast.LENGTH_LONG).show();
    }
  }
Beispiel #29
0
 public static void installApk(Context context, final String apkPath) {
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   Uri uri = Uri.fromFile(new File(apkPath));
   intent.setDataAndType(uri, "application/vnd.android.package-archive");
   context.startActivity(intent);
 }
Beispiel #30
0
  public static void SetFileExplorerLink(
      TextView txtFilename, Spanned htmlString, final String pathToLinkTo, final Context context) {

    final Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse("file://" + pathToLinkTo), "resource/folder");
    intent.setAction(Intent.ACTION_VIEW);

    if (intent.resolveActivity(context.getPackageManager()) != null) {
      txtFilename.setLinksClickable(true);
      txtFilename.setClickable(true);
      txtFilename.setMovementMethod(LinkMovementMethod.getInstance());
      txtFilename.setSelectAllOnFocus(false);
      txtFilename.setTextIsSelectable(false);
      txtFilename.setText(htmlString);

      txtFilename.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              context.startActivity(intent);
            }
          });
    }
  }