2017-03-18 10 views
0

私は場所を取得するための主な活動からのGPS活動を開くしようとしていますが、私はボタンをクリックして、アクティビティにが見つかりませんでしたクラスのandroid.app.AppOpsManager "

アップデートを開くことができないと言うとき、それそれがクラッシュします::: 私はgpsがnullを返す理由を見るためにコードを変更しました.GPSのアクティビティに向けるだけですが、multidexを有効にしてアプリケーションクラスにインストールしようとはしませんでしたが、うまくいきませんでした

PS:私は分のSDK 17 とターゲットSDK 25 を使用していますし、GPSクラスは罰金だけで

の作品

主な活動:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Button two = (Button) findViewById(R.id.button); 
     Recieve = (TextView) findViewById(R.id.textView2); 
     two.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       sendMessage(); 
      } 

     }); 
    } 

    public void sendMessage() { 
     Intent intent = new Intent(this, Activity2.class); 
     startActivity(intent); 

     // startActivityForResult(intent, REQUEST_CODE); 
    } 

    /* @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { 
      Response = data.getStringExtra("key"); 

      Recieve.setText("latitude is :" + Response); 

     } 
    }*/ 

} 

GPSの活動:

public void onConnected(Bundle connectionHint) { 
     createLocationRequest(); 
     startLocationUpdates(); 
     if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      // TODO: Consider calling 
      // ActivityCompat#requestPermissions 
      // here to request the missing permissions, and then overriding 
      // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
      //           int[] grantResults) 
      // to handle the case where the user grants the permission. See the documentation 
      // for ActivityCompat#requestPermissions for more details. 
      return; 
     } 
     Location Location = LocationServices.FusedLocationApi.getLastLocation(GAC); 
     if (Location != null) { 
      Double Lat = Location.getLatitude(); 
      Double lon = Location.getLongitude(); 
      x = (TextView) findViewById(R.id.textView); 
      y = (TextView) findViewById(R.id.textView2); 
      x.setText("Ltitude is " + String.valueOf(Lat)); 
      y.setText("Longitude is " + String.valueOf(lon)); 
     } 

    } 

    @Override 
    protected void onStart() { 
     super.onStart(); 
     if (GAC != null) { 
      GAC.connect(); 
     } 
    } 

    @Override 

    protected void onStop() { 
     GAC.disconnect(); 
     super.onStop(); 
    } 

    @Override 
    public void onConnectionSuspended(int cause) { 
     Toast.makeText(this, "the connection suspended", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onConnectionFailed(ConnectionResult result) { 

     Toast.makeText(this, "the connection failed", Toast.LENGTH_LONG).show(); 

    } 

    @Override 
    public void onLocationChanged(Location location) { 
     x = (TextView) findViewById(R.id.textView); 
     y = (TextView) findViewById(R.id.textView2); 
     x.setText("latitude is " + String.valueOf(location.getLatitude())); 
     y.setText("longitude is " + String.valueOf(location.getLongitude())); 
    } 

    protected void createLocationRequest() { 
     LR = new LocationRequest(); 
     LR.setInterval(5000); 
     LR.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); 
    } 

    protected void startLocationUpdates() { 

     if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
      // TODO: Consider calling 
      // ActivityCompat#requestPermissions 
      // here to request the missing permissions, and then overriding 
      // public void onRequestPermissionsResult(int requestCode, String[] permissions, 
      //           int[] grantResults) 
      // to handle the case where the user grants the permission. See the documentation 
      // for ActivityCompat#requestPermissions for more details. 
      return; 
     } 
     LocationServices.FusedLocationApi.requestLocationUpdates(
       GAC, LR, (this)); 

    } 



    protected void build_GAC(){ 
     GAC =new GoogleApiClient.Builder(this) 
       .addApi(LocationServices.API) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .build(); 

    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     build_GAC(); 

    } 

} 

そして、それは私が取得エラーです:

E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.internal.zzacw.zzg 

答えて

0

このpost

に述べたように、これを解決するために多くの方法があります。

1.アプリケーションクラスを使用していない場合は、このクラスをAndroidManifest.xmlのアプリケーションとして宣言します。あなたはまた、唯一の必要なグーグルを選択してみてくださいすることができます

public class MyApplication extends Application { 
    @Override 
    protected void attachBaseContext(Context base) { 
    super.attachBaseContext(base); 
    MultiDex.install(this);} 
} 

:あなたのアプリケーションオーバーライドattachBaseContext 3.Have

public class MyApplication extends MultiDexApplication { 
    ... 
} 

:あなたのアプリケーションは次のように、MultiDexApplicationクラスを拡張

<application android:name="android.support.multidex.MultiDexApplication"> 

2.Define PlayサービスAPIを使用して問題を解決するか、Instant Runを無効にします。 Gradleの前

: -

compile 'com.google.android.gms:play-services:8.4.0' 

のGradle後: -

compile 'com.google.android.gms:play-services-analytics:8.4.0' 
compile 'com.google.android.gms:play-services-gcm:8.4.0' 
compile 'com.google.android.gms:play-services-location:8.4 
関連する問題