Esempio n. 1
1
  @SuppressWarnings("deprecation")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder = null;

    if (convertView == null) {
      convertView = LayoutInflater.from(mInstance).inflate(R.layout.listview_item, null);

      holder = new ViewHolder();
      holder.checkBox = (CheckBox) convertView.findViewById(R.id.check_box);
      holder.textView = (TextView) convertView.findViewById(R.id.app_name);
      holder.imageView = (ImageView) convertView.findViewById(R.id.app_logo);

      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    final PackageInfo packageInfo = mInstalledList.get(position);

    holder.textView.setText(
        packageInfo.applicationInfo.loadLabel(mInstance.getPackageManager()).toString());
    holder.imageView.setImageResource(packageInfo.applicationInfo.icon);
    Drawable drawable = packageInfo.applicationInfo.loadIcon(mInstance.getPackageManager());
    holder.imageView.setBackgroundDrawable(drawable);

    if (contains(mCheckedList, packageInfo)) {
      holder.checkBox.setChecked(true);
    } else {
      holder.checkBox.setChecked(false);
    }

    convertView.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View view) {

            if (contains(mCheckedList, packageInfo)) {
              remove(mCheckedList, packageInfo);
            } else {
              mCheckedList.add(packageInfo.packageName);
            }

            BlockUtils.save(mInstance, mCheckedList);

            notifyDataSetChanged();
          }
        });

    return convertView;
  }
 @Override
 public boolean isSpecializedHandlerAvailable(Intent intent) {
   try {
     PackageManager pm = mActivity.getPackageManager();
     List<ResolveInfo> handlers =
         pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER);
     if (handlers == null || handlers.size() == 0) {
       return false;
     }
     for (ResolveInfo resolveInfo : handlers) {
       IntentFilter filter = resolveInfo.filter;
       if (filter == null) {
         // No intent filter matches this intent?
         // Error on the side of staying in the browser, ignore
         continue;
       }
       if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) {
         // Generic handler, skip
         continue;
       }
       return true;
     }
   } catch (RuntimeException e) {
     logTransactionTooLargeOrRethrow(e, intent);
   }
   return false;
 }
  public static String printKeyHash(Activity context) {
    PackageInfo packageInfo;
    String key = null;
    try {
      // getting application package name, as defined in manifest
      String packageName = context.getApplicationContext().getPackageName();

      // Retriving package info
      packageInfo =
          context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);

      Log.e("Package Name=", context.getApplicationContext().getPackageName());

      for (Signature signature : packageInfo.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        key = new String(Base64.encode(md.digest(), 0));

        // String key = new String(Base64.encodeBytes(md.digest()));
        Log.e("Key Hash=", key);
      }
    } catch (PackageManager.NameNotFoundException e1) {
      Log.e("Name not found", e1.toString());
    } catch (NoSuchAlgorithmException e) {
      Log.e("No such an algorithm", e.toString());
    } catch (Exception e) {
      Log.e("Exception", e.toString());
    }

    return key;
  }
  /**
   * @param activity The context (normally the UI context)
   * @return boolean True if successfully connected
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private final boolean servicesConnected(Activity activity) {
    int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
      Dialog errorDialog =
          GooglePlayServicesUtil.getErrorDialog(
              resultCode, activity, CONNECTION_FAILURE_RESOLUTION_REQUEST);
      // Can Google Play service provide an error dialog
      if (errorDialog != null) {

        PackageInfo pInfo;
        try {
          pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
          // only version 11 and above support ErrorDialogFragment
          if (pInfo.versionCode >= Build.VERSION_CODES.HONEYCOMB) {
            ErrorDialogFragment errorFragment = new ErrorDialogFragment();
            // Set the dialog in the DialogFragment
            errorFragment.setDialog(errorDialog);
            // Show the error dialog in the DialogFragment
            errorFragment.show(activity.getFragmentManager(), serviceDescription_);
          }
        } catch (NameNotFoundException e) {
          Log.w(serviceDescription_, "Unable to determine version", e);
        }
      } else {
        Log.e(serviceDescription_, "Failed to get Map Service" + resultCode);
      }
      return false;
    } else {
      Log.d(serviceDescription_, "Google Play services is available.");
      return true;
    }
  }
Esempio n. 5
1
 public boolean showFileChooser(
     final String mimeType,
     final String chooserTitle,
     final boolean allowMultiple,
     final boolean mustCanRead) {
   if (mimeType == null || choosing) {
     return false;
   }
   choosing = true;
   // 檢查是否有可用的Activity
   final PackageManager packageManager = activity.getPackageManager();
   final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
   intent.setType(mimeType);
   List<ResolveInfo> list =
       packageManager.queryIntentActivities(intent, PackageManager.GET_ACTIVITIES);
   if (list.size() > 0) {
     this.mustCanRead = mustCanRead;
     // 如果有可用的Activity
     Intent picker = new Intent(Intent.ACTION_GET_CONTENT);
     picker.setType(mimeType);
     picker.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
     picker.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
     // 使用Intent Chooser
     Intent destIntent = Intent.createChooser(picker, chooserTitle);
     activity.startActivityForResult(destIntent, ACTIVITY_FILE_CHOOSER);
     return true;
   } else {
     return false;
   }
 }
  public static void logTokens(Activity context) {

    // Add code to print out the key hash
    try {
      PackageInfo info =
          context
              .getPackageManager()
              .getPackageInfo(
                  context.getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES);
      for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update(signature.toByteArray());
        Log.d("SHA-KeyHash:::", Base64.encodeToString(md.digest(), Base64.DEFAULT));

        md = MessageDigest.getInstance("MD5");
        md.update(signature.toByteArray());
        Log.d("MD5-KeyHash:::", Base64.encodeToString(md.digest(), Base64.DEFAULT));

        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("SHA-Hex-From-KeyHash:::", bytesToHex(md.digest()));
      }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
  }
Esempio n. 7
1
  public static void manageAds(Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    // get a list of installed apps.
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    boolean yboTvProFound = false;

    for (ApplicationInfo info : packages) {
      if (PACKAGE_PRO.equals(info.packageName)) {
        yboTvProFound = true;
        break;
      }
    }

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView) activity.findViewById(R.id.adView);
    if (yboTvProFound) {
      View layout = activity.findViewById(R.id.ad_container);
      FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) layout.getLayoutParams();
      layoutParams.bottomMargin = 0;
      layout.setLayoutParams(layoutParams);
      adView.setVisibility(View.GONE);
    } else {
      adView.loadAd(new AdRequest.Builder().build());
    }
  }
 // Determine whether the RLZ provider is present on the system.
 private boolean rlzProviderPresent() {
   if (mIsProviderPresent == null) {
     PackageManager pm = mActivity.getPackageManager();
     mIsProviderPresent = pm.resolveContentProvider(RLZ_PROVIDER, 0) != null;
   }
   return mIsProviderPresent;
 }
Esempio n. 9
0
  public static void init(final Activity activity) {
    final ApplicationInfo applicationInfo = activity.getApplicationInfo();

    initListener();

    try {
      // Get the lib_name from AndroidManifest.xml metadata
      ActivityInfo ai =
          activity
              .getPackageManager()
              .getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA);
      if (null != ai.metaData) {
        String lib_name = ai.metaData.getString(META_DATA_LIB_NAME);
        if (null != lib_name) {
          System.loadLibrary(lib_name);
        } else {
          System.loadLibrary(DEFAULT_LIB_NAME);
        }
      }
    } catch (PackageManager.NameNotFoundException e) {
      throw new RuntimeException("Error getting activity info", e);
    }

    Cocos2dxHelper.sPackageName = applicationInfo.packageName;
    Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
    // Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);

    Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
    Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
    Cocos2dxHelper.sAssetManager = activity.getAssets();

    // Cocos2dxHelper.nativeSetAssetManager(sAssetManager);
    Cocos2dxBitmap.setContext(activity);
    sActivity = activity;
  }
Esempio n. 10
0
  // Change theme to dark if dark mode is set
  public static void initDarkMode(Activity activity) {
    if (isDarkMode(activity)) {
      int theme = 0;

      try {
        theme = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).theme;
      } catch (NameNotFoundException e) {
        return;
      }

      // Convert to dark theme
      if (theme == R.style.BL_Theme_Light) {
        theme = R.style.BL_Theme_Dark;
      } else if (theme == R.style.BL_Theme_Light_Translucent) {
        theme = R.style.BL_Theme_Dark_Translucent;
      } else if (theme == R.style.BL_Theme_Light_TranslucentActionBar_NoTranslucent) {
        theme = R.style.BL_Theme_Dark_TranslucentActionBar_NoTranslucent;
      } else if (theme == R.style.BL_Theme_Light_TranslucentActionBar) {
        theme = R.style.BL_Theme_Dark_TranslucentActionBar;
      } else if (theme == R.style.BL_Theme_Light_GradientActionBar) {
        theme = R.style.BL_Theme_Dark_GradientActionBar;
      } else if (theme == R.style.BL_Theme_Light_WithNav) {
        theme = R.style.BL_Theme_Dark_WithNav;
      }

      activity.setTheme(theme);
    }
  }
  // NOTE: Currently not reentrant / doesn't support concurrent requests
  @ReactMethod
  public void launchCamera(ReadableMap options, Callback callback) {
    if (options.hasKey("noData")) {
      noData = options.getBoolean("noData");
    }

    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (cameraIntent.resolveActivity(mMainActivity.getPackageManager()) == null) {
      callback.invoke(true, "error resolving activity");
      return;
    }

    // we create a tmp file to save the result
    File imageFile;
    try {
      imageFile =
          File.createTempFile(
              "exponent_capture_",
              ".jpg",
              Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
    } catch (IOException e) {
      e.printStackTrace();
      return;
    }
    if (imageFile == null) {
      callback.invoke(true, "error file not created");
      return;
    }
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile));
    mCameraCaptureURI = Uri.fromFile(imageFile);
    mCallback = callback;
    mMainActivity.startActivityForResult(cameraIntent, REQUEST_LAUNCH_CAMERA);
  }
Esempio n. 12
0
  final void openGoogleShopper(String query) {

    // Construct Intent to launch Shopper
    Intent intent = new Intent(Intent.ACTION_SEARCH);
    intent.setClassName(GOOGLE_SHOPPER_PACKAGE, GOOGLE_SHOPPER_ACTIVITY);
    intent.putExtra(SearchManager.QUERY, query);

    // Is it available?
    PackageManager pm = activity.getPackageManager();
    Collection<?> availableApps =
        pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

    if (availableApps != null && !availableApps.isEmpty()) {
      // If something can handle it, start it
      activity.startActivity(intent);
    } else {
      // Otherwise offer to install it from Market.
      AlertDialog.Builder builder = new AlertDialog.Builder(activity);
      builder.setTitle(R.string.msg_google_shopper_missing);
      builder.setMessage(R.string.msg_install_google_shopper);
      builder.setIcon(R.drawable.shopper_icon);
      builder.setPositiveButton(R.string.button_ok, shopperMarketListener);
      builder.setNegativeButton(R.string.button_cancel, null);
      builder.show();
    }
  }
 /**
  * 判断系统中是否存在可以启动的相机应用
  *
  * @return 存在返回true,不存在返回false
  */
 public boolean hasCamera() {
   PackageManager packageManager = mActivity.getPackageManager();
   Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   List<ResolveInfo> list =
       packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
   return list.size() > 0;
 }
