Skip to content

Instantly share code, notes, and snippets.

@emil2k
emil2k / Connectivity.java
Last active December 22, 2023 06:03
Android utility class for checking device's network connectivity and speed.
/*
* Copyright (c) 2017 Emil Davtyan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@granoeste
granoeste / EachDirectoryPath.md
Last active May 31, 2024 10:47
[Android] How to get the each directory path.

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@binjoo
binjoo / default.java
Created May 27, 2013 08:58
JAVA:清除HTML标签
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HTMLSpirit{
public static String delHTMLTag(String htmlStr){
String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
@swankjesse
swankjesse / RetrofitCachingExample.java
Created June 29, 2013 03:03
Demonstrate HTTP caching with OkHttp and Retrofit.
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@kristopherjohnson
kristopherjohnson / showForegroundNotification.java
Last active June 21, 2022 13:41
Shows a foreground notification for an Android service. Tapping the notification will display the app as if it was tapped in application launcher
private static final int NOTIFICATION_ID = 1;
private void showForegroundNotification(String contentText) {
// Create intent that will bring our app to the front, as if it was tapped in the app
// launcher
Intent showTaskIntent = new Intent(getApplicationContext(), MyMainActivity.class);
showTaskIntent.setAction(Intent.ACTION_MAIN);
showTaskIntent.addCategory(Intent.CATEGORY_LAUNCHER);
showTaskIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@scottyab
scottyab / SignatureCheck.java
Last active June 5, 2024 11:36
Simple Android signature check. Please note: This was created in 2013, not actively maintained and may not be compatible with the latest Android versions. It's not particularly difficult for an attacker to decompile an .apk, find this tamper check, replace the APP_SIGNATURE with theirs and rebuild (or use method hooking to return true from `vali…
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
public class TamperCheck {
//we store the hash of the signture for a little more protection
private static final String APP_SIGNATURE = "1038C0E34658923C4192E61B16846";
@dmarcato
dmarcato / Main.java
Last active May 21, 2020 10:25
De/Serialization of generic SparseArray using Gson library
import android.util.SparseArray;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
public class Main {
public static class MyCustomClass {
public int a;
@daichan4649
daichan4649 / MainActivity.java
Last active August 26, 2016 08:50
プログレス表示(IllegalStateException: Can not perform this action after onSaveInstanceState 対策済)
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.execute).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@studiawan
studiawan / urllib-bsoup.py
Created December 16, 2013 05:09
HTTP client using urllib2 & beautifulsoup parser
# get short tutorial here: http://www.pythonforbeginners.com/python-on-the-web/beautifulsoup-4-python/
import urllib2
from bs4 import BeautifulSoup
response = urllib2.urlopen('http://www.studiawan.com').read()
soup = BeautifulSoup(response)
print soup.title.string
print soup.get_text()
@dustin-graham
dustin-graham / RainEmployeeProvider.java
Created February 22, 2014 00:09
An example Android ContentProvider
package com.rain.example.data.provider;
import com.rain.example.data.database.RainEmployeeDatabase;
import com.rain.example.data.database.table.*;
import android.provider.BaseColumns;
import android.text.TextUtils;
import android.content.ContentUris;
import android.database.sqlite.SQLiteQueryBuilder;