List of usage examples for android.content Context ACCOUNT_SERVICE
String ACCOUNT_SERVICE
To view the source code for android.content Context ACCOUNT_SERVICE.
Click Source Link
From source file:com.cyanogenmod.account.util.CMAccountUtils.java
public static byte[] getHmacSecret(Context context) { AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account account = getCMAccountAccount(context); return getHmacSecret(accountManager, account); }
From source file:net.heroicefforts.viable.android.rep.it.GIssueTrackerRepository.java
private void manageAccount() { AccountManager accMgr = (AccountManager) act.getSystemService(Context.ACCOUNT_SERVICE); if (Config.LOGD) Log.d(TAG, "Requesting account creation."); Account[] accts = accMgr.getAccountsByType(GCLAccountAuthenticator.ACCT_TYPE); if (accts.length > 0) accMgr.confirmCredentials(accts[0], null, act, callback, null); else/* w w w. j a v a 2 s .c o m*/ accMgr.addAccount(GCLAccountAuthenticator.ACCT_TYPE, GCLAccountAuthenticator.TOKEN_TYPE_ISSUE_TRACKER, null, null, act, callback, null); }
From source file:com.phonemetra.account.util.AccountUtils.java
public static byte[] getHmacSecret(Context context) { AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); Account account = getAccountAccount(context); return getHmacSecret(accountManager, account); }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one * if the fake account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account./*from w w w. ja v a2 s .c o m*/ */ private static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { /* * Add the account and account type, no password or user data * If successful, return the Account object, otherwise report an error. */ if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } /* * If you don't set android:syncable="true" in * in your <provider> element in the manifest, * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1) * here. */ onAccountCreated(newAccount, context); } return newAccount; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.MessagesActivity.java
protected void callVideo() { if ((mGroup == null) && (mUser == null)) { log.warn("Group and user not set, cannot call"); return;//from w w w .ja va 2 s .co m } String userVideoName = ""; if ((mGroup != null) || (mUser != null)) { Account ac = AccountUtils.getAccount(messagesActivity, true); if (ac != null) { account = ac; AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); userVideoName = am.getUserData(ac, JsonKeys.NAME) + am.getUserData(ac, JsonKeys.SURNAME); getActionBar().setSubtitle(userName); } Intent i = new Intent(messagesActivity, RoomActivity.class); i.putExtra(RoomActivity.EXTRA_ROOM_NAME, timeline.getParty().getId().toString()); i.putExtra(RoomActivity.EXTRA_USER_NAME, userVideoName); messagesActivity.startActivity(i); } else { return; } }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static String sendMessageToServer(final Context ctx, final String path, final Long toId, final String toType, final Long timelineId, boolean retry, Long localId, String messageBody, Object messageApp) {/*from w ww . j a va 2 s . c o m*/ Account account = AccountUtils.getAccount(ctx.getApplicationContext(), true); AccountManager am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE); MessageSend m = new MessageSend(); m.setBody(messageBody); m.setFrom(Long.valueOf(am.getUserData(account, JsonKeys.ID_STORED))); m.setTo(toId); m.setLocalId(localId); if (messageApp != null) m.setApp(messageApp); CommandStoreService cs = new CommandStoreService(ctx.getApplicationContext()); try { boolean result = false; if (toType.equals(JsonKeys.GROUP)) { result = cs.createCommand(JsonParser.MessageSendToJson(m), Command.METHOD_SEND_MESSAGE_TO_GROUP, path); } else if (toType.equals(JsonKeys.USER)) { result = cs.createCommand(JsonParser.MessageSendToJson(m), Command.METHOD_SEND_MESSAGE_TO_USER, path); } if (result) { return ConstantKeys.SENDING_OK; } else { return ConstantKeys.SENDING_OFFLINE; } } catch (JSONException e) { log.error("Cannot create command", e); return ConstantKeys.SENDING_FAIL; } }
From source file:com.landenlabs.all_devtool.SystemFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();/*from w w w.jav a 2 s .c o m*/ // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { long heapSize = Debug.getNativeHeapSize(); // long maxHeap = Runtime.getRuntime().maxMemory(); // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo(); int largHeapMb = actMgr.getLargeMemoryClass(); int heapMb = actMgr.getMemoryClass(); MemoryInfo memInfo = new MemoryInfo(); actMgr.getMemoryInfo(memInfo); final String sFmtMB = "%.2f MB"; Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB)); listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB)); if (Build.VERSION.SDK_INT >= 16) { listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB)); } listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB)); listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb)); listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb)); addBuild("Memory...", listStr); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState(); int errCnt = (procErrList == null ? 0 : procErrList.size()); procErrList = null; // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses(); int procCnt = actMgr.getRunningAppProcesses().size(); int srvCnt = actMgr.getRunningServices(100).size(); Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("#Processes", String.valueOf(procCnt)); listStr.put("#Proc With Err", String.valueOf(errCnt)); listStr.put("#Services", String.valueOf(srvCnt)); // Requires special permission // int taskCnt = actMgr.getRunningTasks(100).size(); // listStr.put("#Tasks", String.valueOf(taskCnt)); addBuild("Processes...", listStr); } catch (Exception ex) { m_log.e("System-Processes %s", ex.getMessage()); } try { Map<String, String> listStr = new LinkedHashMap<String, String>(); listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity())); listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize())); putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness()); putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey()); addBuild("Misc...", listStr); } catch (Exception ex) { m_log.e("System-Misc %s", ex.getMessage()); } // --------------- Locale / Timezone ------------- try { Locale ourLocale = Locale.getDefault(); Date m_date = new Date(); TimeZone tz = TimeZone.getDefault(); Map<String, String> localeListStr = new LinkedHashMap<String, String>(); localeListStr.put("Locale Name", ourLocale.getDisplayName()); localeListStr.put(" Variant", ourLocale.getVariant()); localeListStr.put(" Country", ourLocale.getCountry()); localeListStr.put(" Country ISO", ourLocale.getISO3Country()); localeListStr.put(" Language", ourLocale.getLanguage()); localeListStr.put(" Language ISO", ourLocale.getISO3Language()); localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage()); localeListStr.put("TimeZoneID", tz.getID()); localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No"); localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No"); localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale)); localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale)); addBuild("Locale TZ...", localeListStr); } catch (Exception ex) { m_log.e("Locale/TZ %s", ex.getMessage()); } // --------------- Location Services ------------- try { Map<String, String> listStr = new LinkedHashMap<String, String>(); final LocationManager locMgr = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); GpsStatus gpsStatus = locMgr.getGpsStatus(null); if (gpsStatus != null) { listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix())); Iterable<GpsSatellite> satellites = gpsStatus.getSatellites(); Iterator<GpsSatellite> sat = satellites.iterator(); while (sat.hasNext()) { GpsSatellite satellite = sat.next(); putIf(listStr, String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()), String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix()); } } Location location = null; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (null != location) { listStr.put(location.getProvider() + " lat,lng", String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude())); } if (listStr.size() != 0) { List<String> gpsProviders = locMgr.getAllProviders(); int idx = 1; for (String providerName : gpsProviders) { LocationProvider provider = locMgr.getProvider(providerName); if (null != provider) { listStr.put(providerName, (locMgr.isProviderEnabled(providerName) ? "On " : "Off ") + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(), provider.getPowerRequirement())); } } addBuild("GPS...", listStr); } else addBuild("GPS", "Off"); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Application Info ------------- ApplicationInfo appInfo = getActivity().getApplicationInfo(); if (null != appInfo) { Map<String, String> appList = new LinkedHashMap<String, String>(); try { appList.put("ProcName", appInfo.processName); appList.put("PkgName", appInfo.packageName); appList.put("DataDir", appInfo.dataDir); appList.put("SrcDir", appInfo.sourceDir); // appList.put("PkgResDir", getActivity().getPackageResourcePath()); // appList.put("PkgCodeDir", getActivity().getPackageCodePath()); String[] dbList = getActivity().databaseList(); if (dbList != null && dbList.length != 0) appList.put("DataBase", dbList[0]); // getActivity().getComponentName(). } catch (Exception ex) { } addBuild("AppInfo...", appList); } // --------------- Account Services ------------- final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); if (null != accMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); try { for (Account account : accMgr.getAccounts()) { strList.put(account.name, account.type); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Accounts...", strList); } // --------------- Package Features ------------- PackageManager pm = getActivity().getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); if (features != null) { Map<String, String> strList = new LinkedHashMap<String, String>(); for (FeatureInfo featureInfo : features) { strList.put(featureInfo.name, ""); } addBuild("Features...", strList); } // --------------- Sensor Services ------------- final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (null != senMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL); try { for (Sensor sensor : listSensor) { strList.put(sensor.getName(), sensor.getVendor()); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Sensors...", strList); } try { if (Build.VERSION.SDK_INT >= 17) { final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); if (null != userMgr) { try { addBuild("UserName", userMgr.getUserName()); } catch (Exception ex) { m_log.e(ex.getMessage()); } } } } catch (Exception ex) { } try { Map<String, String> strList = new LinkedHashMap<String, String>(); int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT); strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000)); int rotate = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); strList.put("RotateEnabled", String.valueOf(rotate)); if (Build.VERSION.SDK_INT >= 17) { // Global added in API 17 int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED); strList.put("AdbEnabled", String.valueOf(adb)); } addBuild("Settings...", strList); } catch (Exception ex) { } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.upenn.chriswang1990.sunshine.sync.SunshineSyncAdapter.java
/** * Helper method to get the fake account to be used with SyncAdapter, or make a new one * if the fake account doesn't exist yet. If we make a new account, we call the * onAccountCreated method so we can initialize things. * * @param context The context used to access the account service * @return a fake account.// w ww. j a v a2 s . c o m */ public static Account getSyncAccount(Context context) { // Get an instance of the Android account manager AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); // Create the account type and default account Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type)); // If the password doesn't exist, the account doesn't exist if (null == accountManager.getPassword(newAccount)) { /* * Add the account and account type, no password or user data * If successful, return the Account object, otherwise report an error. */ if (!accountManager.addAccountExplicitly(newAccount, "", null)) { return null; } /* * If you don't set android:syncable="true" in * in your <provider> element in the manifest, * then call ContentResolver.setIsSyncable(account, AUTHORITY, 1) * here. */ onAccountCreated(newAccount, context); } return newAccount; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.MessagesActivity.java
protected void setupMsgToBeShown(MessageObject mo) { if (mo.getContent().getContentSize() > 0) { mo.setHumanSize(AppUtils.humanReadableByteCount(mo.getContent().getContentSize(), true)); }/*from w w w .ja v a 2s. c o m*/ Account ac = AccountUtils.getAccount(messagesActivity, false); if (ac == null) { log.warn("Cannot setup messages to be shown. Account is null"); return; } AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); String userId = am.getUserData(ac, JsonKeys.ID_STORED); String fromId = String.valueOf(mo.getFrom().getId()); if (userId.equals(fromId)) { mo.setBackgroundColor(R.drawable.bg_right); mo.setMarginLeft(getResources().getDimensionPixelSize(R.dimen.message_margin)); mo.setMarginRight(0); mo.setMessageFromSize(0); mo.setMessageStatusSize(getResources().getDimensionPixelSize(R.dimen.message_status_icon)); mo.setAlignLayout(RelativeLayout.ALIGN_RIGHT); mo.setAvatarSize(0); mo.getFrom().setName(ConstantKeys.STRING_DEFAULT); mo.getFrom().setSurname(ConstantKeys.STRING_DEFAULT); mo.setCanCall(null); } else { mo.setMessageStatusSize(0); mo.setBackgroundColor(R.drawable.bg_left); mo.setMarginLeft(0); mo.setMarginRight(getResources().getDimensionPixelSize(R.dimen.message_margin)); mo.setMessageFromSize(getResources().getDimensionPixelSize(R.dimen.message_from)); mo.setAlignLayout(RelativeLayout.ALIGN_LEFT); mo.setAvatarSize(getResources().getDimensionPixelSize(R.dimen.message_avatar)); mo.setCanCall(null); } if (mo.getContent().getId() != 0) { mo.setMediaThumbnailSize(getResources().getDimensionPixelSize(R.dimen.media_thumnail)); mo.setMediaCancelButtonSize(0); mo.setMediaTypeIconSize(getResources().getDimensionPixelSize(R.dimen.media_type_icon)); if (mo.getContent().getContentType().contains(ConstantKeys.IMAGE)) { mo.setMediaTypeIconResource(android.R.drawable.ic_menu_camera); } else if (mo.getContent().getContentType().contains(ConstantKeys.VIDEO)) { mo.setMediaTypeIconResource(android.R.drawable.ic_media_play); } else { mo.setMediaTypeIconResource(android.R.drawable.ic_menu_gallery); } } else { mo.setMediaThumbnailSize(0); mo.setMediaCancelButtonSize(0); mo.setMediaTypeIconSize(0); // we need something to load, but it's not gonna be shown mo.setMediaTypeIconResource(android.R.drawable.ic_menu_gallery); } }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.MessagesActivity.java
@Override protected void onResume() { super.onResume(); registerReceivers();/*w ww.j av a 2 s.co m*/ if (AppUtils.getDefaults(ConstantKeys.FROMLOGIN, messagesActivity).equalsIgnoreCase("true")) { finish(); } AppUtils.CancelNotification(getApplicationContext()); Account ac = AccountUtils.getAccount(messagesActivity, true); if (ac != null) { account = ac; AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE); userName = am.getUserData(ac, JsonKeys.NAME) + " " + am.getUserData(ac, JsonKeys.SURNAME); getActionBar().setSubtitle(userName); } // First we need to take the group from this timeline if (timeline.getParty().getType().equals(ConstantKeys.GROUP)) { ArrayList<GroupObject> groups = DataBasesAccess.getInstance(getApplicationContext()) .GroupsDataBase(DataBasesAccess.READ, null); for (GroupObject group : groups) { if (group.getGroupId().equals(String.valueOf(timeline.getParty().getId()))) { mGroup = group; break; } } } else if (timeline.getParty().getType().equals(ConstantKeys.USER)) { ArrayList<UserObject> users = DataBasesAccess.getInstance(getApplicationContext()) .UsersDataBase(DataBasesAccess.READ, null); for (UserObject user : users) { if (user.getId().toString().equals(String.valueOf(timeline.getParty().getId()))) { mUser = user; break; } } } DataBasesAccess.getInstance(getApplicationContext()).TimelinesDataBaseWriteNewMessageFalse(timeline); doRefresh(!fromOnCreate); updateTimeline(); }