List of usage examples for android.content Context getString
@NonNull public final String getString(@StringRes int resId)
From source file:biz.bokhorst.xprivacy.Util.java
@SuppressLint("DefaultLocale") public static boolean hasValidFingerPrint(Context context) { try {/* w ww .j av a2 s . c o m*/ PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); byte[] cert = packageInfo.signatures[0].toByteArray(); MessageDigest digest = MessageDigest.getInstance("SHA1"); byte[] bytes = digest.digest(cert); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; ++i) sb.append((Integer.toHexString((bytes[i] & 0xFF) | 0x100)).substring(1, 3).toLowerCase()); String calculated = sb.toString(); String expected = context.getString(R.string.fingerprint); return calculated.equals(expected); } catch (Throwable ex) { bug(null, ex); return false; } }
From source file:de.ub0r.android.websms.connector.innosend.ConnectorInnosend.java
/** * {@inheritDoc}/*from ww w . ja v a2 s. com*/ */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_innosend_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(context.getString(R.string.connector_innosend_author)); c.setBalance(null); c.setCapabilities(ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (!p.getBoolean(PREFS_HIDE_FREE, false)) { c.addSubConnector(ID_FREE, context.getString(R.string.free), SubConnectorSpec.FEATURE_NONE); } if (!p.getBoolean(PREFS_HIDE_TYPE3, false)) { c.addSubConnector(ID_TYPE3, context.getString(R.string.type3), SubConnectorSpec.FEATURE_NONE); } if (!p.getBoolean(PREFS_HIDE_WO_SENDER, false)) { c.addSubConnector(ID_WO_SENDER, context.getString(R.string.wo_sender), SubConnectorSpec.FEATURE_SENDLATER | SubConnectorSpec.FEATURE_FLASHSMS); } if (!p.getBoolean(PREFS_HIDE_W_SENDER, false)) { c.addSubConnector(ID_W_SENDER, context.getString(R.string.w_sender), SubConnectorSpec.FEATURE_CUSTOMSENDER | SubConnectorSpec.FEATURE_SENDLATER); } return c; }
From source file:com.notifry.android.remote.BackendRequest.java
/** * Fire off this request in a thread in the background. * @param context The context for this request. * @param statusMessage If provided, show a progress dialog with this message. If NULL, no progress dialog is shown. * @param accountName The account name to perform the request under. *///from w w w.ja v a 2 s . c o m public void startInThread(final Context context, final String statusMessage, final String accountName) { // Set up the dialog. if (statusMessage != null) { this.dialog = ProgressDialog.show(context, context.getString(R.string.app_name), statusMessage, true); } // Create a new thread. Thread thread = new Thread() { public void run() { // Create a client. BackendClient client = new BackendClient(context, accountName); BackendResponse result; try { //Log.i(TAG, "Beginning request..."); result = client.request(thisRequest); // Was it successful? /*if( result.isError() ) { Log.e(TAG, "Error: " + result.getError()); } else { Log.e(TAG, "Success! Server returned: " + result.getJSON().toString()); }*/ // Prepare the message to send back. Message message = Message.obtain(); message.obj = result; // Post it to ourselves - it will then post it back to the real thread. handler.sendMessage(message); } catch (Exception e) { Log.e(TAG, "Generic exception: " + e.getMessage() + " of type " + e.getClass().toString()); } } }; // And start the request. thread.start(); }
From source file:net.reichholf.dreamdroid.helpers.SimpleHttpClient.java
public String getErrorText(Context context) { if (mErrorTextId > 0) return context.getString(mErrorTextId); return mErrorText; }
From source file:com.rothconsulting.android.websms.connector.yallo.ConnectorYallo.java
/** * {@inheritDoc}/* w w w. j ava 2 s. c o m*/ */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_yallo_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(context.getString(R.string.connector_yallo_author)); c.setBalance(null); c.setLimitLength(130); c.setAdUnitId(AD_UNITID); c.setCapabilities(ConnectorSpec.CAPABILITIES_BOOTSTRAP | ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); c.addSubConnector("yallo", c.getName(), SubConnectorSpec.FEATURE_MULTIRECIPIENTS); return c; }
From source file:com.rothconsulting.android.websms.connector.coopmobile.ConnectorCoopMobile.java
/** * {@inheritDoc}/*from ww w. j ava2 s . c o m*/ */ @Override public final ConnectorSpec initSpec(final Context context) { final String name = context.getString(R.string.connector_coop_name); ConnectorSpec c = new ConnectorSpec(name); c.setAuthor(context.getString(R.string.connector_coop_author)); c.setBalance(null); c.setLimitLength(718); c.setAdUnitId(AD_UNITID); c.setCapabilities(ConnectorSpec.CAPABILITIES_BOOTSTRAP | ConnectorSpec.CAPABILITIES_UPDATE | ConnectorSpec.CAPABILITIES_SEND | ConnectorSpec.CAPABILITIES_PREFS); c.addSubConnector("sunrise", c.getName(), SubConnectorSpec.FEATURE_MULTIRECIPIENTS); return c; }
From source file:com.mappn.gfan.common.util.Utils.java
/** * Android /* w w w .j a v a 2 s. c om*/ * * @param context Application Context * @param filePath APK */ public static void installApk(Context context, File file) { if (file.exists()) { Intent i = new Intent(Intent.ACTION_VIEW); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); ((ContextWrapper) context).startActivity(i); } else { makeEventToast(context, context.getString(R.string.install_fail_file_not_exist), false); } }
From source file:at.ac.tuwien.detlef.gpodder.SyncEpisodeActionsAsyncTask.java
@Override public void run() { Context context = Detlef.getAppContext(); /* Retrieve settings.*/ GpodderSettings gps = Singletons.i().getGpodderSettings(); DeviceId devId = gps.getDeviceId();/*from ww w . jav a 2 s.c o m*/ if (devId == null) { sendError(context.getString(R.string.no_gpodder_account_configured)); return; } String username = gps.getUsername(); String password = gps.getPassword(); MygPodderClient gpc = new MygPodderClient(username, password, gps.getApiHostname()); EpisodeActionChanges changes = null; try { /* Send our episode actions */ EpisodeActionDAO eaDao = Singletons.i().getEpisodeActionDAO(); List<RemoteEpisodeAction> localChanges = eaDao.getAllEpisodeActions(); List<EpisodeAction> sndLocalChanges = new ArrayList<EpisodeAction>(localChanges.size()); for (EpisodeAction a : localChanges) { sndLocalChanges.add(a); } long since = gpc.uploadEpisodeActions(sndLocalChanges); /* Get episode actions. */ changes = gpc.downloadEpisodeActions(gps.getLastEpisodeActionUpdate()); applyActionChanges(Detlef.getAppContext(), changes); /* Sadly, changes.since is always 0, hence we can't use it to fetch new * episode actions. So we use the timestamp returned by the upload. */ gps.setLastEpisodeActionUpdate(since); Singletons.i().getGpodderSettingsDAO().writeSettings(gps); } catch (AuthenticationException e) { sendError(e.getLocalizedMessage()); } catch (ClientProtocolException e) { sendError(e.getLocalizedMessage()); } catch (IOException e) { sendError(e.getLocalizedMessage()); } if (changes == null) { return; } /* Tell receiver we're done.. */ callback.sendEvent(new NoDataResultHandler.NoDataSuccessEvent(callback)); }
From source file:com.otaupdater.utils.KernelInfo.java
@TargetApi(11) public long fetchFile(Context ctx) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle(ctx.getString(R.string.notif_downloading)); request.setDescription(kernelName);/* ww w . j a v a2s. c o m*/ request.setVisibleInDownloadsUi(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationUri(Uri.fromFile(new File(Config.KERNEL_DL_PATH_FILE, getDownloadFileName()))); int netTypes = DownloadManager.Request.NETWORK_WIFI; if (!Config.getInstance(ctx).getWifiOnlyDl()) netTypes |= DownloadManager.Request.NETWORK_MOBILE; request.setAllowedNetworkTypes(netTypes); DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE); return manager.enqueue(request); }
From source file:com.otaupdater.utils.RomInfo.java
@TargetApi(11) public long fetchFile(Context ctx) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle(ctx.getString(R.string.notif_downloading)); request.setDescription(romName);/*www . ja v a 2 s . c om*/ request.setVisibleInDownloadsUi(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationUri(Uri.fromFile(new File(Config.ROM_DL_PATH_FILE, getDownloadFileName()))); int netTypes = DownloadManager.Request.NETWORK_WIFI; if (!Config.getInstance(ctx).getWifiOnlyDl()) netTypes |= DownloadManager.Request.NETWORK_MOBILE; request.setAllowedNetworkTypes(netTypes); DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE); return manager.enqueue(request); }