List of usage examples for android.app Activity getPackageManager
@Override
public PackageManager getPackageManager()
From source file:se.toxbee.sleepfighter.challenge.shake.ShakeChallenge.java
@Override public void start(Activity activity, ChallengeResolvedParams params, Bundle state) { super.start(activity, params); this.activity().setContentView(R.layout.challenge_shake); // Get view references this.progressBar = (ProgressBar) this.activity().findViewById(R.id.progressBar); this.progressText = (TextView) this.activity().findViewById(R.id.progressText); // Check if required sensor is available boolean hasAccelerometer = activity.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER); if (!hasAccelerometer) { // Complete right away, for now. Checking if device has required // hardware could perhaps be done before the challenge is started. Log.e(TAG, "Device lacks required sensor for ShakeChallenge"); this.complete(); return;//from w ww . ja v a 2 s . c om } // Register to get acceleration events this.sensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); this.accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // Get last progress from bundle, if it exists if (state != null) { this.progress = state.getFloat(KEY_PROGRESS_FLOAT); } updateProgress(); }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.dialogs.AboutDialogFragment.java
/** * {@inheritDoc}//from w w w . jav a 2 s . com */ @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final Activity activity = getActivity(); // Get the inflater then inflate the view from XML. final LayoutInflater inflater = LayoutInflater.from(activity); final View layout = inflater.inflate(R.layout.about, null); final TextView temp = (TextView) layout.findViewById(R.id.aboutVersion); // Set the version text. try { temp.setText(getString(R.string.aboutdialog_version, activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName, activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode)); } catch (NameNotFoundException e) { // This should never occur. temp.setText("Unknown"); } final TextView txtDBVersion = (TextView) layout.findViewById(R.id.aboutDBVersion); final TextView txtTopoVersion = (TextView) layout.findViewById(R.id.aboutTopoVersion); // Get the database mod time. long dbtime; final Calendar date = Calendar.getInstance(); final BusStopDatabase bsd = BusStopDatabase.getInstance(activity.getApplicationContext()); try { dbtime = bsd.getLastDBModTime(); } catch (SQLException e) { dbtime = 0; } date.setTimeInMillis(dbtime); // Set the DB version text. txtDBVersion.setText(getString(R.string.aboutdialog_dbversion, dbtime, dateFormat.format(date.getTime()))); // Set the topology ID text. txtTopoVersion.setText(getString(R.string.aboutdialog_topology, bsd.getTopoId())); final Button btnLicenses = (Button) layout.findViewById(R.id.btnLicenses); btnLicenses.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { callbacks.onShowLicences(); } }); // Get the AlertDialog.Builder with the correct theme set. final AlertDialog.Builder builder; if (isHoneycombOrGreater) { builder = getHoneycombDialog(activity); } else { builder = new AlertDialog.Builder(activity); } // Build the Dialog. builder.setView(layout).setNegativeButton(R.string.close, null); return builder.create(); }
From source file:it.telecomitalia.my.base_struct_apps.VersionUpdate.java
public VersionUpdate(Activity activity) { super();/*from www .j av a2 s. co m*/ /* http://developer.android.com/tools/publishing/versioning.html * si comincia dal capire che versione sto utilizzando. Nella documentazione sopra * elencata, leggersi tutto e fare attenzione alla differenza tra Version Name e * Version Code. Con questo metodo mi leggo il versionName e lo salvo per * ulteriori elaborazioni. In caso qualcosa non funzionasse ritorno null */ try { PackageManager manager = activity.getPackageManager(); PackageInfo info = manager.getPackageInfo(activity.getPackageName(), 0); runningVersion = info.versionName; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); runningVersion = null; } }
From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java
private String[] getRequiredPermissions() { Activity activity = getActivity(); try {//from w ww. j a va 2s. co m PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_PERMISSIONS); String[] ps = info.requestedPermissions; if (ps != null && ps.length > 0) { return ps; } else { return new String[0]; } } catch (Exception e) { return new String[0]; } }
From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java
/** * take picture//from w ww .ja v a 2s . c o m */ public void takePicture(Activity act, int requestCode) throws IOException { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // Ensure that there's a camera activity to handle the intent if (takePictureIntent.resolveActivity(act.getPackageManager()) != null) { // Create the File where the photo should go //File photoFile = createImageFile(); File photoFile = createImageSaveFile(act); // Continue only if the File was successfully created if (photoFile != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); } } act.startActivityForResult(takePictureIntent, requestCode); }
From source file:com.example.android.apprestrictionenforcer.SetupProfileFragment.java
/** * Initiates the managed profile provisioning. If we already have a managed profile set up on * this device, we will get an error dialog in the following provisioning phase. */// w w w . j av a 2s . co m private void provisionManagedProfile() { Activity activity = getActivity(); if (null == activity) { return; } Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE); if (Build.VERSION.SDK_INT >= 24) { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME, EnforcerDeviceAdminReceiver.getComponentName(activity)); } else { intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, activity.getApplicationContext().getPackageName()); intent.putExtra(EXTRA_DEVICE_ADMIN, EnforcerDeviceAdminReceiver.getComponentName(activity)); } if (intent.resolveActivity(activity.getPackageManager()) != null) { startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE); activity.finish(); } else { Toast.makeText(activity, "Device provisioning is not enabled. Stopping.", Toast.LENGTH_SHORT).show(); } }
From source file:crittercism.CrittercismModuleModule.java
@Kroll.method public void start(KrollDict dict) { String app_id = (String) dict.get("appID"); Boolean should_collect_logcat = (Boolean) dict.get("setLogcatReportingEnabled"); String custom_app_version = (String) dict.get("customAppVersion"); Activity activity = TiApplication.getAppCurrentActivity(); if (app_id != null) { // We have an app id, now we can do this try {/*from www . j a v a2s. c om*/ CrittercismConfig config = new CrittercismConfig(); // Set the version name if (custom_app_version != null) { config.setCustomVersionName(custom_app_version); config.setVersionCodeToBeIncludedInVersionString(false); } else { config.setCustomVersionName( activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName); config.setVersionCodeToBeIncludedInVersionString(true); } // Send logcat info if (should_collect_logcat != null && should_collect_logcat) { config.setLogcatReportingEnabled(should_collect_logcat); } // Initialize. Crittercism.initialize(activity.getApplicationContext(), app_id, config); handleLastCrash(); } catch (Exception e) { // Well... we couldn't start... // Log.e(LCAT, "Can't inialize because of: "+e); } ; } else { // There's no app id... we can't start it // Log.e(LCAT, "Crittercism cannot be initialized without an app id!"); } }
From source file:net.texh.cordovapluginstepcounter.CordovaStepCounter.java
@Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { LOG.i(TAG, "execute()"); Boolean result = true;// w ww . j a v a 2 s. c o m Activity activity = this.cordova.getActivity(); stepCounterIntent = new Intent(activity, StepCounterService.class); //Get stored value for pedometerActive SharedPreferences sharedPref = activity.getSharedPreferences(USER_DATA_PREF, Context.MODE_PRIVATE); Boolean pActive = this.getPedometerIsActive(sharedPref); if (ACTION_CAN_COUNT_STEPS.equals(action)) { Boolean can = deviceHasStepCounter(activity.getPackageManager()); Log.i(TAG, "Checking if device has step counter APIS: " + can); callbackContext.success(can ? 1 : 0); } else if (ACTION_START.equals(action)) { if (!pActive) { Log.i(TAG, "Starting StepCounterService"); //Update pedometerActive preference this.setPedometerIsActive(sharedPref, true); activity.startService(stepCounterIntent); } else { Log.i(TAG, "StepCounterService Already Started before, just binding to it"); } if (!bound) { Log.i(TAG, "Binding StepCounterService"); activity.bindService(stepCounterIntent, mConnection, Context.BIND_AUTO_CREATE); } else { Log.i(TAG, "StepCounterService already binded"); } //Try getting given param (starting value) Integer startingValue = 0; try { if (data.length() > 0) { startingValue = data.getInt(0); } } catch (JSONException error) { Log.i(TAG, "JSON EXCEPTION While Reading startingValue from 'execute' parameters (JSONArray)"); } //Reset TOTAL COUNT on start CordovaStepCounter.setTotalCount(sharedPref, startingValue); callbackContext.success(startingValue); } else if (ACTION_STOP.equals(action)) { if (pActive) { Log.i(TAG, "Stopping StepCounterService"); this.setPedometerIsActive(sharedPref, false); activity.stopService(stepCounterIntent); } else { Log.i(TAG, "StepCounterService already stopped"); } if (bound) { Log.i(TAG, "Unbinding StepCounterService"); activity.unbindService(mConnection); } else { Log.i(TAG, "StepCounterService already unbinded"); } activity.stopService(stepCounterIntent); Integer currentCount = CordovaStepCounter.getTotalCount(sharedPref); //Callback with final count callbackContext.success(currentCount); } else if (ACTION_GET_STEPS.equals(action)) { if (!pActive) { Log.i(TAG, "Be Careful you're getting a Step count with inactive Pedometer"); } Integer steps = CordovaStepCounter.getTotalCount(sharedPref); Log.i(TAG, "Geting steps counted from stepCounterService: " + steps); callbackContext.success(steps); } else if (ACTION_GET_TODAY_STEPS.equals(action)) { if (sharedPref.contains(PEDOMETER_HISTORY_PREF)) { String pDataString = sharedPref.getString(PEDOMETER_HISTORY_PREF, "{}"); Date currentDate = new Date(); SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd"); String currentDateString = dateFormatter.format(currentDate); JSONObject pData = new JSONObject(); JSONObject dayData = new JSONObject(); Integer daySteps = -1; try { pData = new JSONObject(pDataString); Log.d(TAG, " got json shared prefs " + pData.toString()); } catch (JSONException err) { Log.d(TAG, " Exception while parsing json string : " + pDataString); } if (pData.has(currentDateString)) { try { dayData = pData.getJSONObject(currentDateString); daySteps = dayData.getInt("steps"); } catch (JSONException err) { Log.e(TAG, "Exception while getting Object from JSON for " + currentDateString); } } Log.i(TAG, "Getting steps for today: " + daySteps); callbackContext.success(daySteps); } else { Log.i(TAG, "No steps history found in stepCounterService !"); callbackContext.success(-1); } } else if (ACTION_GET_HISTORY.equals(action)) { if (sharedPref.contains(PEDOMETER_HISTORY_PREF)) { String pDataString = sharedPref.getString(PEDOMETER_HISTORY_PREF, "{}"); Log.i(TAG, "Getting steps history from stepCounterService: " + pDataString); callbackContext.success(pDataString); } else { Log.i(TAG, "No steps history found in stepCounterService !"); callbackContext.success("{}"); } } else { Log.e(TAG, "Invalid action called on class " + TAG + ", " + action); callbackContext.error("Invalid action called on class " + TAG + ", " + action); } return result; }
From source file:com.vuze.android.remote.AndroidUtils.java
public static void openFileChooser(Activity activity, String mimeType, int requestCode) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType);//ww w . j a va2 s.co m intent.addCategory(Intent.CATEGORY_OPENABLE); // special intent for Samsung file manager Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); sIntent.putExtra("CONTENT_TYPE", mimeType); sIntent.addCategory(Intent.CATEGORY_DEFAULT); Intent chooserIntent; if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) { chooserIntent = Intent.createChooser(sIntent, "Open file"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent }); } else { chooserIntent = Intent.createChooser(intent, "Open file"); } if (chooserIntent != null) { try { activity.startActivityForResult(chooserIntent, requestCode); return; } catch (android.content.ActivityNotFoundException ex) { } } Toast.makeText(activity.getApplicationContext(), activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show(); }
From source file:fr.kwiatkowski.apktrack.ui.AppDisplayFragment.java
/** * This method loads the list of installed applications from the database, * or generates it if no data exists./*from ww w . ja va2s . c om*/ */ private List<InstalledApp> _initialize_data() { String where_clause = "_isignored = 0"; // Check whether system apps should be displayed Activity activity = getActivity(); if (activity != null) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity); boolean show_system = pref.getBoolean(SettingsFragment.KEY_PREF_SHOW_SYSTEM, false); if (!show_system) { where_clause += " and _systemapp = 0"; } } List<InstalledApp> installed_apps = InstalledApp.find(InstalledApp.class, where_clause); if (installed_apps.size() == 0 && activity != null) // Database is empty { Log.v(MainActivity.TAG, "Populating database..."); InstalledApp.generate_applist_from_system(activity.getPackageManager()); installed_apps = InstalledApp.find(InstalledApp.class, "_systemapp = 0 AND _isignored = 0"); Log.v(MainActivity.TAG, "...database populated. " + InstalledApp.count(InstalledApp.class) + " records created."); // Enable the "dhow system apps" button now that there may be system apps. activity.invalidateOptionsMenu(); } else if (activity != null) { Log.v(MainActivity.TAG, installed_apps.size() + " records read from the database."); } return installed_apps; }