Esempio n. 14
0
 @Kroll.method
 protected boolean hasFlashLight() {
   Activity activity = TiApplication.getAppRootOrCurrentActivity();
   boolean hasFlash =
       activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
   return hasFlash;
 }
  private void setMockActivityInfo(
      final boolean activityInfoFound, int screenOrientation, int configChanges)
      throws PackageManager.NameNotFoundException {
    final ActivityInfo mockActivityInfo = mock(ActivityInfo.class);

    mockActivityInfo.screenOrientation = screenOrientation;
    mockActivityInfo.configChanges = configChanges;

    final PackageManager mockPackageManager = mock(PackageManager.class);
    doAnswer(
            new Answer() {
              @Override
              public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
                if (!activityInfoFound) {
                  throw new PackageManager.NameNotFoundException("");
                }

                return mockActivityInfo;
              }
            })
        .when(mockPackageManager)
        .getActivityInfo(any(ComponentName.class), anyInt());

    when(activity.getPackageManager()).thenReturn(mockPackageManager);
  }
Esempio n. 16
0
  /**
   * Provides the key hash to solve the openSSL issue with Amazon
   *
   * @return key hash
   */
  @TargetApi(Build.VERSION_CODES.FROYO)
  public static String getKeyHash() {
    try {
      // In some cases the unity activity may not exist. This can happen when we are
      // completing a login and unity activity was killed in the background. In this
      // situation it's not necessary to send back the keyhash since the app will overwrite
      // the value with the value they get during the init call and the unity activity
      // wil be created by the time init is called.
      Activity activity = getUnityActivity();
      if (activity == null) {
        return "";
      }

      PackageInfo info =
          activity
              .getPackageManager()
              .getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES);
      for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
        Log.d(TAG, "KeyHash: " + keyHash);
        return keyHash;
      }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    return "";
  }
