Example usage for android.content.pm PackageManager GET_ACTIVITIES

List of usage examples for android.content.pm PackageManager GET_ACTIVITIES

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_ACTIVITIES.

Prototype

int GET_ACTIVITIES

To view the source code for android.content.pm PackageManager GET_ACTIVITIES.

Click Source Link

Document

PackageInfo flag: return information about activities in the package in PackageInfo#activities .

Usage

From source file:com.example.util.Utils.java

public static HashMap<String, Object> getApkInfo(Context context, File file) {
    PackageManager pm = context.getPackageManager();
    String filePath = file.getAbsolutePath();
    PackageInfo info = pm.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
    if (info == null) {
        return null;
    }//  ww w .j a  v a2s.  c  om
    ApplicationInfo appInfo = info.applicationInfo;
    info.applicationInfo.sourceDir = filePath;
    info.applicationInfo.publicSourceDir = filePath;
    Drawable icon = pm.getApplicationIcon(appInfo);

    HashMap<String, Object> apk = new HashMap<String, Object>();
    apk.put(Constants.KEY_PRODUCT_ICON, icon);
    apk.put(Constants.KEY_PRODUCT_NAME, file.getName());
    apk.put(Constants.KEY_PRODUCT_INFO, filePath);
    apk.put(Constants.KEY_PRODUCT_DESCRIPTION, file.getAbsolutePath());
    apk.put(Constants.KEY_PRODUCT_PAY_TYPE, Constants.PAY_TYPE_FREE);
    apk.put(Constants.KEY_PLACEHOLDER, false);
    return apk;
}

From source file:RhodesService.java

public static void runApplication(String appName, Object params) {
    try {//from  ww  w . j a  v a  2  s  .  com
        Context ctx = RhodesService.getContext();
        PackageManager mgr = ctx.getPackageManager();
        PackageInfo info = mgr.getPackageInfo(appName, PackageManager.GET_ACTIVITIES);
        if (info.activities.length == 0) {
            Logger.E(TAG, "No activities found for application " + appName);
            return;
        }
        ActivityInfo ainfo = info.activities[0];
        String className = ainfo.name;
        if (className.startsWith("."))
            className = ainfo.packageName + className;

        Intent intent = new Intent();
        intent.setClassName(appName, className);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (params != null) {
            Bundle startParams = new Bundle();
            if (params instanceof String) {
                if (((String) params).length() != 0) {
                    String[] paramStrings = ((String) params).split("&");
                    for (int i = 0; i < paramStrings.length; ++i) {
                        String key = paramStrings[i];
                        String value = "";
                        int splitIdx = key.indexOf('=');
                        if (splitIdx != -1) {
                            value = key.substring(splitIdx + 1);
                            key = key.substring(0, splitIdx);
                        }
                        startParams.putString(key, value);
                    }
                }
            } else
                throw new IllegalArgumentException("Unknown type of incoming parameter");

            intent.putExtras(startParams);
        }
        ctx.startActivity(intent);
    } catch (Exception e) {
        Logger.E(TAG, "Can't run application " + appName + ": " + e.getMessage());
    }
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java

public void isAppInstalledMsg(String[] params) {
    if (params == null || params.length < 1) {
        errorCallback(0, 0, "error params!");
        return;/*from  ww w  . j a  v  a  2  s .  c  om*/
    }
    String json = params[0];
    AppInstalledVO data = DataHelper.gson.fromJson(json, AppInstalledVO.class);
    String packageName = data.getAppData();
    if (TextUtils.isEmpty(packageName)) {
        errorCallback(0, 0, "error params!");
        return;
    }
    JSONObject jsonObject = new JSONObject();
    int result;
    try {
        mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        result = EUExCallback.F_C_SUCCESS;
    } catch (NameNotFoundException e) {
        result = EUExCallback.F_C_FAILED;
    }
    try {
        jsonObject.put(JsConst.INSTALLED, result);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    callBackPluginJs(JsConst.CALLBACK_IS_APP_INSTALLED, jsonObject.toString());
}

From source file:com.aware.Aware_Preferences.java

/**
 * Developer UI options//from  w  w  w .j  a v  a2  s.c om
 * - Debug flag
 * - Debug tag
 * - AWARE updates
 * - Device ID
 */
private void developerOptions() {
    final CheckBoxPreference debug_flag = (CheckBoxPreference) findPreference(Aware_Preferences.DEBUG_FLAG);
    debug_flag
            .setChecked(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG).equals("true"));
    debug_flag.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.DEBUG = debug_flag.isChecked();
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_FLAG, debug_flag.isChecked());
            return true;
        }
    });

    final EditTextPreference debug_tag = (EditTextPreference) findPreference(Aware_Preferences.DEBUG_TAG);
    debug_tag.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG));
    debug_tag.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.TAG = (String) newValue;
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG, (String) newValue);
            return true;
        }
    });

    final CheckBoxPreference auto_update = (CheckBoxPreference) findPreference(
            Aware_Preferences.AWARE_AUTO_UPDATE);
    auto_update.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE).equals("true"));

    PackageInfo awareInfo = null;
    try {
        awareInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    auto_update.setSummary("Current version is " + ((awareInfo != null) ? awareInfo.versionCode : "???"));
    auto_update.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE,
                    auto_update.isChecked());
            return true;
        }
    });

    final CheckBoxPreference debug_db_slow = (CheckBoxPreference) findPreference(
            Aware_Preferences.DEBUG_DB_SLOW);
    debug_db_slow.setChecked(
            Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW).equals("true"));
    debug_db_slow.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEBUG_DB_SLOW,
                    debug_db_slow.isChecked());
            return true;
        }
    });

    final EditTextPreference device_id = (EditTextPreference) findPreference(Aware_Preferences.DEVICE_ID);
    device_id.setSummary("UUID: " + Aware.getSetting(getApplicationContext(), DEVICE_ID));
    device_id.setText(Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
    device_id.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, (String) newValue);
            device_id.setSummary(
                    "UUID: " + Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID));
            return true;
        }
    });
}

