Android application crashes with Google Maps Object - java

I have programmed this code in Android Studio:
1) Karte.java
package barsoftware.suedtirolpointer;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class Karte extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap m_map;
boolean mapReady=false;
MarkerOptions Rieserfernerhütte;
MarkerOptions Dahoam;
static final CameraPosition SÜDTIROL = CameraPosition.builder()
.target(new LatLng(46.470576, 11.339986))
.zoom(8)
.bearing(0)
.tilt(0)
.build();
#Override
public Resources getResources() {
return super.getResources();
}
////////////////////////////// onCreate //////////////////////////////
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//// LAYOUT ////
setContentView(R.layout.karte);
//// KARTEN POI'S ////
Rieserfernerhütte = new MarkerOptions()
.position(new LatLng(46.5324, 12.0446))
.title("Rieserfernerhütte");
Dahoam = new MarkerOptions()
.position(new LatLng(46.738886, 12.166471))
.title("Dahoam");
//// KARTEN IMPLEMENTIERUNG ////
MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//// UP BOOTON ////
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
}
#Override
public void onMapReady(GoogleMap map) {
mapReady = true;
m_map = map;
m_map.addMarker(Rieserfernerhütte);
m_map.addMarker(Dahoam);
flyTo(SÜDTIROL);
}
private void flyTo(CameraPosition target)
{
m_map.moveCamera(CameraUpdateFactory.newCameraPosition(target));
}
////////////////////////////////// MENU //////////////////////////////////
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_no_karte, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.menu_home) {
Intent Home = new Intent(Karte.this,
Start.class);
startActivity(Home);
}
if (id == R.id.menu_karte) {
}
if (id == R.id.menu_teilnehmer) {
Intent Teilnehmer = new Intent(Karte.this,
Teilnehmer.class);
startActivity(Teilnehmer);
}
if (id == R.id.menu_einstellungen) {
Intent Einstellungen = new Intent(Karte.this,
Einstellungen.class);
startActivity(Einstellungen);
}
if (id == R.id.menu_update) {
Intent Update = new Intent(Karte.this,
Update.class);
startActivity(Update);
}
if (id == R.id.menu_teilen) {
Intent Teilen = new Intent(Karte.this,
Teilen.class);
startActivity(Teilen);
}
return super.onOptionsItemSelected(item);
}
}
2) karte.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
3) Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="barsoftware.suedtirolpointer">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#style/AppTheme">
<activity
android:name=".Start"
android:label="#string/act_home" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Karte"
android:label="#string/act_karte"
android:parentActivityName=".Start"/>
<activity android:name=".Teilnehmer"
android:label="#string/act_teilnehmer"
android:parentActivityName=".Start"/>
<activity android:name=".Einstellungen"
android:label="#string/act_einstellungen"
android:parentActivityName=".Start"/>
<activity android:name=".Update"
android:label="#string/act_update"
android:parentActivityName=".Start"/>
<activity android:name=".Teilen"
android:label="#string/act_teilen"
android:parentActivityName=".Start"/>
<activity android:name=".Permission"
android:label="Permission"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCT_CaCyQ2uLFclTcrWex-AEmJ1aHWhR08"/>
</application>
</manifest>
But when I run the application on my phone or on the emulator the appliation crashes. Android-Studio is not showing any errors or bugs. Can anyone show me, what's the error?

In karte.xml you are using the SupportMapFragment but in Karte.java you are not using the SupportFragmentManager.
To get a handle on the SupportMapFragment you are using try this in onCreate():
SupportMapFragment supportMapFragment =
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
supportMapFragment.getMapAsync(this);

How just explained from Kevinn O'Neil in the layout file you are using the
"SupportMapFragment" but in the java file not. In the .java replace:
MapFragment mapFragment = (MapFragment)getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
with:
SupportMapFragment supportMapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
supportMapFragment.getMapAsync(this);
And also in the .xml files (Android Manifestr and layout file) you didn't wrote the beginning line:
<?xml version="1.0" encoding="utf-8"?>
Add this line to all files with .xml ending.
I hope I was able to help you.

Related

Android BroadcastReceiver in ScrollActivity

