Skip to content

Instantly share code, notes, and snippets.

Matthew Morrone matthewmorrone

Block or report user

Report or block matthewmorrone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View isTablet.java
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
@matthewmorrone
matthewmorrone / info.java
Created Nov 12, 2019
Show Android device name, model, version code, version name
View info.java
String device = Build.BRAND + " " + android.os.Build.MODEL;
String osInt = "Android " + android.os.Build.VERSION.SDK_INT;
String osRelease = "Android " + Build.VERSION.RELEASE;
Log.e("TAG", "Device: " + device + " " + osInt + " - " + osRelease);
@matthewmorrone
matthewmorrone / alert.java
Created Nov 12, 2019
show alert dialog from anywhere
View alert.java
new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.dialog_title))
.setMessage(getString(R.string.dialog_text))
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// OK clicked
}
})
View getInputStreamFromUrl.java
public static InputStream getInputStreamFromUrl(String url) {
InputStream content = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
content = response.getEntity().getContent();
} catch (Exception e) {
Log.("[GET REQUEST]", "Network exception", e);
}
return content;
View toggle-orientation.java
public void setOrientation(boolean status) {
if (status) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}
}
// In AndroidManifest.xml just add android:screenOrientation="portrait"
// <activity android:name=".MyActivity" android:label="@string/app_name" android:screenOrientation="portrait">
View prevent-suggestions.java
EditText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
View getInstalledApps.java
class PInfo {
private String appname = "";
private String pname = "";
private String versionName = "";
private int versionCode = 0;
private Drawable icon;
private void prettyPrint() {
Log.v(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}
}
View scan-wifi.java
package com.android.wifitester;
import java.util.List;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
View get-gps.java
private double[] getGPS() {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
List<String> providers = lm.getProviders(true);
/* Loop over the array backwards, and if you get an accurate location, then break out the loop*/
Location l = null;
for (int i=providers.size()-1; i>=0; i--) {
l = lm.getLastKnownLocation(providers.get(i));
if (l != null) break;
View file-open.java
File myFile = new File("your any type of file url");
FileOpen.openFile(mContext, myFile);
public class FileOpen {
public static void openFile(Context context, File url) throws IOException {
// Create URI
File file=url;
Uri uri = Uri.fromFile(file);
You can’t perform that action at this time.