From source file:uk.co.workingedge.phonegap.plugin.LaunchNavigator.java

private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
    try {// w  w w.  jav  a2  s  .c o  m
        packageManager.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:net.inbox.InboxMessage.java

/**
 * Looks for available and supported encryption packages.
 * OpenKeychain for GPG.//from w w  w . j av a  2 s  . c o m
 **/
private boolean crypto_package() {
    PackageManager pack_man = getPackageManager();
    try {
        pack_man.getPackageInfo(Pager.open_key_chain, PackageManager.GET_ACTIVITIES);
        return pack_man.getApplicationInfo(Pager.open_key_chain, 0).enabled;
    } catch (PackageManager.NameNotFoundException e) {
        Dialogs.toaster(false, getString(R.string.open_pgp_none_found), this);
        return false;
    }
}

From source file:com.lewa.crazychapter11.MainActivity.java

public boolean isLewaRom(Context context, Intent alarmIntent) {
    PackageManager pm = context.getPackageManager();
    boolean isLewaRom = true;
    String version = "";
    int versionCode = 0;
    PackageInfo pi = null;/*from ww w . ja va2 s  .c o  m*/

    String testsr = null;
    try {
        // com.lewa.permmanager
        // pm.getPackageInfo("com.lewa.deviceactivate",PackageManager.GET_ACTIVITIES);
        pm.getPackageInfo("com.lewa.permmanager", PackageManager.GET_ACTIVITIES);

        pi = pm.getPackageInfo(context.getPackageName(), 0);
        version = pi.versionName;
        versionCode = pi.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        isLewaRom = false;
    }
    Log.d("algerheMain00", "isLewaRom : " + isLewaRom);
    Log.i("algerheVersion", "versionname=" + version + " \n getPackageName()=" + getPackageName()
            + " \n versioncode=" + versionCode);
    Log.i("algerheStr", "TextUtils.isEmpty(testsr) = " + TextUtils.isEmpty(testsr));
    // Log.i("algerheStr","testsr.length="+testsr.length());

    ///alarm test
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 16);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    alarmIntent.setAction("com.lewa.alarm.test");
    PendingIntent pipi = PendingIntent.getBroadcast(context, 3359, alarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Log.i("algerheAlarm", "send alarm message in time=" + System.currentTimeMillis());

    // alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+5000, pipi);

    alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pipi);

    // final Timer timer = new Timer();

    // timer.schedule(new TimerTask() {
    //    @Override
    //    public void run() {
    //       Message msg = new Message();
    //       msg.what = 0x2789;   

    //       handler.sendMessage(msg);

    //       timer.cancel();
    //    }
    // }, 0, 5000);

    return isLewaRom;
}