I had working BroadcastReceiver which notifys user about network status changes, but since i added ScrollActivity to my app, the receiver is not working anymore. So i tried to make a blank ScrollActivity template project to test the reciever and i can see the same - the receiver wont work in apps with ScrollActivity. im a little bit desperate with this situation, would be thankful for help.
I have permissions and receiver registred in manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test_app">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".ScrollingActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ConnectivityStatusReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
</application>
</manifest>
Here comes the receiver code, which hasnt been called even once in scrollactivity apps yet..
package com.example.test_app;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
public class ConnectivityStatusReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//THIS HASNT BEEN CALLED EVEN ONCE YET SINCE SCROLLACTIVITY
final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connMgr.getActiveNetworkInfo();
Log.d("RECIEVER_LOG", "intent:"+intent.getAction());
if(activeNetworkInfo.isConnected()){
Log.d("NETWORK_LOG", "connected.");
}else{
Log.d("NETWORK_LOG", "not connected.");
}
if (activeNetworkInfo == null){
//no connection activity opens on connection loss
context.startActivity(new Intent(context , NoInternetConnection.class));
}
}
}
And here is the Scrolling activity itself, untouched as Android Studio generated it
package com.example.test_app;
import android.os.Bundle;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class ScrollingActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CollapsingToolbarLayout toolBarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
toolBarLayout.setTitle(getTitle());
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_scrolling, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Would be thankful for any help.

Android - Can't show the google map

I need some help...
My application can't show the map. I've enabled the API Key and try to create it many times, with new keystore.
Screenshot for result
The error code says:
12-14 03:47:45.527 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/b: Authentication failed on the server.
12-14 03:47:45.527 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/Google Maps Android API: Authorization failure. Please see
12-14 03:47:45.533 31641-31956/tkj5a.dhiaulhaq.pnj.project_paksyamsi E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: AIzaSyCLdUfhN9SoszJQiGzDF1rcOuV5P2RfcJs
Android Application (<cert_fingerprint>;<package_name>): 39:AD:91:AB:60:3D:34:22:1C:F3:36:4B:B6:98:6F:BB:61:5A:B5:60;tkj5a.dhiaulhaq.pnj.project_paksyamsi
And my layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tkj5a.dhiaulhaq.pnj.project_paksyamsi">
<permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="tkj5a.dhiaulhaq.pnj.project_paksyamsi.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MapsActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
<activity android:name=".CheckInActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCLdUfhN9SoszJQiGzDF1rcOuV5P2RfcJs"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
</application>
</manifest>
And here's the MapsActivity.java:
package tkj5a.dhiaulhaq.pnj.project_paksyamsi;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
public class MapsActivity extends FragmentActivity {
private GoogleMap map;
private DBLokasi lokasi;
private ArrayList<DBLokasi> values;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFrag=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
map=mapFrag.getMap();
map.setMyLocationEnabled(true);
Bundle b=this.getIntent().getExtras();
if (b.containsKey("longitude")){
final LatLng latLng=new LatLng(b.getDouble("latitude"),b.getDouble("longitude"));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this,"Lokasi Saat Ini " + latLng.latitude+ "," +latLng.longitude,Toast.LENGTH_LONG).show();
return false;
}
});
}else if (this.getIntent().getSerializableExtra("lokasi")!=null){
lokasi=(DBLokasi)this.getIntent().getSerializableExtra("lokasi");
if (lokasi!=null){
LatLng latLng=new LatLng(lokasi.getLatD(),lokasi.getLngD());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)).title(lokasi.getNama()));
}
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
final Dialog dialog=new Dialog(MapsActivity.this);
dialog.setTitle("Checkin Data : ");
dialog.setContentView(R.layout.fragment_dialog_datashow);
TextView tvNama=(TextView)dialog.findViewById(R.id.tv_nama);
TextView tvKoordinat=(TextView)dialog.findViewById(R.id.tv_koordinat);
Button btOK=(Button)dialog.findViewById(R.id.bt_checkin_ok);
tvNama.setText(String.format(getResources().getString(R.string.checkin_label_name),marker.getTitle()));
tvKoordinat.setText(marker.getPosition().latitude+ ","+ marker.getPosition().longitude);
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
return false;
}
});
}
else {
LatLng init;
DBLokasi lokInit;
LatLng latLng;
values=((ArrayList<DBLokasi>)this.getIntent().getSerializableExtra("arraylokasi"));
lokInit=values.get(0);
init=new LatLng(lokInit.getLatD(),lokInit.getLngD());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(init,16));
for (DBLokasi lok:values){
latLng=new LatLng(lok.getLatD(),lok.getLngD());
map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN)));
}
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
final Dialog dialog=new Dialog(MapsActivity.this);
dialog.setTitle("Checkin Data : ");
dialog.setContentView(R.layout.fragment_dialog_datashow);
TextView tvNama=(TextView)dialog.findViewById(R.id.tv_nama);
TextView tvKoordinat=(TextView)dialog.findViewById(R.id.tv_koordinat);
Button btOK=(Button)dialog.findViewById(R.id.bt_checkin_ok);
tvNama.setText(String.format(getResources().getString(R.string.checkin_label_name)));
tvKoordinat.setText(marker.getPosition().latitude+","+marker.getPosition().longitude);
btOK.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.cancel();
}
});
dialog.show();
return false;
}
});
}
}
}
Thanks for any helps guys :)
Confirm the SHA-1 key you are getting in the message and the key you have on server are same. Also, make sure adding the API key in manifest as well as in a XML file (release -> res -> values -> google_maps_api.xml) which automatically gets generated.
**Manifest:**
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
and
**google_maps_api.xml**
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
YOUR_KEY_HERE
</string>
You can get SHA-1 key and package name from the error message you have posted. Both are separated by ';'
Make sure your API key is the correct one... and maybe check if you have the 'Google Play Services' SDK installed.
It says "In the Google Developer Console" so i would start there lol
Check:
-SHA 1 key
-API Key
Don't forget to hit 'Save' once you're done, i know a few people who have made that mistake before!

