我正在使用HERE-Maps和this Github示例构建导航应用程序,我复制了大部分代码,我为应用程序创建了新凭据,并按照文档中的步骤进行了操作。但我的代码崩溃EngineInitializationCompleted
我认为是因为我在Manifest,Map Service或磁盘缓存方面犯了一些错误。
我收到以下错误:
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)
我的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>
我的主要活动:
@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
答案 0 :(得分:0)
<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>
将您的服务名称放在此处
android:label="{YOUR_LABEL_NAME}"
android:value="{YOUR_INTENT_NAME}"
action android:name="{YOUR_INTENT_NAME}"
正确填写这些地方,您没有提及活动和服务名称