List of usage examples for android.content ComponentName ComponentName
private ComponentName(String pkg, Parcel in)
From source file:com.google.android.apps.muzei.SourceManager.java
public void selectDefaultSource() { selectSource(new ComponentName(mApplicationContext, FeaturedArtSource.class)); }
From source file:com.daon.identityx.samplefidoapp.SplashActivity.java
/*** * Retrieve the set of authenticators from the FIDO clients by using the FIDO discovery * * The list of authenticators is cached within this class so if authenticators can be * dynamically added or removed from the device, they will not be picked up after the * app is initialized./*w w w .j a v a 2s . c o m*/ * */ protected void retrieveAvailableAuthenticatorAaids() { if (!aaidRetrievalAttempted) { LogUtils.logAaidRetrievalStart(); List<ResolveInfo> clientList = getUafClientList(); this.setCurrentFidoOperation(FidoOperation.Discover); Intent intent = getUafClientUtils().getDiscoverIntent(); if (clientList != null && clientList.size() > 0) { intent.setComponent(new ComponentName(clientList.get(uafClientIdx).activityInfo.packageName, clientList.get(uafClientIdx).activityInfo.name)); UafClientLogUtils.logUafDiscoverRequest(intent); UafClientLogUtils.logUafClientDetails(clientList.get(uafClientIdx)); startActivityForResult(intent, AndroidClientIntentParameters.requestCode); return; } else { // End now if there are no clients LogUtils.logDebug(LogUtils.TAG, (String) getText(R.string.no_fido_client_found)); LogUtils.logAaidRetrievalEnd(); aaidRetrievalAttempted = true; } } if (System.currentTimeMillis() < (start + SPLASH_DISPLAY)) { try { Thread.sleep(start + SPLASH_DISPLAY - System.currentTimeMillis()); } catch (InterruptedException ex) { // ignore and carry on } } finish(); try { Intent newIntent = new Intent(this, IntroActivity.class); startActivity(newIntent); } catch (Throwable ex) { displayError(ex.getMessage()); } }
From source file:org.ohthehumanity.carrie.CarrieActivity.java
/** Called when the activity is first created. */ @Override/*from ww w . j a v a2 s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mServerName = ""; setContentView(R.layout.main); // instantiate our preferences backend mPreferences = PreferenceManager.getDefaultSharedPreferences(this); // set callback function when settings change mPreferences.registerOnSharedPreferenceChangeListener(this); if (mPreferences.getString("server", null) == null) { setStatus("Server not set"); } else if (mPreferences.getString("port", null) == null) { setStatus("Port not configured"); } ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) { AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this); dlgAlert.setTitle("WiFi not active"); dlgAlert.setMessage( "This application is usually used on a local network over a WiFi. Open WiFi settings?"); dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: //Yes button clicked final Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); break; case DialogInterface.BUTTON_NEGATIVE: //Log.i(TAG, "Not opening wifi"); //No button clicked break; } } }); dlgAlert.setNegativeButton("No", null); dlgAlert.setCancelable(true); dlgAlert.create().show(); } updateTitle(); updateSkipLabels(); updateServerName(); }
From source file:com.battlelancer.seriesguide.extensions.ExtensionManager.java
/** * Queries the {@link android.content.pm.PackageManager} for any installed {@link * com.battlelancer.seriesguide.api.SeriesGuideExtension} extensions. Their info is extracted * into {@link com.battlelancer.seriesguide.extensions.ExtensionManager.Extension} objects. *//*w w w . j a v a2s . c o m*/ public List<Extension> queryAllAvailableExtensions() { Intent queryIntent = new Intent(SeriesGuideExtension.ACTION_SERIESGUIDE_EXTENSION); PackageManager pm = mContext.getPackageManager(); List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, PackageManager.GET_META_DATA); List<Extension> extensions = new ArrayList<>(); for (ResolveInfo info : resolveInfos) { Extension extension = new Extension(); // get label, icon and component name extension.label = info.loadLabel(pm).toString(); extension.icon = info.loadIcon(pm); extension.componentName = new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name); // get description Context packageContext; try { packageContext = mContext.createPackageContext(extension.componentName.getPackageName(), 0); Resources packageRes = packageContext.getResources(); extension.description = packageRes.getString(info.serviceInfo.descriptionRes); } catch (SecurityException | PackageManager.NameNotFoundException | Resources.NotFoundException e) { Timber.e(e, "Reading description for extension " + extension.componentName + " failed"); extension.description = ""; } // get (optional) settings activity Bundle metaData = info.serviceInfo.metaData; if (metaData != null) { String settingsActivity = metaData.getString("settingsActivity"); if (!TextUtils.isEmpty(settingsActivity)) { extension.settingsActivity = ComponentName .unflattenFromString(info.serviceInfo.packageName + "/" + settingsActivity); } } Timber.d("queryAllAvailableExtensions: found extension " + extension.label + " " + extension.componentName); extensions.add(extension); } return extensions; }
From source file:com.chale22.ico01.fragments.FragmentExtras.java
private void actRequest() { String pkg = getResources().getString(R.string.pkg); Intent iconrequest = new Intent(Intent.ACTION_MAIN); iconrequest.setComponent(new ComponentName(pkg, pkg + ".IconRequest")); try {/*w w w . j a v a2 s . co m*/ startActivity(iconrequest); } catch (RuntimeException icons) { icons.printStackTrace(); } }
From source file:com.apexlabs.alarm.AlarmService.java
private Intent getClockIntent() { PackageManager packageManager = getPackageManager(); Intent alarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); // Verify clock implementation String clockImpls[][] = {/*from w w w .jav a 2 s.co m*/ { "HTC", "com.htc.android.worldclock", "com.htc.android.worldclock.WorldClockTabControl" }, { "Standard", "com.android.deskclock", "com.android.deskclock.AlarmClock" }, { "Froyo", "com.google.android.deskclock", "com.android.deskclock.DeskClock" }, { "Motorola", "com.motorola.blur.alarmclock", "com.motorola.blur.alarmclock.AlarmClock" }, { "Sony Ericsson", "com.sonyericsson.alarm", "com.sonyericsson.alarm.Alarm" }, { "Samsung", "com.sec.android.app.clockpackage", "com.sec.android.app.clockpackage.ClockPackage" } }; boolean foundClockImpl = false; for (int i = 0; i < clockImpls.length; i++) { String packageName = clockImpls[i][1]; String className = clockImpls[i][2]; try { ComponentName cn = new ComponentName(packageName, className); packageManager.getActivityInfo(cn, PackageManager.GET_META_DATA); alarmClockIntent.setComponent(cn); foundClockImpl = true; break; } catch (NameNotFoundException e) { Log.d(TAG, "Alarm clock " + clockImpls[i][0] + " not found"); } } if (foundClockImpl) { alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } return alarmClockIntent; }
From source file:com.appsaur.tarucassist.AlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:com.ericsender.android_nanodegree.popmovie.com.ericsender.android_nanodegree.popmovie.data.TestProvider.java
public void testProviderRegistry() { PackageManager pm = mContext.getPackageManager(); // We define the component name based on the package name from the context and the // MovieProvider class. ComponentName componentName = new ComponentName(mContext.getPackageName(), MovieProvider.class.getName()); try {/* w w w . ja va 2s .c o m*/ // Fetch the provider info using the component name from the PackageManager // This throws an exception if the provider isn't registered. ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0); // Make sure that the registered authority matches the authority from the Contract. assertEquals( "Error: MovieProvider registered with authority: " + providerInfo.authority + " instead of authority: " + MovieContract.CONTENT_AUTHORITY, providerInfo.authority, MovieContract.CONTENT_AUTHORITY); } catch (PackageManager.NameNotFoundException e) { // I guess the provider isn't registered correctly. assertTrue("Error: MovieProvider not registered at " + mContext.getPackageName(), false); } }
From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { // The data from the menu item. AdapterView.AdapterContextMenuInfo info; // Tries to get the position of the item in the ListView that was long-pressed. try {/*from w ww . jav a 2s. co m*/ // Casts the incoming data object into the type for AdapterView objects. info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { // If the menu object can't be cast, logs an error. Log.e(TAG, "bad menuInfo", e); return; } Intent intent = new Intent(null, Uri.withAppendedPath(getIntent().getData(), Integer.toString((int) info.id))); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null, intent, 0, null); }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
@Override protected Integer doInBackground(Void... params) { SharedPreferences prefs = dataService.getSharedPreferences(SETTINGS_NAME, Context.MODE_PRIVATE); // Connectivity receiver. final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); ComponentName receiver = new ComponentName(dataService, WifiReceiver.class); PackageManager pm = dataService.getPackageManager(); if (activeNetwork == null || !activeNetwork.isConnected()) { // We've missed a scheduled update. Enable the receiver so it can launch an update when we reconnect. Log.d(LOG_TAG, "Missed library update: not connected. Enabling connectivity receiver."); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); return RESULT_CODE_FAILURE; } else {/*from w w w . j a v a 2 s . c o m*/ // We are connected. Disable the receiver. Log.d(LOG_TAG, "Library updater connected. Disabling connectivity receiver."); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } InputStream in = null; String etag = prefs.getString(SETTING_LIBRARY_ETAG, null); try { HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); if (etag != null && !force) { conn.setRequestProperty("If-None-Match", etag); } int code = conn.getResponseCode(); switch (code) { case HttpStatus.SC_NOT_MODIFIED: // If we got a 304, we're done. // Use failure code to indicate there is no temp db to copy over. Log.d(LOG_TAG, "304 in library response."); return RESULT_CODE_FAILURE; default: // Odd, but on 1/3/13 I received correct json responses with a -1 for responseCode. Fall through. Log.w(LOG_TAG, "Error code in library response: " + code); case HttpStatus.SC_OK: // Parse response. in = conn.getInputStream(); JsonFactory factory = new JsonFactory(); final JsonParser parser = factory.createJsonParser(in); SQLiteDatabase tempDb = tempDbHelper.getWritableDatabase(); tempDb.beginTransaction(); try { tempDb.execSQL("delete from topic"); tempDb.execSQL("delete from topicvideo"); tempDb.execSQL("delete from video"); parseObject(parser, tempDb, null, 0); tempDb.setTransactionSuccessful(); } catch (Exception e) { e.printStackTrace(); return RESULT_CODE_FAILURE; } finally { tempDb.endTransaction(); tempDb.close(); } // Save etag once we've successfully parsed the response. etag = conn.getHeaderField("ETag"); prefs.edit().putString(SETTING_LIBRARY_ETAG, etag).apply(); // Move this new content from the temp db into the main one. mergeDbs(); return RESULT_CODE_SUCCESS; } } catch (MalformedURLException e) { e.printStackTrace(); } catch (JsonParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { tempDbHelper.close(); } return RESULT_CODE_FAILURE; }