0

Android アプリの 1 つで大量のバッテリー消費が発生しています。これは、GPS がオンになっているが、新しいアクティビティが開始されてもオフにならないことが原因であると考えています。他の誰かから継承したコード ベースを使用しています。この問題の解決策があれば教えてください。

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Start the tracker in manual dispatch mode...
    GoogleAnalyticsTracker.getInstance().startNewSession(sessionCode, this);

    //Get url to get survey and tags 
    urlSurveyFilter = Global.getInstance().getUrlStringForRequest(R.string.jsonsurveys, this);
    urlJsonTag = Global.getInstance().getUrlStringForRequest(R.string.jsontagrequest,this);


    //to use the KinseyAppActivity.this like a global variable
    _this = this;

    //set the layout from my xml
    setContentView(R.layout.main1);

    Global.getInstance().locatePosition(MapViewActivity.this);

    // button to choice the filter
    Button filterButton = (Button) findViewById(R.id.filterButton);
    filterButton.setOnClickListener(new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(View v) {
            sendTrackingEvents("Click Filter Button", "Open the filter", "clicked", 1, "/MapActivity");
            showDialog(0);
        }
    });
4

1 に答える 1

0

この方法を使用する必要があります

    private void turnGPSOff(){
    String provider = Settings.Secure.getString(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.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3")); 
        sendBroadcast(poke);
    }
}

GPSを停止したい場所。たとえば、これは onDestroy 、 onStop などにすることができます。

于 2013-11-04T14:36:07.897 に答える