List of usage examples for android.util Log INFO
int INFO
To view the source code for android.util Log INFO.
Click Source Link
From source file:net.dian1.player.service.PlayerService.java
/** * Send changes to selected scrobbling application *///from ww w . j ava 2s .co m private void scrobblerMetaChanged() { PlaylistEntry entry = mPlayerEngine.getPlaylist().getSelectedTrack(); if (entry != null) { String scrobblerApp = PreferenceManager.getDefaultSharedPreferences(PlayerService.this) .getString("scrobbler_app", ""); assert (scrobblerApp.length() > 0); if (Log.isLoggable(Dian1Application.TAG, Log.INFO)) { Log.i(Dian1Application.TAG, "Scrobbling track " + entry.getMusic().getName() + " via " + scrobblerApp); } if (scrobblerApp.equalsIgnoreCase("lastfm")) { Intent i = new Intent(LASTFM_INTENT); i.putExtra("artist", entry.getAlbum().getArtistName()); i.putExtra("album", entry.getAlbum().getName()); i.putExtra("track", entry.getMusic().getName()); i.putExtra("duration", entry.getMusic().getDuration() * 1000); // duration in milliseconds sendBroadcast(i); } else if (scrobblerApp.equalsIgnoreCase("simplefm")) { Intent i = new Intent(SIMPLEFM_INTENT); i.putExtra("app-name", getResources().getString(R.string.app_name)); i.putExtra("app-package", "net.dian1.player"); i.putExtra("state", 0); // state 0 = START - track has started playing i.putExtra("artist", entry.getAlbum().getArtistName()); i.putExtra("track", entry.getMusic().getName()); i.putExtra("duration", entry.getMusic().getDuration()); // duration in seconds i.putExtra("album", entry.getAlbum().getName()); i.putExtra("track-no", entry.getMusic().getNumAlbum()); sendBroadcast(i); } else { // somehow the scrobbling app is not selected properly } } }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private void performSync(Account account, Bundle extras, SyncResult syncResult, AccountSyncResult appSyncResult) { String authtoken = null;/*from w ww . j a v a2 s .co m*/ try { long contactSyncMarker = getContactSyncMarker(account); long contactGroupMarker = getContactGroupSyncMarker(account); SyncAnchor syncAnchor = new SyncAnchor(); if (contactSyncMarker == 0) { // By default, contacts from a 3rd party provider are hidden // in the contacts list. ContactManager.setAccountContactsVisibility(mContext, account, true); // Add Default Group, otherwise group selection is not // visible // in the default editor. ContactManager.ensureSampleGroupExists(mContext, account); } authtoken = NetworkUtilities.blockingGetAuthToken(mAccountManager, account, null); if (authtoken == null) { syncResult.stats.numIoExceptions++; appSyncResult.setState(SyncResultState.AUTH_FAILED); return; } boolean getRestrictions = extras != null ? extras.containsKey(Constants.PARAM_GETRESTRICTIONS) : false; Restrictions restr = SyncUtils.getRestrictions(account, mAccountManager); if (restr == null || getRestrictions) { Restrictions oldRestr = restr; restr = NetworkUtilities.getRestrictions(mContext, account, authtoken, mAccountManager); processRestrictions(oldRestr, restr, account); // Return-Value is not processed because we don't have to // restart for a full sync because all relevant data values will // be read after here. } PrivateKeyState readyState = ClientKeyHelper.isReadyForSync(mContext, account, mAccountManager, authtoken); boolean retryLater = false; switch (readyState) { case AUTH_FAILED: retryLater = true; appSyncResult.setState(SyncResultState.AUTH_FAILED); break; case CHECK_FAILED: // Retry later -> delay sync retryLater = true; appSyncResult.setState(SyncResultState.SERVER_ERROR); break; case NETWORK_ERROR: appSyncResult.setState(SyncResultState.NETWORK_ERROR); appSyncResult.setErrorMsg(readyState.getErrorMsg()); retryLater = true; break; case MISSING_KEY: sendMissingKey(account, authtoken, readyState.getCurrSalt()); appSyncResult.setState(SyncResultState.MISSING_KEY); return; default: clearMissingKeyNotification(account); break; } if (retryLater) { syncResult.delayUntil = SYNC_RETRY_DELAY; syncResult.fullSyncRequested = true; return; } SecretKey privKey = ClientKeyHelper.getOrCreatePrivateKey(account, mAccountManager); authtoken = checkIfSaltSaved(account, authtoken); if (authtoken == null) { syncResult.stats.numIoExceptions++; appSyncResult.setState(SyncResultState.AUTH_FAILED); return; } // Update ClientMod if not already set. ContactManager.updateClientModDate(mContext, account); // Get local Dirty Groups List<ContactGroup> dirtyGroups = ContactManager.getDirtyGroups(mContext, account, restr); boolean syncContacts = true; if (!dirtyGroups.isEmpty()) { // sync only Groups if some new groups are available, to // make // sure, that ids are available for (ContactGroup contactGroup : dirtyGroups) { if (contactGroup.getSourceId() == null) { syncContacts = false; break; } } } syncAnchor.setAnchor(ContactConstants.TYPE_CONTACTGROUP, contactGroupMarker); List<RawContact> dirtyContacts = null; Map<Long, String> newIdMap = null; if (syncContacts) { // Get local Dirty contacts dirtyContacts = ContactManager.getDirtyContacts(mContext, account, restr, new SyncRestConflictHandler(account.name)); newIdMap = ContactManager.getNewIdMap(mContext, account); syncAnchor.setAnchor(ContactConstants.TYPE_CONTACT, contactSyncMarker); } // Send the dirty contacts to the server, and retrieve the // server-side changes String saltStr = ClientKeyHelper.getSalt(account, mAccountManager); boolean explizitPhotoSave = getExplicitSavePhoto(account); SyncResponse result = NetworkUtilities.syncContacts(account, authtoken, syncAnchor, dirtyContacts, dirtyGroups, privKey, mAccountManager, mContext, syncResult, saltStr, newIdMap, restr, explizitPhotoSave); if (result.newGroupIdMap != null && !result.newGroupIdMap.isEmpty()) { if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Calling contactManager's set new GroupIds. Count Updates:" + result.newGroupIdMap.size()); } ContactManager.saveGroupIds(mContext, account.name, result.newGroupIdMap); } if (result.newContactIdMap != null && !result.newContactIdMap.isEmpty()) { if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Calling contactManager's set new ContactIds. Count Updates:" + result.newContactIdMap.size()); } ContactManager.saveContactIds(mContext, account.name, result.newContactIdMap); } Set<Long> updatedGroupIds = null; if (result.serverGroups != null && !result.serverGroups.isEmpty()) { // Update the local groups database with the changes. if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Calling contactManager's update groups. Count Updates:" + result.serverGroups.size()); } updatedGroupIds = ContactManager.updateGroups(mContext, account.name, result.serverGroups); } Set<Long> updatedContactIds = null; if (result.serverContacts != null && !result.serverContacts.isEmpty()) { // Update the local contacts database with the changes. if (Log.isLoggable(TAG, Log.INFO)) { Log.i(TAG, "Calling contactManager's update contacts. Count Updates:" + result.serverContacts.size()); } updatedContactIds = ContactManager.updateContacts(mContext, account.name, result.serverContacts, true, restr); } SyncAnchor newSyncAnchor = result.newServerAnchor; if (newSyncAnchor != null) { setContactSyncMarker(account, newSyncAnchor.getAnchor(ContactConstants.TYPE_CONTACT)); setContactGroupSyncMarker(account, newSyncAnchor.getAnchor(ContactConstants.TYPE_CONTACTGROUP)); } if (result.syncstate != null) { switch (result.syncstate) { case INVALID_KEY: // Reset Key-Info && do FullSync mAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authtoken); ClientKeyHelper.clearPrivateKeyData(account, mAccountManager); ContactManager.setDirtyFlag(mContext, account); setContactSyncMarker(account, FULLSYNC_MARKER); setContactGroupSyncMarker(account, FULLSYNC_MARKER); syncResult.fullSyncRequested = true; appSyncResult.setState(SyncResultState.SUCCESS); return; case FORCE_FULLSYNC: ContactManager.setDirtyFlag(mContext, account); setContactSyncMarker(account, FULLSYNC_MARKER); setContactGroupSyncMarker(account, FULLSYNC_MARKER); syncResult.fullSyncRequested = true; appSyncResult.setState(SyncResultState.SUCCESS); return; default: LogHelper.logI(TAG, "Ignoring unknown SyncState:" + result.syncstate); break; } } boolean resync = processRestrictions(restr, result.restrictions, account); if (resync) { ContactManager.setDirtyFlag(mContext, account); syncResult.fullSyncRequested = true; appSyncResult.setState(SyncResultState.SUCCESS); return; } if (!dirtyGroups.isEmpty()) { ContactManager.clearGroupSyncFlags(mContext, dirtyGroups, result.newGroupIdMap, updatedGroupIds); } if (dirtyContacts != null && !dirtyContacts.isEmpty()) { ContactManager.clearSyncFlags(mContext, dirtyContacts, account.name, result.newContactIdMap, updatedContactIds); } if (newIdMap != null && !newIdMap.isEmpty()) { ContactManager.clearServerId(mContext, newIdMap); } if (!syncContacts) { // if only groups were synced, restart for syncing contacts. syncResult.fullSyncRequested = true; } if (explizitPhotoSave) { // Clear Explizit Flag setExplicitSavePhoto(account, false); } appSyncResult.setState(SyncResultState.SUCCESS); } catch (final AuthenticatorException e) { LogHelper.logE(TAG, "AuthenticatorException", e); syncResult.stats.numParseExceptions++; setPrgErrorMsg(appSyncResult, e); } catch (final OperationCanceledException e) { LogHelper.logI(TAG, "OperationCanceledExcetpion", e); appSyncResult.setState(SyncResultState.AUTH_FAILED); } catch (final IOException e) { LogHelper.logE(TAG, "IOException", e); syncResult.stats.numIoExceptions++; setPrgErrorMsg(appSyncResult, e); } catch (final AuthenticationException e) { LogHelper.logI(TAG, "AuthenticationException", e); syncResult.stats.numAuthExceptions++; appSyncResult.setState(SyncResultState.AUTH_FAILED); } catch (final ParseException e) { LogHelper.logE(TAG, "ParseException", e); syncResult.stats.numParseExceptions++; setPrgErrorMsg(appSyncResult, e); } catch (InvalidKeyException e) { mAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authtoken); ClientKeyHelper.clearPrivateKeyData(account, mAccountManager); LogHelper.logW(TAG, "InvalidKeyException", e); syncResult.stats.numAuthExceptions++; } catch (NetworkErrorException e) { syncResult.stats.numIoExceptions++; LogHelper.logWCause(TAG, "Sync failed because of a NetworkException", e); appSyncResult.setState(SyncResultState.NETWORK_ERROR); appSyncResult.setErrorMsg(String.format(getText(R.string.sync_network_error), e.getLocalizedMessage())); } catch (ServerException e) { syncResult.stats.numIoExceptions++; LogHelper.logWCause(TAG, "Sync failed because of a ServerException", e); appSyncResult.setState(SyncResultState.SERVER_ERROR); appSyncResult.setErrorMsg(getText(R.string.sync_server_error)); } catch (OperationApplicationException e) { LogHelper.logW(TAG, "Sync failed because a DB-Operation failed", e); syncResult.databaseError = true; setPrgErrorMsg(appSyncResult, e); } catch (HeaderParseException e) { syncResult.stats.numIoExceptions++; LogHelper.logWCause(TAG, "Sync failed because of server reponse could not be parsed", e); setPrgErrorMsg(appSyncResult, e); } catch (HeaderCreateException e) { syncResult.databaseError = true; LogHelper.logE(TAG, "Sync failed because header could not be created", e); setPrgErrorMsg(appSyncResult, e); } }
From source file:com.radicaldynamic.groupinform.services.InformOnlineService.java
private void connect(boolean forceOnline) { mConnecting = true;//from ww w . j a v a 2s . c om // Make sure that the user has not specifically requested that we be offline if (Collect.getInstance().getInformOnlineState().isOfflineModeEnabled() && forceOnline == false) { if (Collect.Log.INFO) Log.i(Collect.LOGTAG, t + "offline mode enabled; not auto-connecting"); /* * This is not a complete initialization (in the sense that we attempted connection) but we need * to pretend that it is so that the UI can move forward to whatever state is most suitable. */ mInitialized = true; mConnecting = false; return; } if (Collect.Log.INFO) Log.i(Collect.LOGTAG, t + "pinging " + Collect.getInstance().getInformOnlineState().getServerUrl()); // Try to ping the service to see if it is "up" (and determine whether we are registered) String pingUrl = Collect.getInstance().getInformOnlineState().getServerUrl() + "/ping"; String getResult = HttpUtils.getUrlData(pingUrl); JSONObject ping; try { ping = (JSONObject) new JSONTokener(getResult).nextValue(); String result = ping.optString(InformOnlineState.RESULT, InformOnlineState.ERROR); // Online and registered (checked in) if (result.equals(InformOnlineState.OK)) { if (Collect.Log.INFO) Log.i(Collect.LOGTAG, t + "ping successful (we are connected and checked in)"); mServicePingSuccessful = mSignedIn = true; } else if (result.equals(InformOnlineState.FAILURE)) { if (Collect.Log.WARN) Log.w(Collect.LOGTAG, t + "ping successful but not signed in (will attempt checkin)"); mServicePingSuccessful = true; if (Collect.getInstance().getInformOnlineState().hasRegistration() && checkin()) { if (Collect.Log.INFO) Log.i(Collect.LOGTAG, t + "checkin successful (we are connected)"); // Fetch regardless of the fact that we're not yet marked as being signed in AccountDeviceList.fetchDeviceList(true); AccountFolderList.fetchFolderList(true); mSignedIn = true; } else { if (Collect.Log.WARN) Log.w(Collect.LOGTAG, t + "checkin failed (registration invalid)"); mSignedIn = false; } } else { // Assume offline if (Collect.Log.WARN) Log.w(Collect.LOGTAG, t + "ping failed (we are offline)"); mSignedIn = false; } } catch (NullPointerException e) { // This usually indicates a communication error and will send us into an offline state if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, t + "ping error while communicating with service (we are offline)"); e.printStackTrace(); mServicePingSuccessful = mSignedIn = false; } catch (JSONException e) { // Parse errors (malformed result) send us into an offline state if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, t + "ping error while parsing getResult " + getResult + " (we are offline)"); e.printStackTrace(); mServicePingSuccessful = mSignedIn = false; } finally { // Load regardless of whether we are signed in AccountDeviceList.loadDeviceList(); AccountFolderList.loadFolderList(); // Unblock mInitialized = true; mConnecting = false; } }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private Observable<File> createIfNotExists() { return Observable.just(toImageFileName()).flatMap(fileName -> { if (view.isAvailable()) { try { final Context context = view.getContext(); File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); File temp = new File(storageDir, fileName + FILE_EXTENSION); boolean success = temp.createNewFile(); if (success) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp created", temp.getName())); }//w ww . ja va 2 s . com return Observable.just(temp); } catch (IOException ioError) { throw new AndroidException(ioError); } } return Observable.empty(); }); }
From source file:com.radicaldynamic.groupinform.services.DatabaseService.java
synchronized public ReplicationStatus replicate(String db, int mode) { final String tt = t + "replicate(): "; if (Collect.Log.DEBUG) Log.d(Collect.LOGTAG, tt + "about to replicate " + db); // Will not replicate unless signed in if (!Collect.getInstance().getIoService().isSignedIn()) { if (Collect.Log.DEBUG) Log.d(Collect.LOGTAG, tt + "aborting replication: not signed in"); return null; }/*from w w w. ja v a 2 s . c o m*/ if (Collect.getInstance().getInformOnlineState().isOfflineModeEnabled()) { if (Collect.Log.DEBUG) Log.d(Collect.LOGTAG, tt + "aborting replication: offline mode is enabled"); return null; } /* * Lookup master cluster by IP. Do this instead of relying on Erlang's internal resolver * (and thus Google's public DNS). Our builds of Erlang for Android do not yet use * Android's native DNS resolver. */ String masterClusterIP = null; try { InetAddress[] clusterInetAddresses = InetAddress .getAllByName(getString(R.string.tf_default_ionline_server)); masterClusterIP = clusterInetAddresses[new Random().nextInt(clusterInetAddresses.length)] .getHostAddress(); } catch (UnknownHostException e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "unable to lookup master cluster IP addresses: " + e.toString()); e.printStackTrace(); } // Create local instance of database boolean dbCreated = false; // User may not have connected to local database yet - start up the connection for them try { if (mLocalDbInstance == null) { connectToLocalServer(); } } catch (DbUnavailableException e) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, tt + "cannot connect to local database server"); e.printStackTrace(); } if (mLocalDbInstance.getAllDatabases().indexOf("db_" + db) == -1) { switch (mode) { case REPLICATE_PULL: if (Collect.Log.INFO) Log.i(Collect.LOGTAG, tt + "creating local database " + db); mLocalDbInstance.createDatabase("db_" + db); dbCreated = true; break; case REPLICATE_PUSH: // If the database does not exist client side then there is no point in continuing if (Collect.Log.WARN) Log.w(Collect.LOGTAG, tt + "cannot find local database " + db + " to push"); return null; } } // Configure replication direction String source = null; String target = null; String deviceId = Collect.getInstance().getInformOnlineState().getDeviceId(); String deviceKey = Collect.getInstance().getInformOnlineState().getDeviceKey(); String localServer = "http://" + mLocalHost + ":" + mLocalPort + "/db_" + db; String remoteServer = "http://" + deviceId + ":" + deviceKey + "@" + masterClusterIP + ":5984/db_" + db; // Should we use encrypted transfers? SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(Collect.getInstance().getBaseContext()); if (settings.getBoolean(PreferencesActivity.KEY_ENCRYPT_SYNCHRONIZATION, true)) { remoteServer = "https://" + deviceId + ":" + deviceKey + "@" + masterClusterIP + ":6984/db_" + db; } switch (mode) { case REPLICATE_PUSH: source = localServer; target = remoteServer; break; case REPLICATE_PULL: source = remoteServer; target = localServer; break; } ReplicationCommand cmd = new ReplicationCommand.Builder().source(source).target(target).build(); ReplicationStatus status = null; try { status = mLocalDbInstance.replicate(cmd); } catch (Exception e) { // Remove a recently created DB if the replication failed if (dbCreated) { if (Collect.Log.ERROR) Log.e(Collect.LOGTAG, t + "replication exception: " + e.toString()); e.printStackTrace(); mLocalDbInstance.deleteDatabase("db_" + db); } } return status; }
From source file:com.irccloud.android.HTTPFetcher.java
private void http_thread() { try {//ww w. j a v a2 s . c om mThread.setName("http-stream-thread"); int port = (mURI.getPort() != -1) ? mURI.getPort() : (mURI.getProtocol().equals("https") ? 443 : 80); String path = TextUtils.isEmpty(mURI.getPath()) ? "/" : mURI.getPath(); if (!TextUtils.isEmpty(mURI.getQuery())) { path += "?" + mURI.getQuery(); } PrintWriter out = new PrintWriter(mSocket.getOutputStream()); if (mProxyHost != null && mProxyHost.length() > 0 && mProxyPort > 0) { out.print("CONNECT " + mURI.getHost() + ":" + port + " HTTP/1.0\r\n"); out.print("\r\n"); out.flush(); HybiParser.HappyDataInputStream stream = new HybiParser.HappyDataInputStream( mSocket.getInputStream()); // Read HTTP response status line. StatusLine statusLine = parseStatusLine(readLine(stream)); if (statusLine == null) { throw new HttpException("Received no reply from server."); } else if (statusLine.getStatusCode() != HttpStatus.SC_OK) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } // Read HTTP response headers. while (!TextUtils.isEmpty(readLine(stream))) ; if (mURI.getProtocol().equals("https")) { mSocket = getSSLSocketFactory().createSocket(mSocket, mURI.getHost(), port, false); SSLSocket s = (SSLSocket) mSocket; try { s.setEnabledProtocols(ENABLED_PROTOCOLS); } catch (IllegalArgumentException e) { //Not supported on older Android versions } try { s.setEnabledCipherSuites(ENABLED_CIPHERS); } catch (IllegalArgumentException e) { //Not supported on older Android versions } out = new PrintWriter(mSocket.getOutputStream()); } } if (mURI.getProtocol().equals("https")) { SSLSocket s = (SSLSocket) mSocket; StrictHostnameVerifier verifier = new StrictHostnameVerifier(); if (!verifier.verify(mURI.getHost(), s.getSession())) throw new SSLException("Hostname mismatch"); } Crashlytics.log(Log.DEBUG, TAG, "Sending HTTP request"); out.print("GET " + path + " HTTP/1.0\r\n"); out.print("Host: " + mURI.getHost() + "\r\n"); if (mURI.getHost().equals(NetworkConnection.IRCCLOUD_HOST) && NetworkConnection.getInstance().session != null && NetworkConnection.getInstance().session.length() > 0) out.print("Cookie: session=" + NetworkConnection.getInstance().session + "\r\n"); out.print("Connection: close\r\n"); out.print("Accept-Encoding: gzip\r\n"); out.print("User-Agent: " + NetworkConnection.getInstance().useragent + "\r\n"); out.print("\r\n"); out.flush(); HybiParser.HappyDataInputStream stream = new HybiParser.HappyDataInputStream(mSocket.getInputStream()); // Read HTTP response status line. StatusLine statusLine = parseStatusLine(readLine(stream)); if (statusLine != null) Crashlytics.log(Log.DEBUG, TAG, "Got HTTP response: " + statusLine); if (statusLine == null) { throw new HttpException("Received no reply from server."); } else if (statusLine.getStatusCode() != HttpStatus.SC_OK && statusLine.getStatusCode() != HttpStatus.SC_MOVED_PERMANENTLY) { Crashlytics.log(Log.ERROR, TAG, "Failure: " + mURI + ": " + statusLine.getStatusCode() + " " + statusLine.getReasonPhrase()); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } // Read HTTP response headers. String line; boolean gzipped = false; while (!TextUtils.isEmpty(line = readLine(stream))) { Header header = parseHeader(line); if (header.getName().equalsIgnoreCase("content-encoding") && header.getValue().equalsIgnoreCase("gzip")) gzipped = true; if (statusLine.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY && header.getName().equalsIgnoreCase("location")) { Crashlytics.log(Log.INFO, TAG, "Redirecting to: " + header.getValue()); mURI = new URL(header.getValue()); mSocket.close(); mSocket = null; mThread = null; connect(); return; } } if (gzipped) onStreamConnected(new GZIPInputStream(mSocket.getInputStream())); else onStreamConnected(mSocket.getInputStream()); onFetchComplete(); } catch (Exception ex) { NetworkConnection.printStackTraceToCrashlytics(ex); onFetchFailed(); } }
From source file:biz.bokhorst.xprivacy.Util.java
public static boolean isProEnablerInstalled(Context context) { Version version = getProEnablerVersion(context); if (version != null && isValidProEnablerVersion(version) && hasValidProEnablerSignature(context)) { Util.log(null, Log.INFO, "Licensing: enabler installed"); return true; }//from w w w .j a v a2 s.c om Util.log(null, Log.INFO, "Licensing: enabler not installed"); return false; }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
private void dispatchTakePictureIntent() { createIfNotExists().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(file -> {//from w w w. j ava 2s . com if (file.exists()) { log(Log.INFO, String.format(Locale.ENGLISH, "%s is temp file.", file.getAbsolutePath())); } if (view.isAvailable()) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(view.getContext().getPackageManager()) != null) { this.tempTakenPhoto = file;//set it in property Uri uri = FileProvider.getUriForFile(view.getContext(), GRANT_PERMISSION, file); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); //fileProvider requires gran permission to others access that uri if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { final Context context = view.getContext(); List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (infos != null) { StreamSupport.stream(infos).filter(x -> x.activityInfo != null) .map(x -> x.activityInfo.packageName).forEach(pack -> { context.grantUriPermission(pack, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); }); } } view.startActivityForResult(intent, REQUEST_TAKE_PHOTO); } else { view.showError("You need to install app that can capture photo."); } } }, this::log); }
From source file:com.cbsb.ftpserv.ProxyConnector.java
/** * Reads our persistent storage, looking for a stored proxy authentication secret. * @return The secret, if present, or null. *//*from www.j a v a 2 s .com*/ //Obsolete, there's no authentication anymore /*private String retrieveSecret() { SharedPreferences settings = Globals.getContext(). getSharedPreferences(Defaults.getSettingsName(), Defaults.getSettingsMode()); return settings.getString("proxySecret", null); }*/ //Obsolete, there's no authentication anymore /*private void storeSecret(String secret) { SharedPreferences settings = Globals.getContext(). getSharedPreferences(Defaults.getSettingsName(), Defaults.getSettingsMode()); Editor editor = settings.edit(); editor.putString("proxySecret", secret); editor.commit(); }*/ //Obsolete, there's no authentication anymore /*private void removeSecret() { SharedPreferences settings = Globals.getContext(). getSharedPreferences(Defaults.getSettingsName(), Defaults.getSettingsMode()); Editor editor = settings.edit(); editor.remove("proxySecret"); editor.commit(); }*/ private void incomingCommand(JSONObject json) { try { String action = json.getString("action"); if (action.equals("control_connection_waiting")) { startControlSession(json.getInt("port")); } else if (action.equals("prefer_server")) { String host = json.getString("host"); // throws JSONException, fine preferServer(host); myLog.i("New preferred server: " + host); } else if (action.equals("message")) { proxyMessage = json.getString("text"); myLog.i("Got news from proxy server: \"" + proxyMessage + "\""); FTPServerService.updateClients(); // UI update to show message } else if (action.equals("noop")) { myLog.d("Proxy noop"); } else { myLog.l(Log.INFO, "Unsupported incoming action: " + action); } // If we're starting a control session register with ftpServerService } catch (JSONException e) { myLog.l(Log.INFO, "JSONException in proxy incomingCommand"); } }
From source file:org.swiftp.server.ProxyConnector.java
/** * Reads our persistent storage, looking for a stored proxy authentication secret. * /*ww w . j a va 2 s . c om*/ * @return The secret, if present, or null. */ // Obsolete, there's no authentication anymore /* * private String retrieveSecret() { SharedPreferences settings = * Globals.getContext(). getSharedPreferences(Defaults.getSettingsName(), * Defaults.getSettingsMode()); return settings.getString("proxySecret", null); } */ // Obsolete, there's no authentication anymore /* * private void storeSecret(String secret) { SharedPreferences settings = * Globals.getContext(). getSharedPreferences(Defaults.getSettingsName(), * Defaults.getSettingsMode()); Editor editor = settings.edit(); * editor.putString("proxySecret", secret); editor.commit(); } */ // Obsolete, there's no authentication anymore /* * private void removeSecret() { SharedPreferences settings = Globals.getContext(). * getSharedPreferences(Defaults.getSettingsName(), Defaults.getSettingsMode()); * Editor editor = settings.edit(); editor.remove("proxySecret"); editor.commit(); } */ private void incomingCommand(JSONObject json) { try { String action = json.getString("action"); if (action.equals("control_connection_waiting")) { startControlSession(json.getInt("port")); } else if (action.equals("prefer_server")) { String host = json.getString("host"); // throws JSONException, fine preferServer(host); myLog.i("New preferred server: " + host); } else if (action.equals("message")) { proxyMessage = json.getString("text"); myLog.i("Got news from proxy server: \"" + proxyMessage + "\""); // TODO: send intent to notify UI about news // FTPServerService.updateClients(); // UI update to show message } else if (action.equals("noop")) { myLog.d("Proxy noop"); } else { myLog.l(Log.INFO, "Unsupported incoming action: " + action); } // If we're starting a control session register with ftpServerService } catch (JSONException e) { myLog.l(Log.INFO, "JSONException in proxy incomingCommand"); } }