public class MyService extends Service {
final String CHECK_STEP_KEY = "steps_key";
private double magLast = 0;
static int stepsCheck = -1;
private TextView steps;
final String TAG = "myLog";
public MyService() {
}
public void onCreate(){
super.onCreate();
Log.d(TAG, "onCreate");
}
public int onStartCommand(Intent intent, int flags, int startId){
Log.d(TAG, "onStartCommand ");
SharedPreferences sPref = getSharedPreferences("MyPref", MODE_PRIVATE);
stepsCheck = sPref.getInt(CHECK_STEP_KEY, 0);
SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
SensorEventListener stepDetector = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent != null) {
double dx = sensorEvent.values[0];
double dy = sensorEvent.values[1];
double dz = sensorEvent.values[2];
double mag = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (mag - magLast > 4) {
SharedPreferences sPref = getSharedPreferences("MyPref", MODE_PRIVATE);
SharedPreferences.Editor myEditor = sPref.edit();
myEditor.putInt(CHECK_STEP_KEY, stepsCheck);
myEditor.commit();
stepsCheck++;
Log.d(TAG, String.valueOf(stepsCheck));
myEditor.putInt(CHECK_STEP_KEY, stepsCheck);
}
magLast = mag;
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
sensorManager.registerListener(stepDetector,sensor,sensorManager.SENSOR_DELAY_NORMAL);
return super.onStartCommand(intent, flags, startId);
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}
package com.example.serviss;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private TextView steps;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, MyService.class);
startService(intent);
steps = findViewById(R.id.steps);
steps.setText(String.valueOf(MyService.stepsCheck));
Toast.makeText(MainActivity.this, String.valueOf(MyService.stepsCheck), Toast.LENGTH_SHORT).show();
}
}
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# instance of Options class allows
# us to configure Headless Chrome
options = Options()
# this parameter tells Chrome that
# it should be run without UI (Headless)
options.headless = True
# initializing webdriver for Chrome with our options
driver = webdriver.Chrome('C:\\Users\\maksi\\PycharmProjects\\testBot\\chromedriver.exe')
# getting GeekForGeeks webpage
driver.get('https://ru.tradingview.com/chart/?symbol=KUCOIN%3ABTCUSDT')
# We can also get some information
# about page in browser.
# So let's output webpage title into
# terminal to be sure that the browser
# is actually running.
print(driver.title)
# close browser after our manipulations
driver.close()
Warning (from warnings module):
File "C:\Users\maksi\Desktop\vepsrf.py", line 13
driver = webdriver.Chrome('C:\\Users\\maksi\\PycharmProjects\\testBot\\chromedriver.exe')
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
Traceback (most recent call last):
File "C:\Users\maksi\Desktop\vepsrf.py", line 13, in
driver = webdriver.Chrome('C:\\Users\\maksi\\PycharmProjects\\testBot\\chromedriver.exe')
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in init
super().init(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in init
super().init(
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 277, in init
self.start_session(capabilities, browser_profile)
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 370, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
self.error_handler.check_response(response)
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Stacktrace:
Backtrace:
Ordinal0 [0x00E48823+2197539]
Ordinal0 [0x00DE0911+1771793]
Ordinal0 [0x00CF3FE8+802792]
Ordinal0 [0x00D1063B+919099]
Ordinal0 [0x00D0EA51+911953]
Ordinal0 [0x00D42260+1122912]
Ordinal0 [0x00D41EBA+1121978]
Ordinal0 [0x00D3D476+1102966]
Ordinal0 [0x00D17660+947808]
Ordinal0 [0x00D18556+951638]
GetHandleVerifier [0x010F1A32+2740578]
GetHandleVerifier [0x010E3776+2682534]
GetHandleVerifier [0x00ED307A+518058]
GetHandleVerifier [0x00ED2196+514246]
Ordinal0 [0x00DE7ADB+1800923]
Ordinal0 [0x00DEC2E8+1819368]
Ordinal0 [0x00DEC3D5+1819605]
Ordinal0 [0x00DF5810+1857552]
BaseThreadInitThunk [0x76C1FA29+25]
RtlGetAppContainerNamedObjectPath [0x76F37A9E+286]
RtlGetAppContainerNamedObjectPath [0x76F37A6E+238]
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# instance of Options class allows
# us to configure Headless Chrome
options = Options()
# this parameter tells Chrome that
# it should be run without UI (Headless)
options.headless = True
# initializing webdriver for Chrome with our options
driver = webdriver.Chrome(options=options)
# getting GeekForGeeks webpage
driver.get('https://ru.tradingview.com/chart/?symbol=KUCOIN%3ABTCUSDT')
# We can also get some information
# about page in browser.
# So let's output webpage title into
# terminal to be sure that the browser
# is actually running.
print(driver.title)
# close browser after our manipulations
driver.close()
Traceback (most recent call last):
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\subprocess.py", line 969, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Не удается найти указанный файл
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\maksi\Desktop\vepsrf.py", line 13, in
driver = webdriver.Chrome(options=options)
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in init
super().init(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in init
self.service.start()
File "C:\Users\maksi\AppData\Local\Programs\Python\Python310-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home