android-1.5-cupcake

How do I find out if the GPS of an Android device is enabled

会有一股神秘感。 提交于 2019-11-25 23:33:31
问题 On an Android Cupcake (1.5) enabled device, how do I check and activate the GPS? 回答1: Best way seems to be the following: final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE ); if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) { buildAlertMessageNoGps(); } private void buildAlertMessageNoGps() { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Your GPS seems to be disabled, do you want to enable it?

Android: How to use AlarmManager

橙三吉。 提交于 2019-11-25 22:46:20
问题 I need to trigger a block of code after 20 minutes from the AlarmManager being set. Can someone show me sample code on how to use an AlarmManager in ِAndroid? I have been playing around with some code for a few days and it just won\'t work. 回答1: "Some sample code" is not that easy when it comes to AlarmManager . Here is a snippet showing the setup of AlarmManager : AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i=new Intent(context, OnAlarmReceiver