Skip to content

Instantly share code, notes, and snippets.

@varunon9
varunon9 / AlwaysRunningAndroidService.md
Last active April 20, 2024 23:38
How to create an always running service in Android

Full Source Code: https://github.com/varunon9/DynamicWallpaper/tree/always_running_service

Steps-

  1. Create a Foreground Service (MyService.java)
  2. Create a Manifest registered Broadcast Receiver (MyReceiver.java) which will start your Foreground Service
  3. In onDestroy lifecycle of MyService, send a broadcast intent to MyReceiver
  4. Launch the MyService on app start from MainActivity (see step 8)
  5. With above 4 steps, MyService will always get re-started when killed as long as onDestroy of Service gets called
  6. onDestroy method of Service is not always guaranteed to be called and hence it might not get started again
#facebook marketplace
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from pymongo import MongoClient
class App:
@DusanMadar
DusanMadar / TorPrivoxyPython.md
Last active May 28, 2024 22:51
A step-by-step guide how to use Python with Tor and Privoxy

A step-by-step guide how to use Python with Tor and Privoxy

Latest revision: 2021-12-05.

Tested on Ubuntu 18.04 Docker container. The Dockerfile is a single line FROM ubuntu:18.04. Alternatively, you can simply run docker run -it ubuntu:18.04 bash.

NOTE: stopping services didn't work for me for some reason. That's why there is kill $(pidof <service name>) after each failed service <service name> stop to kill it.

References

@emaillenin
emaillenin / DownloadManagerActivity.java
Created December 11, 2016 04:54
Download APK using DownloadManager and start installation automatically - Android 7.0 Nougat compatible
public void downloadUpdate() {
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
String fileName = "your_app.apk";
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
File file = new File(destination);
if (file.exists())
file.delete();