std :: bind不能使用字符串向量

时间:2016-01-26 15:17:01

标签: c++ c++11

有没有办法让这段代码编译?

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {



@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    Log.i("GcmBroadcast",intent.getExtras().toString());


    SharedPreferences settings = context.getSharedPreferences("MyPrefsFile", 0);



        if (settings.getBoolean("my_first_time", true)) {
            //the app is being launched for first time, do something        

                  //do nothing

            // record the fact that the app has been started at least once
            settings.edit().putBoolean("my_first_time", false).commit(); 
        }else{
            ComponentName comp = new ComponentName(context.getPackageName(),
                   GcmIntentService.class.getName());
                // Start the service, keeping the device awake while it is launching.

            startWakefulService(context, (intent.setComponent(comp)));
            setResultCode(Activity.RESULT_OK);
        }

    }
}

g1工作正常,g2给出了一些复杂的编译错误

修改 根据受欢迎的要求,我给你错误:

public class GcmIntentService extends IntentService {

private String TAG = "GcmIntent";
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;

public GcmIntentService() {
    super("GcmIntentService");
}

@Override
public void onCreate(){
    super.onCreate();
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    onHandleIntent(intent);
    return START_STICKY;
}



@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    Log.i(TAG, "Received: " + extras.toString());
    String messageType = gcm.getMessageType(intent);

    Log.i(TAG, "Message type:" + messageType);
    if (!extras.isEmpty()) {  // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM
         * will be extended in the future with new message types, just ignore
         * any message types you're not interested in, or that you don't
         * recognize.
         */
         if (GoogleCloudMessaging.
                MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.

             sendNotification(extras.getString("message"), extras.getString("title"));

             Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

// Put the message into a notification and post it.
// This is just one simple example of what you might choose to do with
// a GCM message.
private void sendNotification(String msg, String title) {
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);
    if(title.isEmpty()){
        title="Happy Hour plus";
    }

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, SplashScreen.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_stat_notification)
    .setContentTitle(title)
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(msg))
    .setContentText(msg)
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
    .setVibrate(new long[] {250,250,250,250})
    .setAutoCancel(true);


    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

}

public boolean checkApp(){
    ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);

    // get the info from the currently running task
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

    ComponentName componentInfo = taskInfo.get(0).topActivity;
    if (componentInfo.getPackageName().equalsIgnoreCase("com.happyhour.main")) {
        return true;
        } else {
            return false;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

#include <functional>
#include <vector>
#include <iostream>
using namespace std;
void f1(int x, int y){}
void f2(int x, vector<string> v) {}
int main ()
{
    f2(2, {{"hello", "it's", "me"}});
    auto g1 = bind(f1, placeholders::_1, 3); 
    auto g2 = bind(f2, placeholders::_1, vector<string>{{"hello", "it's", "me"}});
    return 0;
}