diff --git a/buildozer.spec.arm.ci b/buildozer.spec.arm.ci index 9ed05d68..53dc11ad 100644 --- a/buildozer.spec.arm.ci +++ b/buildozer.spec.arm.ci @@ -148,7 +148,7 @@ android.react_src = ./app # (list) Gradle dependencies to add (currently works only with sdl2_gradle # bootstrap) -android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0 +android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0, com.google.firebase:firebase-messaging:18.0.0 # (str) python-for-android branch to use, defaults to master #p4a.branch = stable diff --git a/buildozer.spec.arm64.ci b/buildozer.spec.arm64.ci index 36fa035e..a019b0d2 100644 --- a/buildozer.spec.arm64.ci +++ b/buildozer.spec.arm64.ci @@ -148,7 +148,7 @@ android.react_src = ./app # (list) Gradle dependencies to add (currently works only with sdl2_gradle # bootstrap) -android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0 +android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0, com.google.firebase:firebase-messaging:18.0.0 # (str) python-for-android branch to use, defaults to master #p4a.branch = stable diff --git a/buildozer.spec.sample b/buildozer.spec.sample index bb830caf..4b524077 100644 --- a/buildozer.spec.sample +++ b/buildozer.spec.sample @@ -148,7 +148,7 @@ android.react_src = ./app # (list) Gradle dependencies to add (currently works only with sdl2_gradle # bootstrap) -android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0 +android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0, com.google.firebase:firebase-messaging:18.0.0 # (str) python-for-android branch to use, defaults to master #p4a.branch = stable diff --git a/buildozer.spec.vagrant b/buildozer.spec.vagrant index a90031c8..cd4631b9 100644 --- a/buildozer.spec.vagrant +++ b/buildozer.spec.vagrant @@ -148,7 +148,7 @@ android.react_src = ./app # (list) Gradle dependencies to add (currently works only with sdl2_gradle # bootstrap) -android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0 +android.gradle_dependencies = com.android.support:support-v4:28.0.0, com.android.support:support-media-compat:28.0.0, com.android.support:appcompat-v7:28.0.0, com.facebook.react:react-native:0.59.10, com.google.android.gms:play-services-gcm:11.0.4+, com.facebook.fresco:fresco:1.9.0, com.facebook.fresco:animated-gif:1.9.0, com.squareup.picasso:picasso:2.71828, com.google.firebase:firebase-core:16.0.1, com.google.android.gms:play-services-base:16.1.0, com.android.support:exifinterface:28.0.0, com.facebook.fresco:animated-base-support:1.3.0, com.facebook.fresco:animated-gif:1.10.0, com.google.firebase:firebase-messaging:18.0.0 # (str) python-for-android branch to use, defaults to master #p4a.branch = stable diff --git a/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml b/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml index 92a0dbb7..0d244d06 100644 --- a/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml +++ b/p4a/pythonforandroid/bootstraps/lbry/build/templates/AndroidManifest.tmpl.xml @@ -58,6 +58,16 @@ android:hardwareAccelerated="true" android:usesCleartextTraffic="true"> + + + + {% for m in args.meta_data %} {% endfor %} @@ -131,6 +141,14 @@ + + + + + + {% if args.billing_pubkey %} diff --git a/p4a/pythonforandroid/bootstraps/lbry/build/templates/strings.tmpl.xml b/p4a/pythonforandroid/bootstraps/lbry/build/templates/strings.tmpl.xml index 8e1abff8..d3df3120 100644 --- a/p4a/pythonforandroid/bootstraps/lbry/build/templates/strings.tmpl.xml +++ b/p4a/pythonforandroid/bootstraps/lbry/build/templates/strings.tmpl.xml @@ -4,7 +4,8 @@ {{ private_version }} {{ args.presplash_color }} {{ url_scheme }} - + io.lbry.browser.LBRY_ENGAGEMENT_CHANNEL + Running Service Status Stopped diff --git a/src/main/java/io/lbry/browser/LbrynetMessagingService.java b/src/main/java/io/lbry/browser/LbrynetMessagingService.java new file mode 100644 index 00000000..958d0e15 --- /dev/null +++ b/src/main/java/io/lbry/browser/LbrynetMessagingService.java @@ -0,0 +1,93 @@ +package io.lbry.browser; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; +import android.os.Build; +import android.support.v4.app.NotificationCompat; +import android.support.v4.content.ContextCompat; +import android.util.Log; + +import com.google.firebase.messaging.FirebaseMessagingService; +import com.google.firebase.messaging.RemoteMessage; + +public class LbrynetMessagingService extends FirebaseMessagingService { + + private static final String TAG = "LbrynetMessagingService"; + + private static final String NOTIFICATION_CHANNEL_ID = "io.lbry.browser.LBRY_ENGAGEMENT_CHANNEL"; + + @Override + public void onMessageReceived(RemoteMessage remoteMessage) { + Log.d(TAG, "From: " + remoteMessage.getFrom()); + + // Check if message contains a notification payload. + RemoteMessage.Notification remoteNotification = remoteMessage.getNotification(); + if (remoteNotification != null) { + Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); + sendNotification(remoteNotification.getTitle(), remoteNotification.getBody()); + } + } + + @Override + public void onNewToken(String token) { + Log.d(TAG, "Refreshed token: " + token); + + // If you want to send messages to this application instance or + // manage this apps subscriptions on the server side, send the + // Instance ID token to your app server. + sendRegistrationToServer(token); + } + + /** + * Persist token to third-party servers. + * + * Modify this method to associate the user's FCM InstanceID token with any server-side account + * maintained by your application. + * + * @param token The new token. + */ + private void sendRegistrationToServer(String token) { + // TODO: Implement this method to send token to your app server. + } + + /** + * Create and show a simple notification containing the received FCM message. + * + * @param messageBody FCM message body received. + */ + private void sendNotification(String title, String messageBody) { + Intent intent = new Intent(this, MainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + // TODO: Update pending intent based on notification data (eg. open a LBRY URI or the Rewards page?) + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, + PendingIntent.FLAG_ONE_SHOT); + + Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); + NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) + .setColor(ContextCompat.getColor(this, R.color.lbryGreen)) + .setSmallIcon(R.drawable.ic_lbry) + .setContentTitle(title) + .setContentText(messageBody) + .setAutoCancel(true) + .setSound(defaultSoundUri) + .setContentIntent(pendingIntent); + + NotificationManager notificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + // Since android Oreo notification channel is needed. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel( + NOTIFICATION_CHANNEL_ID, "LBRY Engagement", NotificationManager.IMPORTANCE_DEFAULT); + notificationManager.createNotificationChannel(channel); + } + + notificationManager.notify(9898, notificationBuilder.build()); + } +} \ No newline at end of file diff --git a/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java b/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java index 38839a45..d75aacf1 100644 --- a/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java +++ b/src/main/java/io/lbry/browser/reactmodules/FirebaseModule.java @@ -11,6 +11,10 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableMap; import com.google.firebase.analytics.FirebaseAnalytics; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.iid.InstanceIdResult; import io.lbry.browser.BuildConfig; import io.lbry.browser.MainActivity; @@ -37,7 +41,7 @@ public class FirebaseModule extends ReactContextBaseJavaModule { public String getName() { return "Firebase"; } - + @ReactMethod public void setCurrentScreen(String name, final Promise promise) { final Activity activity = getCurrentActivity(); @@ -50,7 +54,7 @@ public class FirebaseModule extends ReactContextBaseJavaModule { } promise.resolve(true); } - + @ReactMethod public void track(String name, ReadableMap payload) { Bundle bundle = new Bundle(); @@ -86,4 +90,22 @@ public class FirebaseModule extends ReactContextBaseJavaModule { Toast.LENGTH_LONG).show(); } } + + @ReactMethod + public void getMessagingToken(final Promise promise) { + FirebaseInstanceId.getInstance().getInstanceId() + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(Task task) { + if (!task.isSuccessful()) { + promise.reject("getInstanceId failed"); + return; + } + + // Get new Instance ID token + String token = task.getResult().getToken(); + promise.resolve(token); + } + }); + } } \ No newline at end of file