i have build a class, based on firebasenotifications source, like this
i´m not sure about
as i do not see them used somewhere.
but when i try to build the manifest like this
it does not work. I´m not sure here if the implementation or the manifest is wrong
I´m fighing with this error
Any hints on how to setup the manifest correctly are highly welcome ;-)
B4X:
/*
* Copyright 2010 - 2020 Anywhere Software (www.b4x.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package anywheresoftware.b4a.objects;
import com.amazon.device.messaging.ADMMessageHandlerBase;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.ShortName;
@Hide
public class AmazonNotificationsService extends ADMMessageHandlerBase {
protected AmazonNotificationsService(String className) {
super(className);
}
private static boolean firstMessage = true;
private static Handler handler;
private static Class<?> ServiceClass;
private static Class<?> ReceiverClass;
public SampleADMMessageReceiver amazonmessagingbr;
@Override
public void onCreate() {
super.onCreate();
try {
handler = new Handler();
ServiceClass = Class.forName(getPackageName() + ".amazonmessaging");
ReceiverClass = Class.forName(getPackageName() + ".amazonmessaging$amazonmessaging_BR");
} catch (ClassNotFoundException e) {
e.printStackTrace();
BA.LogError("AmazonMessaging not found.");
}
IntentFilter filter = new IntentFilter();
filter.addAction("com.amazon.device.messaging.intent.REGISTRATION");
filter.addAction("com.amazon.device.messaging.intent.RECEIVE");
filter.addCategory(getPackageName());
amazonmessagingbr = new SampleADMMessageReceiver();
registerReceiver(amazonmessagingbr, filter);
}
public static Intent createIntent(Service me, String event, String value) {
Intent i;
i = new Intent(me, ReceiverClass);
i.setAction("b4a_amazonmessaging");
i.putExtra("event", event);
return i;
}
// @Hide
// public static class InstanceService extends FirebaseInstanceIdService {
// @Override
// public void onTokenRefresh() {
// sendBroadcast(createIntent(this, "b4a_tokenrefresh"));
// }
// }
// @DependsOn(values={"com.google.firebase:firebase-messaging",
// "com.google.firebase:firebase-installations"})
@ShortName("AmazonMessaging")
// @Events(values={"TokenRefresh (Token As String)", "MessageArrived (Message
// As RemoteMessage)"})
public static class AmazonMessageWrapper {
private BA ba;
private String eventName;
public void Initialize(BA ba, String EventName) {
this.ba = ba;
this.eventName = EventName.toLowerCase(BA.cul);
}
// /**
// * Should be called from Service_Start. Returns true if the intent was
// handled.
// */
// public boolean HandleIntent(Intent Intent) {
// if (Intent == null || "b4a_firebasemessaging".equals(Intent.getAction())
// == false)
// return false;
// Intent.setExtrasClassLoader(RemoteMessage.class.getClassLoader());
// String event = Intent.getStringExtra("event");
// if (event.equals("b4a_tokenrefresh"))
// ba.raiseEventFromUI(this, eventName + "_tokenrefresh", getToken());
// else if (event.equals("b4a_messagereceived")) {
// RemoteMessage rm = Intent.getParcelableExtra("message");
// ba.raiseEventFromUI(this, eventName + "_messagearrived",
// AbsObjectWrapper.ConvertToWrapper(new RemoteMessageWrapper(), rm));
// }
// return true;
// }
// /**
// * Returns the device token. The token can change from time to time. The
// TokenRefresh event is raised when the token changes.
// *The token is only needed when sending messages to a specific device.
// */
// public String getToken() {
// return BA.returnString(FirebaseInstanceId.getInstance().getToken());
// }
// /**
// * Subscribes to the specified topic.
// *Example:<code>
// *fm.SubscribeToTopic("general")</code>
// */
// public void SubscribeToTopic(String Topic) {
// getObject().subscribeToTopic(Topic);
// }
// /**
// * Unsubscribes from a topic.
// */
// public void UnsubscribeFromTopic(String Topic) {
// getObject().unsubscribeFromTopic(Topic);
// }
//
// }
// /**
// * Holds the push message data.
// */
// @ShortName("RemoteMessage")
// public static class RemoteMessageWrapper extends
// AbsObjectWrapper<RemoteMessage> {
// /**
// * Gets the collapse key (if set).
// */
// public String getCollapseKey() {
// return BA.returnString(getObject().getCollapseKey());
// }
// /**
// * Returns the sender id or the topic name. In the later case the value
// will start with /topics/
// */
// public String getFrom() {
// return BA.returnString(getObject().getFrom());
// }
// /**
// * Gets the message id.
// */
// public String getMessageId() {
// return getObject().getMessageId();
// }
// /**
// * Returns the time the message was sent.
// */
// public long getSentTime() {
// return getObject().getSentTime();
// }
// /**
// * Returns a Map with the key / values set as the message data.
// */
// public Map GetData() {
// Map m = new Map();
// m.Initialize();
// if (getObject().getData() != null) {
// for (Entry<String, String> e : getObject().getData().entrySet()) {
// m.Put(e.getKey(), e.getValue());
// }
// }
// return m;
// }
// // public String getNotificationBody() {
// // Notification n = getObject().getNotification();
// // if (n == null)
// // return "";
// // return BA.returnString(n.getBody());
// // }
// // public String getNotificationTitle() {
// // Notification n = getObject().getNotification();
// // if (n == null)
// // return "";
// // return BA.returnString(n.getTitle());
// // }
//
// }
}
@Override
protected void onMessage(Intent intent) {
BA.Log("AmazonNotificationsService.OnMessage("+intent+")");
// TODO Auto-generated method stub
if (intent == null || "b4a_amazonmessaging".equals(intent.getAction()) == false) {
} else {
BA.applicationContext.sendBroadcast(createIntent(this, "b4a_onmessage",intent.getAction()));
}
}
@Override
protected void onRegistered(String arg0) {
BA.Log("AmazonNotificationsService.OnRegistered("+arg0+")");
// TODO Auto-generated method stub
BA.applicationContext.sendBroadcast(createIntent(this, "b4a_onregistered",arg0));
}
@Override
protected void onRegistrationError(String arg0) {
// TODO Auto-generated method stub
BA.Log("AmazonNotificationsService.OnRegistrationError("+arg0+")");
BA.applicationContext.sendBroadcast(createIntent(this, "b4a_onerror",arg0));
}
@Override
protected void onUnregistered(String arg0) {
// TODO Auto-generated method stub
BA.Log("AmazonNotificationsService.OnUnRegistered("+arg0+")");
BA.applicationContext.sendBroadcast(createIntent(this, "b4a_onunregistered",arg0));
}
}
i´m not sure about
B4X:
ServiceClass = Class.forName(getPackageName() + ".amazonmessaging");
ReceiverClass = Class.forName(getPackageName() + ".amazonmessaging$amazonmessaging_BR");
but when i try to build the manifest like this
B4X:
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
SetManifestAttribute(xmlns:amazon,"http://schemas.amazon.com/apk/res/android")
AddApplicationText(<amazon:enable-feature android:name="com.amazon.device.messaging" android:required="true"/>)
AddApplicationText(
<service
android:name="anywheresoftware.b4a.objects.AmazonNotificationsService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false" />
)
AddApplicationText(
<receiver
android:name="anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessagingbr"
android:permission="com.amazon.device.messaging.permission.SEND" >
<intent-filter>
<action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
<action android:name="com.amazon.device.messaging.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
<category android:name="${applicationId}" />
</receiver>
)
AddManifestText(
<permission android:name="${applicationId}.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.RECEIVE_ADM_MESSAGE" />
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
)
I´m fighing with this error
Logger connected to: Amazon AFTT
--------- beginning of system
Successfully loaded all classes
Successfully loaded all methods
Successfully loaded all fields
Successfully loaded all classes
Successfully loaded all methods
Successfully loaded all fields
Successfully loaded all classes
Successfully loaded all methods
Successfully loaded all fields
--------- beginning of main
Shutting down VM
java.lang.RuntimeException: Unable to instantiate receiver anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR: java.lang.ClassNotFoundException: Didn't find class "anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR" on path: DexPathList[[zip file "/data/app/de.donmanfred.admtest-1/base.apk", zip file "/system/priv-app/DeviceMessagingAndroidSDK/DeviceMessagingAndroidSDK.apk", zip file "/system/priv-app/MetricsApi/MetricsApi.apk", zip file "/system/priv-app/com.amazon.dp.logger/com.amazon.dp.logger.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2750)
at android.app.ActivityThread.access$1700(ActivityThread.java:160)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5597)
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:984)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.ClassNotFoundException: Didn't find class "anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR" on path: DexPathList[[zip file "/data/app/de.donmanfred.admtest-1/base.apk", zip file "/system/priv-app/DeviceMessagingAndroidSDK/DeviceMessagingAndroidSDK.apk", zip file "/system/priv-app/MetricsApi/MetricsApi.apk", zip file "/system/priv-app/com.amazon.dp.logger/com.amazon.dp.logger.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2745)
... 9 more
Suppressed: java.lang.ClassNotFoundException: anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 11 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
--------- beginning of crash
FATAL EXCEPTION: main
Process: de.donmanfred.admtest, PID: 22697
java.lang.RuntimeException: Unable to instantiate receiver anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR: java.lang.ClassNotFoundException: Didn't find class "anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR" on path: DexPathList[[zip file "/data/app/de.donmanfred.admtest-1/base.apk", zip file "/system/priv-app/DeviceMessagingAndroidSDK/DeviceMessagingAndroidSDK.apk", zip file "/system/priv-app/MetricsApi/MetricsApi.apk", zip file "/system/priv-app/com.amazon.dp.logger/com.amazon.dp.logger.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2750)
at android.app.ActivityThread.access$1700(ActivityThread.java:160)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5597)
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:984)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: java.lang.ClassNotFoundException: Didn't find class "anywheresoftware.b4a.objects.AmazonNotificationsService.amazonmessaging$amazonmessaging_BR" on path: DexPathList[[zip file "/data/app/de.donmanfred.admtest-1/base.apk", zip file "/system/priv-app/DeviceMessagingAndroidSDK/DeviceMessagingAndroidSDK.apk", zip file "/system/priv-app/MetricsApi/MetricsApi.apk", zip file "/system/priv-app/com.amazon.dp.logger/com.amazon.dp.logger.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2745)
... 9 more
Any hints on how to setup the manifest correctly are highly welcome ;-)
Last edited: