示例#1
0
 public static void startActivityOrWarn(Context ctx, Intent intent, String errorMessage) {
   try {
     ctx.startActivity(intent);
   } catch (ActivityNotFoundException e) {
     L.w(e);
     new AbstractDialogFactory(ctx)
         .showToast((errorMessage != null) ? errorMessage : e.getMessage());
   }
 }
 static boolean openUri(@Nonnull Activity activity, @Nonnull String uri) {
   try {
     activity.startActivity(new Intent(ACTION_VIEW, Uri.parse(uri)));
     return true;
   } catch (ActivityNotFoundException e) {
     Log.e("Checkout", e.getMessage(), e);
   }
   return false;
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == RESULT_OK) {
     if (requestCode == SELECT_FILE) {
       picUri = data.getData();
       try {
         Intent cropIntent = new Intent("com.android.camera.action.CROP");
         cropIntent.setDataAndType(picUri, "image/*");
         cropIntent.putExtra("crop", "true");
         cropIntent.putExtra("aspectX", 1);
         cropIntent.putExtra("aspectY", 1);
         cropIntent.putExtra("outputX", 480);
         cropIntent.putExtra("outputY", 480);
         cropIntent.putExtra("return-data", true);
         startActivityForResult(cropIntent, PIC_CROP);
       } catch (ActivityNotFoundException e) {
         Toast.makeText(EditProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
       }
     }
     if (requestCode == REQUEST_CAMERA) {
       try {
         Intent cropIntent = new Intent("com.android.camera.action.CROP");
         cropIntent.setDataAndType(picUri, "image/*");
         cropIntent.putExtra("crop", "true");
         cropIntent.putExtra("aspectX", 1);
         cropIntent.putExtra("aspectY", 1);
         cropIntent.putExtra("outputX", 480);
         cropIntent.putExtra("outputY", 480);
         cropIntent.putExtra("return-data", true);
         startActivityForResult(cropIntent, PIC_CROP);
       } catch (ActivityNotFoundException e) {
         Toast.makeText(EditProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
       }
     }
     if (requestCode == PIC_CROP) {
       Bundle extras = data.getExtras();
       Bitmap bitmap = extras.getParcelable("data");
       editAvatar.setImageBitmap(bitmap);
     }
   }
 }
        @Override
        public void onClick(View v) {
          // Perform action on click
          switch (v.getId()) {
            case R.id.home:
              // Log.e("MyPagerAdapter", "home");
              // ctx.setScrollX(0);
              break;

            case R.id.about:
              // Log.e("MyPagerAdapter", "about");

              LayoutInflater inflater =
                  (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View view = inflater.inflate(R.layout.about, null);

              break;

            case R.id.secret:
              // Log.e("MyPagerAdapter", "secret");
              break;

            case R.id.anyproblemsemail:
              Intent emailIntent = new Intent(Intent.ACTION_SEND);
              emailIntent.setType("text/html");
              emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
              emailIntent.putExtra(Intent.EXTRA_SUBJECT, "For testing............");
              ctx.startActivity(Intent.createChooser(emailIntent, email));

              break;

            case R.id.anyproblemsnum:
              try {
                Intent my_callIntent = new Intent(Intent.ACTION_CALL);
                my_callIntent.setData(
                    Uri.parse(
                        "tel:" + num)); // here the word 'tel' is important for making a call...
                // ctx.startActivityForResult(my_callIntent , 1);
                ctx.startActivity(my_callIntent);
                // finish();
              } catch (ActivityNotFoundException e) {
                Toast.makeText(ctx, "Error in your phone call" + e.getMessage(), Toast.LENGTH_LONG)
                    .show();
              }
              break;
          }
        }
 void configWifi() {
   Log.d(TAG, "show net config interface");
   try {
     if (Utils.ANDROID_VERSION >= 16) {
       Intent in = new Intent(Settings.ACTION_WIFI_SETTINGS);
       startActivity(in);
     } else {
       Intent in = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
       startActivity(in);
     }
   } catch (ActivityNotFoundException anf) {
     Log.d(TAG, "no activity for : Settings.ACTION_WIRELESS_SETTINGS" + anf.getMessage());
     Intent in = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
     startActivity(in);
   }
 }
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    ApplicationInfo app = applist.get(position);
    try {
      Intent intent = packageManager.getLaunchIntentForPackage(app.packageName);
      if (null != intent) {
        startActivity(intent);
      }
    } catch (ActivityNotFoundException e) {
      Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
    } catch (Exception e) {
      Toast.makeText(AllAppsActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
  }
  public static void launchFileBrowser(
      Activity parentActivity, String reason, int requestCode, String samplePath) {
    try {
      String startPath = "/";
      String inf = samplePath;
      if (inf != null && inf.length() > 0) {
        File f = new File(samplePath);
        startPath = f.getParent();
      }

      Intent intent = new Intent("kellinwood.zipsigner.action.BROWSE_FILE");
      intent.putExtra("startPath", startPath);
      intent.putExtra("reason", reason);
      parentActivity.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
      Toast.makeText(parentActivity, e.getMessage(), 0).show();
    }
  }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    ApplicationInfo app = applist.get(position);

    try {
      app_save_new4 = app.packageName;
      Intent intent = new Intent(this, SettingsActivity.class);
      startActivity(intent);
      overridePendingTransition(center_to_right, center_to_right2);

    } catch (ActivityNotFoundException e) {
      Toast.makeText(ActivityAppsNew4.this, e.getMessage(), Toast.LENGTH_LONG).show();
    } catch (Exception e) {
      Toast.makeText(ActivityAppsNew4.this, e.getMessage(), Toast.LENGTH_LONG).show();
    }
  }
示例#9
0
    @Override
    public void onReceive(Context context, Intent intent) {

      if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        long completeDownloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
        DownloadManager downloadManager =
            (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

        Intent installIntent = new Intent(Intent.ACTION_VIEW);
        installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        installIntent.setDataAndType(
            downloadManager.getUriForDownloadedFile(completeDownloadId), MINETYPE_APPLCATION);
        try {
          context.startActivity(installIntent);
        } catch (ActivityNotFoundException e) {
          Toast.makeText(context, "Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
        } finally {
          LocalBroadcastManager.getInstance(context)
              .unregisterReceiver(DownloadCompleteReceiver.this);
        }
      }
    }
示例#10
0
  public void startApp(String[] params) {
    if (params.length < 2) {
      Log.e(tag, "startApp has error params!!!");
      return;
    }
    String startMode = params[0];
    Intent intent = null;
    String extraJson = null;
    if (!TextUtils.isEmpty(startMode)) {
      if ("0".equals(startMode)) {
        String pkgName = params[1];
        String clsName = null;
        if (TextUtils.isEmpty(pkgName)) {
          Log.e(tag, "startApp has error params!!!");
          callBackPluginJs(JsConst.CALLBACK_START_APP, "error params");
          return;
        }

        if (params.length > 2) {
          clsName = params[2];
        }
        if (TextUtils.isEmpty(clsName)) {
          clsName = getMainActivity(pkgName);
        }
        if (TextUtils.isEmpty(clsName)) {
          Log.e(tag, "startApp has error params!!!");
          callBackPluginJs(JsConst.CALLBACK_START_APP, "package is not exist!");
          return;
        }
        ComponentName component = new ComponentName(pkgName, clsName);
        intent = new Intent();
        intent.setComponent(component);
      } else if ("1".equals(startMode)) {
        String action = params[1];
        String filterJson = null;
        intent = new Intent(action);
        if (params.length > 2) {
          filterJson = params[2];
        }
        if (!TextUtils.isEmpty(filterJson)) {
          intent = setIntentFilter(intent, filterJson);
        }
      } else {
        Log.e(tag, "startApp has error params!!!");
        callBackPluginJs(JsConst.CALLBACK_START_APP, "error params!");
        return;
      }
    }
    if (intent == null) {
      Log.e(tag, "startApp has error params!!!");
      callBackPluginJs(JsConst.CALLBACK_START_APP, "error params!");
      return;
    }
    if (params.length > 3) {
      extraJson = params[3];
      if (!TextUtils.isEmpty(extraJson)) {
        intent = setIntentExtras(intent, extraJson);
      }
    }
    try {
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(intent);
    } catch (ActivityNotFoundException e) {
      callBackPluginJs(JsConst.CALLBACK_START_APP, e.getMessage());
    }
  }