From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java

private boolean appInstalledOrNot(String uri) {
    Log.d("raft", "4");

    PackageManager pm = this.getPackageManager();
    boolean app_installed = false;
    try {// w  w w.ja va2s  .c  o  m
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Load installed (user or system) packages.
 *//*from   w  ww  . j  a v  a  2s  .  c o m*/
void loadInstalledPackages() {
    try {
        m_workList = new ArrayList<PackingItem>();
        int flags1 = PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS // use hides some app, may require permissions
                | PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS // use hides some app, may require permissions
                | PackageManager.GET_SERVICES;

        int flags2 = PackageManager.GET_PERMISSIONS | PackageManager.GET_ACTIVITIES
                | PackageManager.GET_SERVICES;

        int flags3 = PackageManager.GET_PERMISSIONS;
        int flags4 = 0;
        boolean showSys = (m_show == SHOW_SYS);

        // Some packages will not appear with some flags.
        loadAndAddPackages(showSys, flags1);
        loadAndAddPackages(showSys, flags2);
        loadAndAddPackages(showSys, flags3);
        loadAndAddPackages(showSys, flags4);

        // Sort per settings.
        // TODO *** This does not seem to be working ***
        Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST);
        m_handler.sendMessage(msgObj);

    } catch (Exception ex) {
        m_log.e(ex.getMessage());
    }
}

From source file:com.amaze.filemanager.activities.MainActivity.java

void initialiseFab() {
    String folder_skin = PreferenceUtils.getFolderColorString(Sp);
    int fabSkinPressed = PreferenceUtils.getStatusColor(fabskin);
    int folderskin = Color.parseColor(folder_skin);
    int fabskinpressed = (PreferenceUtils.getStatusColor(folder_skin));
    floatingActionButton = (FloatingActionMenu) findViewById(R.id.menu);
    floatingActionButton.setMenuButtonColorNormal(Color.parseColor(fabskin));
    floatingActionButton.setMenuButtonColorPressed(fabSkinPressed);

    //if (theme1 == 1) floatingActionButton.setMen
    floatingActionButton.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
        @Override//from   w  ww.  j  a v  a  2s  . c  o m
        public void onMenuToggle(boolean b) {
            View v = findViewById(R.id.fab_bg);
            if (b)
                revealShow(v, true);
            else
                revealShow(v, false);
        }
    });

    FloatingActionButton floatingActionButton1 = (FloatingActionButton) findViewById(R.id.menu_item);
    floatingActionButton1.setColorNormal(folderskin);
    floatingActionButton1.setColorPressed(fabskinpressed);
    floatingActionButton1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(0);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });
    FloatingActionButton floatingActionButton2 = (FloatingActionButton) findViewById(R.id.menu_item1);
    floatingActionButton2.setColorNormal(folderskin);
    floatingActionButton2.setColorPressed(fabskinpressed);
    floatingActionButton2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(1);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });
    FloatingActionButton floatingActionButton3 = (FloatingActionButton) findViewById(R.id.menu_item2);
    floatingActionButton3.setColorNormal(folderskin);
    floatingActionButton3.setColorPressed(fabskinpressed);
    floatingActionButton3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(2);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });
    final FloatingActionButton floatingActionButton4 = (FloatingActionButton) findViewById(R.id.menu_item3);
    floatingActionButton4.setColorNormal(folderskin);
    floatingActionButton4.setColorPressed(fabskinpressed);
    floatingActionButton4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(3);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });

    new Thread(new Runnable() {
        @Override
        public void run() {
            PackageManager pm = getPackageManager();
            boolean app_installed;
            try {
                pm.getPackageInfo("com.amaze.filemanager.driveplugin", PackageManager.GET_ACTIVITIES);
                app_installed = true;
            } catch (PackageManager.NameNotFoundException e) {
                app_installed = false;
            }
            if (!app_installed)
                floatingActionButton4.setVisibility(View.GONE);
        }
    }).run();
}