#1929 - Adding token.txt reading for programmatic setting of access token in activity

This commit is contained in:
Brad Leege
2015-07-24 17:27:47 -05:00
parent 955b610fc8
commit c16b0bfb34
2 changed files with 15 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ import android.location.Location;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -38,11 +39,15 @@ import com.mapzen.android.lost.api.LocationServices;
import com.mapzen.android.lost.api.LostApiClient;
import io.fabric.sdk.android.Fabric;
import org.json.JSONException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class MainActivity extends ActionBarActivity {
private static final String TAG = "MainActivity";
//
// Static members
//
@@ -111,6 +116,15 @@ public class MainActivity extends ActionBarActivity {
// Load the layout
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mainMapView);
// Load the access token
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.token)));
String line = reader.readLine();
mapView.setAccessToken(line);
} catch (IOException e) {
Log.e(TAG, "Error loading access token from token.txt: " + e.toString());
}
mapView.onCreate(savedInstanceState);
mapView.setOnFpsChangedListener(new MyOnFpsChangedListener());
mapView.setOnMapChangedListener(new MyOnMapChangedListener());

View File

@@ -45,7 +45,7 @@
android:id="@+id/mainMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:accessToken=""/>
/>
<ImageView
android:id="@+id/view_compass"