I am building navigation app using HERE-Maps and this Github example, I replicated most of the code, I created new credentials for my app and followed steps written in documentation. But my code is crashing on EngineInitializationCompleted I think its because of some mistake I did in Manifest, Regarding Map Service or Disk cache.
I am getting this error below:
03-28 13:16:21.077 26352-26352/propelit.actionopps.com.propelit D/xxxxxx: Unknown error occurred.
java.lang.SecurityException: Not allowed to start service Intent { act={YOUR_INTENT_NAME} cmp=com.here.android.example.basicpositioningsolution/com.here.android.mpa.service.MapService (has extras) } without permission not exported from uid 10205
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1418)
at android.app.ContextImpl.startService(ContextImpl.java:1395)
at android.content.ContextWrapper.startService(ContextWrapper.java:623)
at com.nokia.maps.MapServiceClient.a(MapServiceClient.java:77)
at com.nokia.maps.MapsEngine.a(MapsEngine.java:621)
at com.nokia.maps.MapsEngine.a(MapsEngine.java:363)
at com.here.android.mpa.common.MapEngine.init(MapEngine.java:261)
at com.nokia.maps.bw.a(MapFragmentImpl.java:132)
at com.here.android.mpa.mapping.MapFragment.init(MapFragment.java:112)
at propelit.actionopps.com.propelit.MainActivity.initializeMapsAndPositioning(MainActivity.java:178)
at propelit.actionopps.com.propelit.MainActivity.onRequestPermissionsResult(MainActivity.java:369)
at propelit.actionopps.com.propelit.MainActivity.checkPermissions(MainActivity.java:350)
at propelit.actionopps.com.propelit.MainActivity.onCreate(MainActivity.java:79)
at android.app.Activity.performCreate(Activity.java:6852)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2766)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
My Manifest.xml :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="propelit.actionopps.com.propelit">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:maxSdkVersion="22" android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:screenOrientation="portrait"
android:theme="#style/AppTheme"
android:label="#string/app_name" android:hardwareAccelerated="true">
<meta-data android:name="com.here.android.maps.appid" android:value="skxxxxxxxxxxxxxxxxZO"/>
<meta-data android:name="com.here.android.maps.apptoken" android:value="Dgm_cxxxxxxxxxxxxxxv6FGEeQ"/>
<meta-data android:name="com.here.android.maps.license.key" android:value="hZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZuC0m2vtXunxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5wZVsq1Li2RSU="/>
<activity android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".SplashScreen"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
</activity>
<meta-data
android:name="INTENT_NAME"
android:value="{YOUR_INTENT_NAME}" />
<service
android:name="com.here.android.mpa.service.MapService"
android:label="{YOUR_LABEL_NAME}"
android:exported="false">
<intent-filter>
<action android:name="{YOUR_INTENT_NAME}">
</action>
</intent-filter>
</service>
<!--
Embed the HERE Positioning Service.
For more information, see the HERE SDK Developer's Guide
-->
<service android:enabled="true" android:exported="false" android:name="com.here.services.internal.LocationService" android:process=":remote">
</service>
</application>
</manifest>
My MainActivity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
checkPermissions();
private void initializeMapsAndPositioning() {
setContentView(R.layout.activity_main);
mTopToolbar = (Toolbar) findViewById(R.id.toolbar);
rotateLoading = (RotateLoading) findViewById(R.id.progressBar2);
setSupportActionBar(mTopToolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
if (navigationView != null) {
navigationView.setNavigationItemSelectedListener(this);
}
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, mTopToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
Window window = this.getWindow();
// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// finally change the color
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(ContextCompat.getColor(this ,R.color.colorPrimaryDark));
}
mLocationInfo = (TextView) findViewById(R.id.textViewLocationInfo);
mapFragment = (MapFragment)getFragmentManager().findFragmentById(
R.id.mapfragment);
mapFragment.setRetainInstance(false);
// Set path of isolated disk cache
String diskCacheRoot = Environment.getExternalStorageDirectory().getPath()
+ File.separator + ".isolated-here-maps";
// Retrieve intent name from manifest
String intentName = "";
try {
ApplicationInfo ai = getPackageManager().getApplicationInfo(this.getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = ai.metaData;
intentName = bundle.getString("INTENT_NAME");
} catch (PackageManager.NameNotFoundException e) {
Log.e(this.getClass().toString(), "Failed to find intent name, NameNotFound: " + e.getMessage());
}
Toast.makeText(MainActivity.this, "before", Toast.LENGTH_SHORT).show();
boolean success = MapSettings.setIsolatedDiskCacheRootPath(diskCacheRoot, intentName);
if (!success) {
Toast.makeText(MainActivity.this, "diskcache", Toast.LENGTH_SHORT).show();
// Setting the isolated disk cache was not successful, please check if the path is valid and
// ensure that it does not match the default location
// (getExternalStorageDirectory()/.here-maps).
// Also, ensure the provided intent name does not match the default intent name.
} else {
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(Error error) {
Toast.makeText(MainActivity.this, "inside", Toast.LENGTH_SHORT).show();
if (error == Error.NONE) {
Toast.makeText(MainActivity.this, "inside 2", Toast.LENGTH_SHORT).show();
map = mapFragment.getMap();
map.setCenter(new GeoCoordinate(61.497961, 23.763606, 0.0), Map.Animation.NONE);
map.setZoomLevel(map.getMaxZoomLevel() - 1);
map.addTransformListener(MainActivity.this);
mPositioningManager = PositioningManager.getInstance();
mHereLocation = LocationDataSourceHERE.getInstance(
new StatusListener() {
#Override
public void onOfflineModeChanged(boolean offline) {
// called when offline mode changes
}
#Override
public void onAirplaneModeEnabled() {
// called when airplane mode is enabled
}
#Override
public void onWifiScansDisabled() {
// called when Wi-Fi scans are disabled
}
#Override
public void onBluetoothDisabled() {
// called when Bluetooth is disabled
}
#Override
public void onCellDisabled() {
// called when Cell radios are switch off
}
#Override
public void onGnssLocationDisabled() {
// called when GPS positioning is disabled
}
#Override
public void onNetworkLocationDisabled() {
// called when network positioning is disabled
}
#Override
public void onServiceError(ServiceError serviceError) {
// called on HERE service error
}
#Override
public void onPositioningError(PositioningError positioningError) {
// called when positioning fails
}
});
if (mHereLocation == null) {
Toast.makeText(MainActivity.this, "LocationDataSourceHERE.getInstance(): failed, exiting", Toast.LENGTH_LONG).show();
finish();
}
mPositioningManager.setDataSource(mHereLocation);
mPositioningManager.addListener(new WeakReference<PositioningManager.OnPositionChangedListener>(
MainActivity.this));
// start position updates, accepting GPS, network or indoor positions
if (mPositioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK_INDOOR)) {
mapFragment.getPositionIndicator().setVisible(true);
} else {
Toast.makeText(MainActivity.this, "PositioningManager.start: failed, exiting", Toast.LENGTH_LONG).show();
finish();
}
} else {
Log.d("xxxxxx", error.getDetails());
Log.d("xxxxxx", error.getStackTrace());
Toast.makeText(MainActivity.this, "onEngineInitializationCompleted: error: " + error + ", exiting", Toast.LENGTH_LONG).show();
finish();
}
}
});
}
}
// some more overriden methods and callback methods
<meta-data
android:name="INTENT_NAME"
android:value="{YOUR_INTENT_NAME}" />
<service
android:name="com.here.android.mpa.service.MapService"
android:label="{YOUR_LABEL_NAME}"
android:exported="false">
<intent-filter>
<action android:name="{YOUR_INTENT_NAME}">
</action>
</intent-filter>
</service>
Put your service name here
android:label="{YOUR_LABEL_NAME}"
android:value="{YOUR_INTENT_NAME}"
action android:name="{YOUR_INTENT_NAME}"
fill these places properly, you didn't mention activity and service names
Related
I want to ask users to agree with the disclaimer that I have provided in my application, and then if they agreed, next time they are using the app, we just re-show them the disclaimer for a few seconds without asking to click on anything and redirect them to the application. The best way I could have come up with it was, using a custom permission and however I did add permission commands to my manifest I could not figure out how to actually activate the permission in my code:
import java.util.jar.Manifest;
public class Language extends Activity {
Button engBut, fraBut;
// public static int j;
public void click (View view){
// j=1;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
public void fraClick (View view){
// j=2;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language);
ImageView logo = (ImageView) findViewById(R.id.logo);
ImageView montfortLogo = (ImageView) findViewById(R.id.montfortLogo);
montfortLogo.setImageResource(R.drawable.k);
logo.setImageResource(R.drawable.j);
engBut = (Button) findViewById(R.id.engBut);
engBut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(Language.this);
builder.setCancelable(true);
builder.setTitle("DISCLAIMER");
builder.setMessage(R.string.result_disclaimer);
builder.setNegativeButton("Get me out of here.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
builder.setPositiveButton("I agree.", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
intent.setAction("com.techideas4you.pharamacy.MyAction");
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
});
builder.show();
}
});
fraBut = (Button) findViewById(R.id.fraBut);
Log.i("Locale", String.valueOf(Locale.getDefault()));
}
}
This was my first page code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.ex"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
<permission android:name="testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"/>
<uses-permission android:name="testDisclaimer"/>
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name">
</activity>
<activity
android:name=".ActivityQuestion"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".ActivityResult"
android:icon="#drawable/home"
android:label="Home"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity android:name=".Language">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter >
<action android:name="com.techideas4you.pharamacy.MyAction"
/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
and this is my manifest if anybody could help me out here I really appreciate it.
You have to add android:protectionLevel="dangerous" to the declaration of your permission else it will be granted automatically and users will not be presented with a dialog although you call requestPermission().
<permission android:name="your.package.name.permission.testDisclaimer" android:label="DISCLAIMER"
android:description="#string/result_disclaimer"
android:protectionLevel="dangerous"/>
<uses-permission android:name="your.package.name.permission.testDisclaimer"/>
In order to have the runtime show the disclaimer, you have to call
requestPermissions(new String[]{"your.package.name.permission.testDisclaimer"}, 42);
The result (whether user agreed) will be transmitted to you in onRequestPermissionsResult()
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 42 && grantResults != null){
Toast.makeText(this, "Permission " + permissions[0] + (grantResults[0] == PERMISSION_GRANTED ? "" : " NOT ") + " granted! ", Toast.LENGTH_LONG).show();
}
}
Please note that by using the permission system, you also have to cope with the fact that users will NOT be shown the permission-request-disguised-as-disclaimer if they
[...] turned down the permission request in the past and chose the
Don't ask again option in the permission request system dialog [...]
(quoted from documentation).
So maybe simply writing a flag to SharedPreferences will do the job just as well.
I am new to HERE maps currently trying to get current user location from Positioning manager , getlocation() method, but my code always return below information
com.nokia.maps.GeoPositionImpl[coordinate=GeoCoordinate [Latitude=-179769313486232000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 Longitude=-179769313486232000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 Altitude=1073741824.000000 Valid=FALSE]]
Below is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//requestPermissions();
// Search for the Map Fragment
final MapFragment mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.mapfragment);
// initialize the Map Fragment and
// retrieve the map that is associated to the fragment
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(
OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// now the map is ready to be used
map = mapFragment.getMap();
onMapFragmentInitializationCompleted();
} else {
System.out.println("ERROR: Cannot initialize MapFragment");
System.out.println("ERROR: Cannot initialize Map Fragment: " + error.toString());
}
}
});
}
private void onMapFragmentInitializationCompleted() {
PositioningManager posManager;
MapContainer placesContainer = null;
// retrieve a reference of the map from the map fragment
// map = mapFragment.getMap();
// start the position manager
posManager = PositioningManager.getInstance();
posManager.start(PositioningManager.LocationMethod.GPS_NETWORK);
GeoPosition position = posManager.getPosition();
GeoCoordinate cor = position.getCoordinate();
// Set a pedestrian friendly map scheme
map.setMapScheme(Map.Scheme.PEDESTRIAN_DAY);
// Display position indicator
map.getPositionIndicator().setVisible(true);
placesContainer = new MapContainer();
map.addMapObject(placesContainer);
// Set the map center coordinate to the current position
map.setCenter(posManager.getPosition().getCoordinate(), Map.Animation.NONE);
map.setZoomLevel(14);
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.benz.event.navigation">
<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-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="navigation"
android:hardwareAccelerated="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.here.android.maps.appid" android:value="MY ID"/>
<meta-data android:name="com.here.android.maps.apptoken" android:value="MY TOKEN"/>
<meta-data android:name="com.here.android.maps.license.key" android:value="MY KEY"/>
<!--
Embed the HERE Map Service.
For more information, see the HERE SDK Developer's Guide
-->
<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v2"
android:exported="true" >
<intent-filter>
<action android:name="com.here.android.mpa.service.MapService" >
</action>
</intent-filter>
</service>
</application>
</manifest>
Any help/hint will save my day
Thanks
Valid=FALSE Implies your device does not have a GPS lock. Is your device indoors and unable to obtain a position? Second, please check to see if your application has the positioning permission.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION " />
Issue: ProjectManager.getInstance(); gives null object, I am clueless I have done the code as below,
Activity class & Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="proj.Mobi">
<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-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:hardwareAccelerated="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.here.android.maps.appid" android:value="WcIOjXKhgYk8" />
<meta-data android:name="com.here.android.maps.apptoken" android:value="XaRs1SILAVi2sw" />
<meta-data android:name="com.here.android.maps.license.key" android:value="phEpi5ZL3jiNTElgM3ldzrJTeevoNeYY47oE9eSzgJfySv=" />
</application>
</manifest>
I am creating class of map activity below, I have created the PositioningManager.getInstance() it gives null object by Toast popup
public class MainActivity extends AppCompatActivity {
// map embedded in the map fragment
private Map map = null;
// map fragment embedded in this activity
private MapFragment mapFragment = null;
private PositioningManager positioningManager = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Positioning Manager
positioningManager = PositioningManager.getInstance();
if (positioningManager == null) {
Toast.makeText(MainActivity.this, " Positioning Null", Toast.LENGTH_LONG).show();
}
// Search for the map fragment to finish setup by calling init().
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(
OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap();
// Set the map center to the Vancouver region (no animation)
map.setCenter(new GeoCoordinate(12.9172, 77.5738, 0.0),
Map.Animation.NONE);
// Set the zoom level to the average between min and max
map.setZoomLevel(
(map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
Toast.makeText(MainActivity.this, "Error:" + error.toString(), Toast.LENGTH_LONG).show();
}
}
});
}
}
Everything that's HERE Maps related needs to happen after initialization. This is applicable for everything related to the HERE MobileSDK.
Try getting the PositioningManager inside your EngineInitListener.onEngineInitializationCompleted (and keep in mind, once you get the instance, you also have to call start on it to receive any events)
I am sure this is simple but I cannot figure it out. All I am trying to do is send a message via NFC (android Beam) and open my App on the receiver device. I did test my code on a new Project and it worked perfectly but if I try it on my real Project it just start "New Tag collected" and shows application/eu.freemoser.mydebts2go (see my screenshot). I don't know what's wrong maybe something with the manifest? The Google results doesn't match with my problem (or I am just to stupid) but I believe I found some related answer unfortunately I still was not able to solve my problem
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.freemoser.myDebts2go"
android:versionCode="16"
android:versionName="1.1.0">
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<uses-feature android:name="android.hardware.nfc" android:required="false" />
<uses-feature android:name="android.hardware.camera" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:name="eu.freemoser.myDebts2go.MyApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Mydebts2go">
>
<service android:name="eu.freemoser.myDebts2goService.NotificationService"></service>
<service android:name="eu.freemoser.myDebts2goService.SynchronizationService"></service>
<service android:name="eu.freemoser.myDebts2goService.SynchronizService"></service>
<service android:name="eu.freemoser.myDebts2goService.AwesomeSynchronizService"></service>
<activity
android:name="eu.freemoser.myDebts2go.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="eu.freemoser.myDebts2GoActivities.AwesomeDetailActivity"
android:screenOrientation="portrait" android:theme="#style/Theme.MyDebts2GO.Detail">
</activity>
<activity android:name=".AndroidBeamActivity" android:screenOrientation="portrait"
android:theme="#android:style/Theme.DeviceDefault.Wallpaper.NoTitleBar">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/eu.freemoser.myDebts2go" />
</intent-filter>
</activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.DriveRestoreActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.SynchronizActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.SettingActivity">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.DatePickerActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.LocationPickerActivity"></activity>
<activity android:name="eu.freemoser.myDebts2GoActivities.SearchActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
<activity
android:name="eu.freemoser.myDebts2GoActivities.DriveAuthorzingActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar">
</activity>
<activity
android:name="eu.freemoser.myDebts2GoActivities.FastModusShortcutActivity"
android:exported="true"
android:theme="#android:style/Theme.Holo.Light.NoActionBar">
</activity>
<!-- android:value="API_KEY" /> DEBUG-->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="VERSION" />
</application>
</manifest>
The Fragment (sender)
public class AwesomeDetailFragment extends Fragment implements ObservableScrollView.Callbacks, NfcAdapter.CreateNdefMessageCallback, NfcAdapter.OnNdefPushCompleteCallback {
...
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
setUpAndroidBeam();
return mRootView;
}
private void setUpAndroidBeam() {
PackageManager pm = getActivity().getPackageManager();
// Check whether NFC is available on device
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
// NFC is not available on the device.
}
// Check whether device is running Android 4.1 or higher
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
// Android Beam feature is not supported.
} else {
myNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
manageNfc();
}
}
private void manageNfc() {
if (myNfcAdapter != null) {
myNfcAdapter.setNdefPushMessageCallback(this, getActivity());
myNfcAdapter.setOnNdefPushCompleteCallback(this, getActivity());
}
}
...
#Override
public NdefMessage createNdefMessage(NfcEvent event) {
Time time = new Time();
time.setToNow();
String text = myBetrag + "//" + myTitle + "//" + myContactName + "//" + myStatus + "//" + myDebtDate + "//" + myCreateDate + "//" + myRemamberDate + "//" + myNote;
NdefMessage msg = new NdefMessage(
new NdefRecord[]{createMimeRecord(
"application/eu.freemoser.myDebts2go", text.getBytes())});
return msg;
}
public NdefRecord createMimeRecord(String mimeType, byte[] payload) {
byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
NdefRecord mimeRecord = new NdefRecord(
NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
return mimeRecord;
}
#Override
public void onNdefPushComplete(NfcEvent event) {
}
}
The Activity (receiver)
public class Beam extends Activity {
private Long userID = null;
private Long adressID = null;
private DBAdapter myDb;
//NFC
private String myBetrag;
private String myTitle;
private String myContactName;
private String myDebtDate;
private String myCreateDate;
private String myStatus;
private String myRemamberDate;
private String myNote;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
protected void onResume() {
super.onResume();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
processIntent(getIntent());
}
}
void processIntent(Intent intent) {
myDb = new DBAdapter(this);
myDb.open();
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(
NfcAdapter.EXTRA_NDEF_MESSAGES);
// only one message sent during the beam
NdefMessage msg = (NdefMessage) rawMsgs[0];
// record 0 contains the MIME type, record 1 is the AAR, if present
String temp = new String(msg.getRecords()[0].getPayload());
String[] arrrayTemp = temp.split("//");
try {
myBetrag = arrrayTemp[0];
myTitle = arrrayTemp[1];
myContactName = arrrayTemp[2];
myStatus = arrrayTemp[3];
myDebtDate = arrrayTemp[4];
myCreateDate = arrrayTemp[5];
// can be "NOT"
myRemamberDate = arrrayTemp[6];
myNote = arrrayTemp[7];
// checkValues
channgeStatus();
checkIfNot();
checkUser();
//write to database
write();
} catch (Exception ex) {
this.finish();
}
}
#Override
protected void onDestroy() {
super.onDestroy();
myDb.close();
}
private void checkUser() {
//do some stuff
...
}
private void write() {
//do some stuff
...
}
private void checkIfNot() {
//do some stuff
...
}
private void channgeStatus() {
//do some stuff
...
}
#Override
public void onNewIntent(Intent intent) {
// onResume gets called after this to handle the intent
setIntent(intent);
}
}
Android's MIME type matching for intent filters is case-sensitive (eventhough the MIME types themselves are not). Therefore, with Android (and also pretty much everywhere you use them) you should stick to the convention to use MIME types with lowercase letters only.
Specifically with MIME type records received over NFC, Android will automatically convert them to all-lowercase letters to overcome the problem of case-sensitivity in intent filters. So in your example, changing the type name in the intent filter to "application/eu.freemoser.mydebts2go" should work:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/eu.freemoser.mydebts2go"/>
</intent-filter>
In addition, you should also make sure you send the MIME type in lowercase letters only:
NdefMessage msg = new NdefMessage(
new NdefRecord[]{createMimeRecord(
"application/eu.freemoser.mydebts2go", text.getBytes())});
I am trying to make an app which is using parse library for push notifications.I followed the tutorials from parse.com but its not working.
I am getting error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.robotrackerclient/com.robotrackerclient.MainActivity}:
java.lang.IllegalArgumentException: listener==null
I think the problem is in the code.I am having a main activity which is launching activity of the app.I am putting the parse.initialize() code in the onCreate method of main activity.Is this creating the problem? There is one more error: You must call parse.initialize(..) before using the parse library.
The Main Activity is just a simple class getting the lattitude and longitude of the current location and pushing it.
public class MainActivity extends Activity {
private String imei_code_of_device;
private LocationManager lm;
private LocationListener locationListener;
TelephonyManager mngr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Specify an Activity to handle all pushes by default.
//PushService.setDefaultPushCallback(this, MainActivity.class);
Parse.initialize(this, "APP_KEY", "CLIENT_KEY");
PushService.setDefaultPushCallback(this, MainActivity.class);
mngr=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
imei_code_of_device=mngr.getDeviceId();
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListener);
locationListener = new MyLocationListener();
if ( !lm.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
buildAlertMessageNoGps();
}
else{
lm.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
10000,
0,
locationListener);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,10000,0,locationListener);
}
}
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(#SuppressWarnings("unused") final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, #SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
private class MyLocationListener implements LocationListener {
#Override
public void onLocationChanged(Location loc) {
if (loc != null) {
ParseObject po=new ParseObject("LatLang");
po.put("imei_code",imei_code_of_device);
po.put("latitude",loc.getLatitude());
po.put("longitude",loc.getLongitude());
po.saveInBackground();
Toast.makeText(getBaseContext(),"Location changed : Lat: " + loc.getLatitude() +" Lng: " + loc.getLongitude(),Toast.LENGTH_SHORT).show();
}
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
#Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
#Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
#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);
}
}
Here is my androidmenifest file:
I completed these steps with help of the tutorials available on parse.com.I included everything which parse.com tutorial said me to include.I am not getting the point of Application.Because I have to parse in the one of the activities only and it is not the first activity to be launched.So I dont want to initialize parse at my application startup.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robotrackerclient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<permission android:name="com.robotrackerclient.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.robotrackerclient.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/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>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.robotrackerclient" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
</manifest>
You should use your app and client keys instead of default values APP_KEY and CLIENT_KEY in this line:
Parse.initialize(this, "APP_KEY", "CLIENT_KEY");
which you can get after signing up at Parse.
OKay thank you very much for helping I am able to send push to parse.com.The mistake was in the manifest file.I updated the menifestfile with providing android:name=."ParseActivity" under the application tag.Then I defined the initialization in the ParseActivity class.
Now can anybody tell how to get the pushed data over server back on another device using the same set of keys?