Esempio n. 17
0
  public static void startViewActivity(
      final Activity activity, final String path, final String mimeType, boolean useDefaultViewer) {
    if (useDefaultViewer) {
      ComponentName componentName =
          AppPickerUtils.getDefaultViewerComponentName(activity, path, mimeType);
      Intent intent =
          getAppIntentFromMimeType(activity.getPackageManager(), path, componentName, mimeType);

      // use default saved viewer
      if (intent != null) {
        activity.startActivity(intent);
        return;
      }
    }

    final AppPickerDialog appPickerDialog = new AppPickerDialog(activity, path, mimeType);
    appPickerDialog.setOpenAppClickListener(
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            ActivityInfo activityInfo = appPickerDialog.getSelectedApp().activityInfo;
            ComponentName componentName1 =
                new ComponentName(activityInfo.applicationInfo.packageName, activityInfo.name);
            activity.startActivity(createViewIntent(path, componentName1, mimeType));
          }
        });
    appPickerDialog.show();
  }
  @Override
  public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
      throws JSONException {

    if (action.equals(ACTION_HAS_SMS_POSSIBILITY)) {

      Activity ctx = this.cordova.getActivity();
      if (ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
      } else {
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
      }
      return true;
    } else if (action.equals(ACTION_SEND_SMS)) {
      try {
        String phoneNumber = args.getString(0);
        String message = args.getString(1);
        this.sendSMS(phoneNumber, message);

        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
      } catch (JSONException ex) {
        callbackContext.sendPluginResult(
            new PluginResult(PluginResult.Status.ERROR, ex.getMessage()));
      }
      return true;
    }
    return false;
  }
 private String getVersion() {
   try {
     PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0);
     return p.versionName;
   } catch (PackageManager.NameNotFoundException e) {
     e.printStackTrace();
     return "1.0";
   }
 }
 @Override
 public boolean canResolveActivity(Intent intent) {
   try {
     return mActivity.getPackageManager().resolveActivity(intent, 0) != null;
   } catch (RuntimeException e) {
     logTransactionTooLargeOrRethrow(e, intent);
     return false;
   }
 }
  // NOTE: Currently not reentrant / doesn't support concurrent requests
  @ReactMethod
  public void launchImageLibrary(final ReadableMap options, final Callback callback) {
    response = Arguments.createMap();

    if (options.hasKey("noData")) {
      noData = options.getBoolean("noData");
    }
    if (options.hasKey("maxWidth")) {
      maxWidth = options.getInt("maxWidth");
    }
    if (options.hasKey("maxHeight")) {
      maxHeight = options.getInt("maxHeight");
    }
    if (options.hasKey("aspectX")) {
      aspectX = options.getInt("aspectX");
    }
    if (options.hasKey("aspectY")) {
      aspectY = options.getInt("aspectY");
    }
    if (options.hasKey("quality")) {
      quality = (int) (options.getDouble("quality") * 100);
    }
    tmpImage = true;
    if (options.hasKey("storageOptions")) {
      tmpImage = false;
    }
    if (options.hasKey("allowsEditing")) {
      allowEditing = options.getBoolean("allowsEditing");
    }
    forceAngle = false;
    if (options.hasKey("angle")) {
      forceAngle = true;
      angle = options.getInt("angle");
    }
    if (options.hasKey("assetProperties")) {
      assetProperties = options.getBoolean("assetProperties");
    }

    Intent libraryIntent =
        new Intent(
            Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    if (libraryIntent.resolveActivity(mMainActivity.getPackageManager()) == null) {
      response.putString("error", "Cannot launch photo library");
      callback.invoke(response);
      return;
    }

    mCallback = callback;

    try {
      mMainActivity.startActivityForResult(libraryIntent, REQUEST_LAUNCH_IMAGE_LIBRARY);
    } catch (ActivityNotFoundException e) {
      e.printStackTrace();
    }
  }
 @Override
 public boolean willChromeHandleIntent(Intent intent) {
   try {
     ResolveInfo info = mActivity.getPackageManager().resolveActivity(intent, 0);
     return info != null && info.activityInfo.packageName.equals(mActivity.getPackageName());
   } catch (RuntimeException e) {
     logTransactionTooLargeOrRethrow(e, intent);
     return false;
   }
 }
 private Drawable getIconDrawableResourceId(Activity activity) {
   try {
     PackageManager pm = activity.getPackageManager();
     PackageInfo pi = pm.getPackageInfo(activity.getPackageName(), 0);
     return activity.getResources().getDrawable(pi.applicationInfo.icon);
   } catch (Exception e) {
     Log.e("Error loading app icon.", e);
   }
   return null;
 }
Esempio n. 24
0
 /** @return Application's version code from the {@code PackageManager}. */
 private static int getAppVersion(Activity context) {
   try {
     PackageInfo packageInfo =
         context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
     return packageInfo.versionCode;
   } catch (NameNotFoundException e) {
     // should never happen
     throw new RuntimeException("Could not get package name: " + e);
   }
 }
 // Get the current app version
 private String GetAppVersion() {
   try {
     PackageInfo _info =
         fActivity.getPackageManager().getPackageInfo(fActivity.getPackageName(), 0);
     return _info.versionName;
   } catch (NameNotFoundException e) {
     e.printStackTrace();
     return "";
   }
 }
 /**
  * checks if ble is supported on the device. If not the app is closed.
  *
  * @param activity current activity of the app.
  * @return true if yes.
  */
 private boolean hasBluetooth(Activity activity) {
   if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
     Toast.makeText(
             activity.getApplicationContext(), R.string.ble_not_supported, Toast.LENGTH_SHORT)
         .show();
     activity.finish();
   }
   Log.i(DEBUG_BLUETOOTH, "Device supports BLE");
   return true;
 }