Google Analytics Campaign Tracking: Testing

I am trying to implement google analytics campaign tracking into my app. The relevant code is:
MainActivity.java
package com.example.prakhar.myapplication;
import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View;
import com.google.android.gms.analytics.HitBuilders; import com.google.android.gms.analytics.Tracker;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Tracker t = ((AnalyticsApplication) getApplication()).getTracker(AnalyticsApplication.TrackerName.APP_TRACKER);
String campaignData = "http://examplepetstore.com/index.html?" +
"utm_source=email&utm_medium=email_marketing&utm_campaign=summer" +
"&utm_content=email_variation_1";
Log.d("MainActivity", "Sending an event");
t.send(new HitBuilders.ScreenViewBuilder()
.setCampaignParamsFromUrl(campaignData)
.build()
);
Log.d("MainActivity", "Event sent");
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_SHORT)
.setAction("Action", null).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} }
AnalyticsApplication.java
package com.example.prakhar.myapplication;
import android.app.Application;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import java.util.HashMap;
/**
* Created by prakhar on 2/12/15.
*/
public class AnalyticsApplication extends Application{
private Tracker mTracker;
// The following line should be changed to include the correct property id.
private static final String PROPERTY_ID = "UA-XXXX-XX";
/**
* Enum used to identify the tracker that needs to be used for tracking.
*
* A single tracker is usually enough for most purposes. In case you do need multiple trackers,
* storing them all in Application object helps ensure that they are created only once per
* application instance.
*/
public enum TrackerName {
APP_TRACKER,
GLOBAL_TRACKER,
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
: analytics.newTracker(R.xml.app_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
synchronized public Tracker getDefaultTracker()
{
if (mTracker == null)
{
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
mTracker = analytics.newTracker(R.xml.global_tracker);
}
return mTracker;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prakhar.myapplication" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name="com.example.prakhar.myapplication.AnalyticsApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Used for Google Play Store Campaign Measurement-->
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
installation campaign reporting -->
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
</application>
</manifest>
app_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="ga_sessionTimeout">300</integer>
<bool name="ga_autoActivityTracking">true</bool>
<string name="ga_trackingId">UA-XXXXXX </string>
<string name="ga_sampleFrequency">100.0</string>
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
Essentially, I should get a log as soon as I install the app, but that is not happening. Where am I going wrong? Am I testing it the wrong way?
Initially I was getting the ClassCastException but that I resolved by including the name in the android manifest.
I am not sure, but on web pages, when you install analytics you have to wait more or less 1/2 days to begin to work.

get map from geoserver to argis sdk android

I can't getMap from geoserver 2.7 to my Android application using argis SDK in Android studio 1.1.0 i try to get the map via WMS (Web Map Service) to my android app her's the code below
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapView;
import com.esri.android.map.ogc.WMSLayer;
public class MainActivity extends Activity {
MapView mMapView;
WMSLayer wmsLayer;
String wmsURL;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// after the content of this activity is set
// the map can be accessed from the layout
mMapView = (MapView)findViewById(R.id.map);
// set up the wms url
wmsURL ="http://10.1.1.100:8090/geoserver/cyobjet/wms?service=WMS" +
"&version=1.1.0" +
"&request=GetMap" +
"&layers=cyobjet:object" +
"&styles=" +
"&bbox=-20.8250007629395,-9.94999980926514,4185.8251953125,1999.94995117188" +
"&width=690&height=330" +
"&srs=EPSG:900913" +
"&format=image%2Fpng";
wmsLayer = new WMSLayer(wmsURL);
wmsLayer.setImageFormat("image/png");
// available layers
String[] visibleLayers = {"cyobject:object"};
wmsLayer.setVisibleLayer(visibleLayers);
wmsLayer.setOpacity(0.5f);
mMapView.addLayer(wmsLayer);
// Set the Esri logo to be visible, and enable map to wrap around date line.
mMapView.setEsriLogoVisible(true);
mMapView.enableWrapAround(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
and My Androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pfe.loungou.map" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and my Layout to see MAP in my android APP
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!-- MapView -->
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
I'm testing the APP in my android phone and when i open it i get black screen
PS: when i get the Link Below in my phone browser i get the MAP , i think that my geoserver is running and the issue with my Android code so hope helping me ;)
I got the map to work fine by removing the parameters from wmsURL. Here's the modified code:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapView;
import com.esri.android.map.ogc.WMSLayer;
public class MainActivity extends Activity {
MapView mMapView;
WMSLayer wmsLayer;
String wmsURL;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// after the content of this activity is set
// the map can be accessed from the layout
mMapView = (MapView)findViewById(R.id.map);
wmsURL = "http://10.1.1.100:8090/geoserver/cyobjet/wms";
wmsLayer = new WMSLayer(wmsURL);
wmsLayer.setImageFormat("image/png");
// available layers
String[] visibleLayers = {"cyobjet:object"};
wmsLayer.setVisibleLayer(visibleLayers);
wmsLayer.setOpacity(0.5f);
mMapView.addLayer(wmsLayer);
mMapView.setEsriLogoVisible(false);
mMapView.enableWrapAround(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Shifting between activities (Android)

Shifting between activities isn't working.
What the app does is it opens the android.xml file then after 5 secs open the main file
Here's the code:
android manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.android.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.android.android"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.ANDROID" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
android.java file:
package com.example.android;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class android extends Activity{
MediaPlayer sound1;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.android);
sound1 = MediaPlayer.create(android.this , R.raw.android);
sound1.start();
Thread timer = new Thread()
{public void run()
{
try{
sleep(5000);
}
catch(InterruptedException ac){
ac.printStackTrace();
}
finally{
Intent openactivity = new Intent ("android.intent.action.MAIN");
startActivity(openactivity);
}
}
};
timer.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
sound1.release();
finish();
}
}
Mainactivity.java:
package com.example.android;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
android.xml file:(the first file that launches up)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background = "#drawable/android"
>
</LinearLayout>
Try this way
Intent openactivity = new Intent(android.this,MainActivity.class);
startActivity(openactivity);
And for more information go to starting-new-activity
First, always Capitalise 1st letter of class names (code convention),
and then write your intents like below:
Intent intent = new Intent(android.this, MainActivity.class);
startActivity(intent );
You can check Starting Another Activity in Android Developers website.

Categories

Resources