s = 1
list = [1,2,3,4]
list2 = list if s in list else 0
print(list2) #[1, 2, 3, 4]が出力される
counts = [ list if s in list else 0 for a in range(10)]
print(counts) #[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], ...] [1,2,3,4]が10個あるリストが出力される
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d("MyFirebaseInstanceIDS", "Refreshed token: " + refreshedToken);
}
}
メッセージを受け取ったら、Logに表示するサービスも追加します。
MyFcmService.java
public class MyFcmService extends FirebaseMessagingService {
private static final String TAG = "MyFcmService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
if (/* Check if data needs to be processed by long running job */ true) {
// For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
//scheduleJob();
} else {
// Handle message within 10 seconds
handleNow();
}
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
/**
* Handle time allotted to BroadcastReceivers.
*/
private void handleNow() {
Log.d(TAG, "Short lived task is done.");
}
}
java.lang.RuntimeException: Unable to start receiver com.google.android.gcm.GCMBroadcastReceiver:
java.lang.IllegalStateException: Not allowed to start service Intent
{ act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=hogehoge.com cmp=hogehoge.com/.GCMIntentService (has extras) }: app is in background uid
// 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.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}