Whenever I try to initialize the map, I always get the "error UNKNOWN" message.
I tried the examples from HERE, but I get the same error on all of them. So I made a very simple and clean application with the sole purpose of loading the map. It still doesn't work and I can't put my finger on it.
I'm using Android, trying to target version 4.4 (KitKat).
I am using the Premium SDK (during the 90 day trial).
I verified the app key, code and licence key many times now. They are absolutely correct.
The registered package name is
com.example.workywork
but in the manifest I have:
package="com.example.workywork.testherepremium"
(It was supposed to be a test, so don't mind the package name :) )
I think it is right, since they asked for package name, not for package name + project name.
Here is the code from my simple application:
Build.Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.workywork.testherepremium"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation (name: 'HERE-sdk', ext: 'aar')
implementation 'com.vividsolutions:jts:1.13'
implementation 'com.google.code.gson:gson:2.8.0'
}
Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.workywork.testherepremium.MainActivity">
<fragment
class="com.here.android.mpa.mapping.MapFragment"
android:id="#+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.constraint.ConstraintLayout>
Activity
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.here.android.mpa.common.GeoCoordinate;
import com.here.android.mpa.common.OnEngineInitListener;
import com.here.android.mpa.mapping.Map;
import com.here.android.mpa.mapping.MapFragment;
public class MainActivity extends AppCompatActivity {
MapFragment mapFragment;
Map map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
#Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == Error.NONE) {
map = mapFragment.getMap();
map.setCenter(new GeoCoordinate(49.259149, -123.008555),
Map.Animation.LINEAR);
map.setZoomLevel(13.2);
} else {
Toast.makeText(getApplicationContext(),"ERROR: Cannot initialize Map with error " + error,
Toast.LENGTH_LONG).show();
Log.e("mymsg", error.getStackTrace());
Log.e("mymsg", error.getDetails());
}
}
});
}
}
AndroidManifest.xml
...
<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.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: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>
<!--Developers should put application credentials here.To obtain them, please register the application
at https://developer.here.com/develop/mobile-sdks-->
<meta-data android:name="com.here.android.maps.appid" android:value="-- app id --"/>
<meta-data android:name="com.here.android.maps.apptoken" android:value="-- app token --"/>
<meta-data android:name="com.here.android.maps.license.key" android:value="-- license --" />
<service
android:name="com.here.android.mpa.service.MapService"
android:label="HereMapService"
android:process="global.Here.Map.Service.v3"
android:exported="true">
<intent-filter>
<action android:name="com.here.android.mpa.service.MapService.v3">
</action>
</intent-filter>
</service>
</application>
I also tried to use
android:process="global.Here.Map.Service.v2"
with
android:name="com.here.android.mpa.service.MapService"
or
android:name="com.here.android.mpa.service.MapService.v2"
Or any other such combination.
What am I missing?
As you can see, I've been struggleing with this for a couple of days now ;)
Thank you very much for your help. It is greatly appreciated.
The applicationId has to match the registered name exactly (in your case com.example.workywork). Otherwise, I can't spot an issue with the code you've posted.
You can try following this guide: Creating a Simple Application Using the HERE SDK
Related
viewOverride as you leave the webview
public boolean shouldOverrideUrlLoading (WebView view, String url)}} coding Saw writing webview did not go out.The application works if I go to google and click on the map. I need to intent the application and go to google map scroll
public class MainActivity extends Activity {
/**
* WebViewClient subclass loads all hyperlinks in the existing WebView
*/
public class GeoWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("tel:")) {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
return true;
} else if (url.startsWith("mailto:")) {
url = url.replaceFirst("mailto:", "");
url = url.trim();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text").putExtra(Intent.EXTRA_EMAIL, new String[]{url});
startActivity(i);
return true;
}else {
if (url.startsWith("geo:")) {
Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(searchAddress);
return true;
} else {
view.loadUrl(url);
return true;
}
}
}
}
/**
* WebChromeClient subclass handles UI-related calls
* Note: think chrome as in decoration, not the Chrome browser
*/
public class GeoWebChromeClient extends WebChromeClient {
#Override
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
// Always grant permission since the app itself requires location
// permission and the user has therefore already granted it
callback.invoke(origin, true, false);
}
}
WebView mWebView;
/**
* Called when the activity is first created.
*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
// Brower niceties -- pinch / zoom, follow links in place
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setWebViewClient(new GeoWebViewClient());
// Below required for geolocation
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setGeolocationEnabled(true);
mWebView.setWebChromeClient(new GeoWebChromeClient());
mWebView.loadUrl("http://www.google.com");
}
#Override
public void onBackPressed() {
// Pop the browser back stack or exit the activity
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
Correct if you want to write anything in AndroidManifest and have a burqa if you know the answer
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="youngsterus.meo.app" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<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.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- We may use GPS but it's not required -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#drawable/ic_launcher"
android:label="GOOGLE"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
android:supportsRtl="true">
<activity
android:name="youngsterus.meo.app.MainActivity"
android:label="GOOGLE"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="geo"/>
<data android:scheme="google.navigation"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<!-- Filter for geo scheme geo -->
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="geo" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
My app is working on Android 8.1 or higher smoothly but application crashes when try to run on Android 5.0, 6.0 or lower than 8.0 version.
Tried to find the solution on internet but no relevant answer found.
Some time it shows some error on
This is the Logcat report:
04-16 16:20:22.416 3033-3059/com.silverfoxsoft.concretepumpandconstructioncalculator E/FirebaseInstanceId: Google Play services missing or without correct permission.
04-16 16:20:22.760 3033-3063/com.silverfoxsoft.concretepumpandconstructioncalculator E/ActivityThread: Failed to find provider info for com.google.android.gms.chimera
04-16 16:20:22.762 3033-3063/com.silverfoxsoft.concretepumpandconstructioncalculator E/DynamiteModule: Failed to load IDynamiteLoader from GmsCore: Application package com.google.android.gms not found
04-16 16:20:22.764 3033-3065/com.silverfoxsoft.concretepumpandconstructioncalculator E/DynamiteModule: Failed to load IDynamiteLoader from GmsCore: Application package com.google.android.gms not found
04-16 16:20:23.009 3033-3059/com.silverfoxsoft.concretepumpandconstructioncalculator E/FirebaseInstanceId: Google Play services missing or without correct permission.
04-16 16:20:23.104 3033-3033/com.silverfoxsoft.concretepumpandconstructioncalculator E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.silverfoxsoft.concretepumpandconstructioncalculator, PID: 3033
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.silverfoxsoft.concretepumpandconstructioncalculator/com.silverfoxsoft.concretepumpandconstructioncalculator.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class androidx.appcompat.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class androidx.appcompat.widget.Toolbar
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.silverfoxsoft.concretepumpandconstructioncalculator.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.silverfoxsoft.concretepumpandconstructioncalculator.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: Resource "com.silverfoxsoft.concretepumpandconstructioncalculator:drawable/tape" (7f0700d4) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0700d4 a=-1 r=0x7f0700d4}
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2390)
at android.content.res.Resources.loadDrawable(Resources.java:2330)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3730)
at android.view.ViewGroup.<init>(ViewGroup.java:491)
at android.view.ViewGroup.<init>(ViewGroup.java:487)
at androidx.appcompat.widget.Toolbar.<init>(Toolbar.java:236)
at androidx.appcompat.widget.Toolbar.<init>(Toolbar.java:232)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:916)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:802)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.silverfoxsoft.concretepumpandconstructioncalculator.MainActivity.onCreate(MainActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
04-16 16:20:23.962 3033-3059/com.silverfoxsoft.concretepumpandconstructioncalculator E/FirebaseInstanceId: Google Play services missing or without correct permission.
04-16 16:20:24.029 3033-3059/com.silverfoxsoft.concretepumpandconstructioncalculator E/FirebaseInstanceId: Google Play services missing or without correct permission.
04-16 16:20:24.033 3033-3059/com.silverfoxsoft.concretepumpandconstructioncalculator E/FirebaseInstanceId: Google Play services missing or without correct permission.
Showing an error on (MainActivity.java:41) as well. but why?
My MainActivity.java File is here:
package com.silverfoxsoft.concretepumpandconstructioncalculator;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import android.view.MenuItem;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.messaging.FirebaseMessaging;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private long backPressedTime;
private AppBarConfiguration mAppBarConfiguration;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel =
new NotificationChannel("Mynotification", "MyNotification", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager = getSystemService(NotificationManager.class);
assert manager != null;
manager.createNotificationChannel(channel);
}
FirebaseMessaging.getInstance().subscribeToTopic("general")
.addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
String msg = "Connected to Firebase!";
if (!task.isSuccessful()) {
msg = "Failed";
}
//Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Email your feedback or suggestion", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
Toast.makeText(MainActivity.this,
"Select Email option only!", Toast.LENGTH_LONG).show();
//Thread.sleep(2000);
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
String[] address = {"silverfoxsofts#gmail.com"};
email.putExtra(Intent.EXTRA_EMAIL, address);
email.putExtra(Intent.EXTRA_SUBJECT, "Feed Back/Suggestion for MIXO - Construction Manager App");
email.putExtra(Intent.EXTRA_TEXT, "\nType your feedback or suggestion here.\n\n");
startActivity(email);
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow,
R.id.nav_tools, R.id.nav_share, R.id.nav_send)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
}
#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 onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
#Override
public void onBackPressed() {
if(backPressedTime + 2000 > System.currentTimeMillis()) {
super.onBackPressed();
} else {
Toast.makeText(MainActivity.this,
"Press back again to exit", Toast.LENGTH_LONG).show();
}
backPressedTime = System.currentTimeMillis();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_settings:
Toast.makeText(MainActivity.this,
"Privacy Policy", Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, Privacy_Policy.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
}
Manifests file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.silverfoxsoft.concretepumpandconstructioncalculator">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<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=".Volume_Calculation_Cylinder"></activity>
<activity android:name=".Area_Converter" />
<activity android:name=".Area_Calculator" />
<activity android:name=".Volume_Calculator" />
<activity android:name=".Volume_Converter" />
<activity android:name=".Torque_converter" />
<activity android:name=".Length_Converter" />
<activity android:name=".Lpm_to_Gpm" />
<activity android:name=".Bar_to_PSI" />
<activity android:name=".Accumulator" />
<activity android:name=".SpareConsumption" />
<activity android:name=".Slide_Sales_Reporting" />
<activity android:name=".ServiceReport" />
<activity android:name=".Hyd_vs_Concrete_Pressure" />
<activity android:name=".Slurry_Calculation" />
<activity android:name=".Pipe_Line_Calculation" />
<activity android:name=".OnSIte_Pressure_Calculation" />
<activity android:name=".Capacity_Of_Pump" />
<activity android:name=".Friction_Factor" />
<activity android:name=".DataLogger" />
<activity android:name=".Ampacity" />
<activity android:name=".VA_to_Watts" />
<activity android:name=".MAh_to_Wh" />
<activity android:name=".Kw_to_KWh" />
<activity android:name=".KvaToWatts" />
<activity android:name=".VoltageDrop" />
<activity android:name=".WireGauge" />
<activity android:name=".PowerFactor" />
<activity android:name=".Electron_Volts" />
<activity android:name=".Energy_consumption" />
<activity android:name=".Amps_To_Voltage" />
<activity android:name=".Joule_To_Watt" />
<activity android:name=".AmpsToKVA" />
<activity android:name=".kW_to_HP" />
<activity android:name=".ampsToKW" />
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name=".Privacy_Policy" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/cap" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<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>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-4613380677660687~9880768728" />
</application>
</manifest>
(Build.gradle)Project Level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
(Build.gradle)App Level
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.silverfoxsoft.concretepumpandconstructioncalculator"
minSdkVersion 19
targetSdkVersion 29
versionCode 3
versionName "1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation 'com.google.firebase:firebase-messaging:20.1.5'
implementation 'com.google.android.gms:play-services-ads:19.0.1'
implementation 'com.google.android.gms:play-services-base:17.2.1'
implementation 'com.google.android.gms:play-services-location:17.0.0'
}
What am I doing wrong?
I already publish this app on google play store:
You can check it # https://play.google.com/store/apps/details?id=com.silverfoxsoft.concretepumpandconstructioncalculator
The problem is not the API you are targeting, the problem is in your toolbar
Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class androidx.appcompat.widget.Toolbar
And the reason is
Caused by: android.content.res.Resources$NotFoundException: Resource "com.silverfoxsoft.concretepumpandconstructioncalculator:drawable/tape" (7f0700d4) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0700d4 a=-1 r=0x7f0700d4}
I'm trying to implement Firebase Cloud messaging on my App, using Kotlin.
In MyFirebaseMessagingService.kt I get the message "MyFirebaseMessagingService is not registered in the manifest,
Also, my app keeps stopping when built.
I have spend whole day searching for solution but haven't found one yet.
I tried adding several services but with no success.
(like: "MyFirebaseMessagingService"
".MyFirebaseMessagingService"
".java.MyFirebaseMessagingService"
".firebase.MyFirebaseMessagingService"
AndroidManifest.xml
<service
android:name="MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>`
MyFirebaseMessagingService.kt
import android.annotation.SuppressLint
import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import android.app.NotificationManager
import android.media.RingtoneManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.example.recapp.MainActivity
import com.example.recapp.R
import com.google.firebase.iid.InstanceIdResult
import com.google.android.gms.tasks.OnSuccessListener
import com.google.firebase.iid.FirebaseInstanceId
class MyFirebaseMessagingService : FirebaseMessagingService(){
val TAG = "FirebaseMessagingService"
override fun onNewToken(token: String) {
Log.d("New_Token", token)
}
#SuppressLint("LongLogTag")
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
Log.d(TAG, "Poruka: ${remoteMessage.from}")
if (remoteMessage.notification != null) {
Log.d(TAG, "Sadrzaj: ${remoteMessage.notification?.body}")
sendNotification(remoteMessage)
}
}
private fun sendNotification(remoteMessage: RemoteMessage) {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this#MyFirebaseMessagingService, 0, intent, PendingIntent.FLAG_ONE_SHOT)
val soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this#MyFirebaseMessagingService, "Notification")
.setSmallIcon(com.example.recapp.R.mipmap.ic_launcher)
.setContentTitle("Poruka")
.setContentText(remoteMessage.notification?.body)
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0, notificationBuilder.build())
}
}
App builds with no errors, but keeps stopping when built.
Build gradle (myApp) is ok?:
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.0'
Build gradle (app) is ok?:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
You have to declare the full name of your service. For example, if your service is in package com.example then it will be com.example.MyFirebaseMessagingService
<service
android:name="com.example.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
this is my firebase depedencies in build.gradle level app :
implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.google.firebase:firebase-core:17.4.3'
implementation 'com.google.firebase:firebase-iid:20.2.1'
implementation 'com.google.firebase:firebase-messaging:20.2.1'
and in Manifest
<service
android:name = "com.aplikasipdam.lampupanggungcirebon.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
I tries to use Firebase Cloud Messaging for my app, and I coded follow guide "https://firebase.google.com/docs/cloud-messaging/android/client" to get device tooken
MainActivity:
FirebaseApp.initializeApp(this);
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
#Override
public void onComplete(#NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w("FCM", "getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
// Log and toast
String msg = getString(R.string.msg_token_fmt, token);
Log.d("FCM", msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.triaxlogistic.myapplication"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
useLibrary 'org.apache.http.legacy'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.libraries.places:places:1.0.0'
implementation 'com.facebook.android:account-kit-sdk:5.0.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.android.volley:volley:1.1.0'
implementation 'net.gotev:uploadservice:2.1'
testImplementation 'junit:junit:4.12'
core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
AndroidManifest
<service android:name=".utilities.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
MyFirebaseMessagingService
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
//TODO: xu ly thong bao co du lieu
if (remoteMessage.getData().size() > 0) {
sendNotification(remoteMessage.getData());
}
//TODO: xu ly thong bao tin thong thuong
if (remoteMessage.getNotification() != null) {
sendNotificationBody(remoteMessage.getNotification().getBody());
}
}
#Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);
sendRegistrationToServer(token);
}
....
But when I run test on my device mobile, get issue in log:"
D/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.triaxlogistic.myapplication, PID: 32022
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.triaxlogistic.myapplication/com.triaxlogistic.myapplication.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.triaxlogistic.myapplication. Make sure to call FirebaseApp.initializeApp(Context) first."
I don't know what I did wrong, even though I was
add Firebase to my Android app in my project on the Firebase Console, and filled value the package name, value debug debugging certificate SHA1; download the latest json config file and copy to my project in Android studio.
How to fix it?
I'm developing an application on Xamarin.Forms. I'm using the following plug-in to get push notifications from Firebase. I'm working on a MacBook.
FirebasePushNotificationPlugin
https://github.com/CrossGeeks/FirebasePushNotificationPlugin
I tried;
Many times clean & rebuild solution
Many times delete bin and obj folders.
error: package com.google.firebase.messaging does not exist
This has not a solution. It's same with me.
https://github.com/CrossGeeks/FirebasePushNotificationPlugin/issues/153
There is no problem with iOS, but I get the error on Android.
Error: com.google.firebase.messaging package com.google.firebase.messaging.FirebaseMessagingService
and second error;
/Users/Username/Projects/MyProject/MyProject.Android/obj/Debug/android/src/md5f94c48bc84b2956c5a5be24cbc1fa7f2/PNFirebaseMessagingService.java(7,7): Error: error: cannot find symbol if (getClass () == PNFirebaseMessagingService.class) symbol: method getClass() location: class PNFirebaseMessagingService (MyProject.Android)
My Nuget packages are up to date. I couldn't figure out this error on the Android side, thank you.
First: the library you post is really outdated (2+ years). You should use Xamarin.Firebase.Messaging.
Second: don't forget to add the google-services.json file on Android folder and GoogleService-Info.plist on iOS folder and set the Build Action as GoogleServiceJson.
Third: You must have a way to detect if the phone has Google Play Services enabled.
So you must add this on the AndroidManifest:
<application android:label="YourAppName">
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
android:exported="false" />
<receiver
android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
android:exported="true"
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="${applicationId}" />
</intent-filter>
</receiver>
</application>
Then create a service:
namespace YourAppName.Droid
{
[Service]
[IntentFilter(new [] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class FirebaseService : FirebaseInstanceIdService
{
const string TAG = "MyFirebaseIIDService";
public override void OnTokenRefresh()
{
var refreshedToken = FirebaseInstanceId.Instance.Token;
Log.Debug(TAG, "Refreshed token: " + refreshedToken);
SendRegistrationToServer(refreshedToken);
}
void SendRegistrationToServer(string token)
{
// Add custom implementation, as needed.
}
}
}
And last, add this method on your MainActivity and call it on the OnCreate method:
public bool CheckForGoogleServices()
{
int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.Success)
{
if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode))
{
Toast.MakeText(this, GoogleApiAvailability.Instance.GetErrorString(resultCode), ToastLength.Long);
}
else
{
Toast.MakeText(this, "This device does not support Google Play Services", ToastLength.Long);
}
return false;
}
return true;
}
In some android devices Google Play Services are not installed, so we need to ensure the user knows if can receieve push notifications.
And remember if you're using android emulator, install it Google Play Service on it.