Skip to content

Instantly share code, notes, and snippets.

View mstefanko's full-sized avatar

Mike Stefanko mstefanko

View GitHub Profile
@mstefanko
mstefanko / gist:890441
Created March 28, 2011 13:26
Call a given number using Android Intent
//Present you with the dialler
Code: Select all
Uri telUri = Uri.parse("tel:100861");
returnIt = new Intent(Intent.ACTION_DIAL, telUri);
// Start the call
@mstefanko
mstefanko / gist:890440
Created March 28, 2011 13:25
Can app access internet
*@return boolean return true if the application can access the internet
*/
private boolean haveInternet(){
NetworkInfo info=(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo();
if(info==null || !info.isConnected()){
return false;
}
if(info.isRoaming()){
//here is the roaming option you can change it if you want to disable internet while roaming, just return false
return true;
@mstefanko
mstefanko / Android
Created March 28, 2011 13:25
Enable/disable wifi
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(enabled);
@mstefanko
mstefanko / Kill android app
Created March 28, 2011 13:23
Kill Android app
/* Way one */
android.os.Process.killProcess(android.os.Process.myPid())
/* Way Two */
System.exit(0);
@mstefanko
mstefanko / read .txt file
Created March 28, 2011 13:23
read .txt file from android
try{
File f = new File(Environment.getExternalStorageDirectory()+"/myFile.txt");
fileIS = new FileInputStream(f);
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
//just reading each line and pass it on the debugger
@mstefanko
mstefanko / Get tilt from accelerometer values
Created March 28, 2011 13:21
Get tilt from accelerometer values
double accX = -x/SensorManager.GRAVITY_EARTH;
double accY = -y/SensorManager.GRAVITY_EARTH;
double accZ = z/SensorManager.GRAVITY_EARTH;
double totAcc = Math.sqrt((accX*accX)+(accY*accY)+(accZ*accZ));
double tiltX = Math.asin(accX/totAcc);
double tiltY = Math.asin(accY/totAcc);
double tiltZ = Math.asin(accZ/totAcc);
@mstefanko
mstefanko / Calculate android screen size
Created March 28, 2011 13:15
calculates android screen size
Display display;
display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int height = display.getHeight();
int width = display.getWidth();
@mstefanko
mstefanko / Hide the status bar and title bar
Created March 28, 2011 13:00
Hide the status bar and title bar
//for hide the status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//hide the title bar