This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Way one */ | |
android.os.Process.killProcess(android.os.Process.myPid()) | |
/* Way Two */ | |
System.exit(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); | |
wifi.setWifiEnabled(enabled); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*@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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Present you with the dialler | |
Code: Select all | |
Uri telUri = Uri.parse("tel:100861"); | |
returnIt = new Intent(Intent.ACTION_DIAL, telUri); | |
// Start the call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getMyNumber(){ | |
TelephonyManager mTelephonyMgr; | |
mTelephonyMgr = (TelephonyManager) | |
getSystemService(Context.TELEPHONY_SERVICE); | |
return mTelephonyMgr.getLine1Number(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private double gps2m(float lat_a, float lng_a, float lat_b, float lng_b) { | |
float pk = (float) (180/3.14169); | |
float a1 = lat_a / pk; | |
float a2 = lng_a / pk; | |
float b1 = lat_b / pk; | |
float b2 = lng_b / pk; | |
float t1 = FloatMath.cos(a1)*FloatMath.cos(a2)*FloatMath.cos(b1)*FloatMath.cos(b2); | |
float t2 = FloatMath.cos(a1)*FloatMath.sin(a2)*FloatMath.cos(b1)*FloatMath.sin(b2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Basic contact information stored in Contacts table with detailed information stored in individual //tables for normalization. In Android 2.0 to query the base contact records the URI to query is stored //in ContactsContract.Contacts.CONTENT_URI. | |
ContentResolver cr = getContentResolver(); | |
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, | |
null, null, null, null); | |
if (cur.getCount() > 0) { | |
while (cur.moveToNext()) { | |
String id = cur.getString( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//retrieving phone numbers | |
//Phone numbers are stored in their own table and need to be queried separately. To query the phone //number table use the URI stored in the SDK variable ContactsContract.CommonDataKinds.Phone.CONTENT_URI. //Use a WHERE conditional to get the phone numbers for the specified contact. | |
if (Integer.parseInt(cur.getString( | |
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { | |
Cursor pCur = cr.query( | |
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, | |
null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", | |
new String[]{id}, null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Querying email addresses is similar to phone numbers. A query must be performed to get email addresses //from the database. Query the URI stored in ContactsContract.CommonDataKinds.Email.CONTENT_URI to query the //email address table. | |
Cursor emailCur = cr.query( | |
ContactsContract.CommonDataKinds.Email.CONTENT_URI, | |
null,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", | |
new String[]{id}, null); | |
while (emailCur.moveToNext()) { | |
// This would allow you get several email addresses | |
// if the email addresses were stored in an array |