Skip to content

Instantly share code, notes, and snippets.

@varunon9
varunon9 / AlwaysRunningAndroidService.md
Last active October 16, 2024 13:19
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
@colesnicov
colesnicov / ftoa.c
Last active September 22, 2023 11:25
Float to string conversion for AVR's devices and over embedded MCU's..
/**
* @Licence WTFPL
*/
#include "ftoa.h"
int ftoa(float f, char *p, uint8_t precision)
{
typedef union
@PasanBhanu
PasanBhanu / AndroidDownloadImage.java
Created September 26, 2019 09:04
Download Image from URL and Added to Gallery - Android (Java)
/*
This method can be used to download an image from the internet using a url in Android. This use Android Download Manager to
download the file and added it to the Gallery. Downloaded image will be saved to "Pictures"
Folder in your internal storage
*/
private void downloadImageNew(String filename, String downloadUrlOfImage){
try{
DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(downloadUrlOfImage);
@abdurrahmanekr
abdurrahmanekr / gist:2747d704edec93a06e454eba2653e0df
Last active September 26, 2024 14:48
WhatsApp original chat background image

WhatsApp original chat background image

WhatsApp original darkmoda background image

@FrantisekGazo
FrantisekGazo / StatefulRecyclerView.java
Last active November 10, 2024 22:57
Retain & restore recycler view scroll position
package eu.f3rog.ui.custom;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
/**
@lopspower
lopspower / README.md
Last active August 16, 2024 15:51
All Android Directory Path

All Android Directory Path

Twitter

1) System directories

⚠️ We can't write to these folers

Method Result
@liu7yong
liu7yong / WifiConnection.java
Last active November 7, 2021 14:45
How to connect to a specific wifi network in Android programmatically?
WifiConfiguration wifiConfig = new WifiConfiguration();
wifiConfig.SSID = String.format("\"%s\"", ssid);
wifiConfig.preSharedKey = String.format("\"%s\"", key);
WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
//remember id
int netId = wifiManager.addNetwork(wifiConfig);
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
@grantland
grantland / post.md
Last active February 9, 2023 05:09
RecyclerView item onClick

RecyclerView item onClick

RecyclerView does not have an OnItemClickListener like it's predecessor, ListView. However, detecting item clicks is pretty simple.

Set an OnClickListener in your ViewHolder creation:

private class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {

    public static class ViewHolder extends RecyclerView.ViewHolder
@vinigracindo
vinigracindo / gist:5388567
Created April 15, 2013 14:37
Android Download Image from URL
package utils;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
@codeswimmer
codeswimmer / Android.Bitmap.Rotate
Created March 7, 2011 17:25
Android: rotate a bitmap
public Bitmap rotateBitmap(Bitmap original, float degrees) {
int width = original.getWidth();
int height = original.getHeight();
Matrix matrix = new Matrix();
matrix.preRotate(degrees);
Bitmap rotatedBitmap = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true);
Canvas canvas = new Canvas(rotatedBitmap);
canvas.drawBitmap(original, 5.0f, 0.0f, null);