hosseinaryai
جمعه 19 تیر 1394, 19:15 عصر
با درود خدمت دوستان
خب دقیقن سوالم همینه .. چطور می تونم GPS گوشیو روشن و خاموش کنم ؟
یه کد گیر آوردم که در زیر می ذارم ، دوتا متده واسه روشن و خاموش کردن اما کار نمی کنن ، کجای کار داره می لنگه یعنی ؟
public static void turnGPSOn(Context context){
String provider = Settings.Secure.getString
(context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvi der");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
}
}
public static void turnGPSOff(Context context){
String provider = Settings.Secure.getString
(context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){ //if gps is enabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvi der");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
}
}
خب دقیقن سوالم همینه .. چطور می تونم GPS گوشیو روشن و خاموش کنم ؟
یه کد گیر آوردم که در زیر می ذارم ، دوتا متده واسه روشن و خاموش کردن اما کار نمی کنن ، کجای کار داره می لنگه یعنی ؟
public static void turnGPSOn(Context context){
String provider = Settings.Secure.getString
(context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.contains("gps")){ //if gps is disabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvi der");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
}
}
public static void turnGPSOff(Context context){
String provider = Settings.Secure.getString
(context.getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){ //if gps is enabled
final Intent poke = new Intent();
poke.setClassName("com.android.settings",
"com.android.settings.widget.SettingsAppWidgetProvi der");
poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
poke.setData(Uri.parse("3"));
context.sendBroadcast(poke);
}
}