try { String[] reboot = new String[] { "su", "-c", "reboot" }; //-c will cause the next argument to be treated as a command Process process = Runtime.getRuntime().exec(reboot); process.waitFor(); //wait for the native process to finish executing. } catch (Exception e) { Toast.makeText(getApplicationContext()," Device not rooted.\n Could not reboot...",Toast.LENGTH_SHORT).show(); }
su
command, the application starts with privileged rights, and if the device is ruled, it will restart. If not, a message appears:<uses-permission android:name="android.permission.ACCESS_SUPERUSER">
<uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CALENDAR"></uses-permission>
<uses-permission android:name="android.permission.READ_CALL_LOG"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
String message = "Hello Android fans! "; String number = "xxxxxxxxxxxx"; //it is preferable to use a complete international number SmsManager.getDefault().sendTextMessage(number, null, message, null, null);
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
public class MainActivity extends Activity implements LocationListener { private LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, this); } @Override public void onLocationChanged(Location location) { String myLocation ="Location changed...\n\nYou are located at: " + "\nLatitude: " + location.getLatitude() + "\nLongitude: " + location.getLongitude(); Toast.makeText(getApplicationContext(), myLocation, Toast.LENGTH_LONG).show(); } @Override public void onProviderDisabled(String provider) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); Toast.makeText(getApplicationContext(), "Gps is turned off... ", Toast.LENGTH_SHORT).show(); } @Override public void onProviderEnabled(String provider) { Toast.makeText(getApplicationContext(), "Gps is turned on... ", Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }
MainActivity
class implements LocationListener
to get the right data from the device. The current location is requestLocationUpdates()
by calling requestLocationUpdates()
in the onCreate()
method. When a location changes, onLocationChanged()
is called to get new data. If the GPS data is not available, the onProviderDisabled () method is called, passing the location information to the application.<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"></uses-permission>
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<permission android:name="android.permission.INSTALL_PACKAGES">
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"></uses-permission>
Source: https://habr.com/ru/post/268219/
All Articles