Esempio n. 27
0
  /**
   * Returns the meta data of the specified activity
   *
   * @param context The activity context
   * @return The meta data bundle
   */
  public static Bundle getMetaData(final Activity context) {
    final PackageManager pm = context.getPackageManager();

    try {
      final ComponentName componentName = ((Activity) context).getComponentName();
      return pm.getActivityInfo(componentName, PackageManager.GET_META_DATA).metaData;
    } catch (NameNotFoundException e) {
      return null;
    }
  }
 public static String getApplicationVersion(Activity context) {
   String res = "";
   try {
     PackageManager manager = context.getPackageManager();
     PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
     res = info.versionName;
   } catch (Exception e) {
   }
   return res;
 }
Esempio n. 29
0
  public static void doStartApplicationWithPackageName(Activity thisActivity, String packagename) {

    // 通过包名获取此APP详细信息,包括Activities、services、versioncode、name等等
    PackageInfo packageinfo = null;
    try {
      packageinfo = thisActivity.getPackageManager().getPackageInfo(packagename, 0);
    } catch (PackageManager.NameNotFoundException e) {
      e.printStackTrace();
    }

    if (packageinfo == null) {
      Log.w(">>>>>>>>>>>>>>>", packagename + " is null");
      return;
    }

    // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(packageinfo.packageName);

    // 通过getPackageManager()的queryIntentActivities方法遍历
    List<ResolveInfo> resolveinfoList =
        thisActivity.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo resolveinfo = resolveinfoList.iterator().next();
    if (resolveinfo != null) {
      // packagename = 参数packname
      String packageName = resolveinfo.activityInfo.packageName;
      // 这个就是我们要找的该APP的LAUNCHER的Activity[组织形式:packagename.mainActivityname]
      String className = resolveinfo.activityInfo.name;
      // LAUNCHER Intent
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

      // 设置ComponentName参数1:packagename参数2:MainActivity路径
      ComponentName cn = new ComponentName(packageName, className);

      intent.setComponent(cn);
      thisActivity.startActivity(intent);
    }
  }
Esempio n. 30
0
  /**
   * Returns the app's name.
   *
   * @return The app's name as a String.
   */
  public String getAppName() {
    Activity activity = getActivity();

    try {
      PackageManager pm = activity.getPackageManager();
      ApplicationInfo applicationInfo = pm.getApplicationInfo(activity.getPackageName(), 0);
      return pm.getApplicationLabel(applicationInfo).toString();
    } catch (NameNotFoundException exception) {
      return "";
    }
  }