Example #1
0
  /** Issues a notification to inform the user that server has sent a message. */
  public void generateNotification(Context context, String message) {
    int icon = R.drawable.ingine;
    long when = System.currentTimeMillis();
    ComponentName myService = new ComponentName(this, this.getClass());
    String activityName = null;
    try {
      Bundle data =
          getPackageManager().getServiceInfo(myService, PackageManager.GET_META_DATA).metaData;
      App42Log.debug(" Message Activity Name : " + data.getString("onMessageOpen"));
      activityName = data.getString("onMessageOpen");
    } catch (NameNotFoundException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    NotificationManager notificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent;
    try {
      notificationIntent = new Intent(context, Class.forName(activityName));
      notificationIntent.putExtra("message_delivered", true);
      notificationIntent.putExtra(EXTRA_MESSAGE, message);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      notificationIntent = new Intent(context, UtilMenu.class);
    }
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification =
        new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setContentText(message)
            .setContentIntent(intent)
            .setSmallIcon(icon)
            .setWhen(when)
            .setNumber(++msgCount)
            .setLargeIcon(getBitmapFromURL(LARGE_IMAGE_URL))
            .setLights(Color.YELLOW, 1, 2)
            .setAutoCancel(true)
            .build();

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);
  }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   super.requestWindowFeature(Window.FEATURE_NO_TITLE);
   setContentView(R.layout.activity_main);
   responseTv = ((TextView) findViewById(R.id.response_msg));
   edUserName = ((EditText) findViewById(R.id.uname));
   edMessage = ((EditText) findViewById(R.id.message));
   buildSpinnerLayout();
   App42API.initialize(this, "Your API Key", "Your Secret Key");
   App42Log.setDebug(true);
   // UserName You want to register on App42
   App42API.setLoggedInUser("YourUserName");
 }
Example #3
0
  private void registerWithApp42(String regId) {
    App42Log.debug(" Registering on Server ....");
    App42API.buildPushNotificationService()
        .storeDeviceToken(
            App42API.getLoggedInUser(),
            regId,
            new App42CallBack() {
              @Override
              public void onSuccess(Object paramObject) {
                // TODO Auto-generated method stub
                App42Log.debug(" ..... Registeration Success ....");
                GCMRegistrar.setRegisteredOnServer(App42API.appContext, true);
              }

              @Override
              public void onException(Exception paramException) {
                App42Log.debug(" ..... Registeration Failed ....");
                App42Log.debug("storeDeviceToken :  Exception : on start up " + paramException);
              }
            });
  }
Example #4
0
  private void uploadScoresleaderboard() {

    final ListView listView = (ListView) findViewById(android.R.id.list);
    App42Log.setDebug(true);

    String gameName = "Ultipedia fun";

    int max = 15;
    App42API.initialize(
        this,
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");
    ScoreBoardService scoreBoardService = App42API.buildScoreBoardService();
    scoreBoardService.getTopNRankings(
        gameName,
        max,
        new App42CallBack() {
          public void onSuccess(Object response) {
            Game game = (Game) response;
            ArrayList e = game.getScoreList();

            System.out.println("Game Name is : " + game.getName());
            for (int i = 0; i < game.getScoreList().size(); i++) {
              System.out.println("userName is : " + game.getScoreList().get(i).getUserName());
              System.out.println("score is : " + game.getScoreList().get(i).getValue());
              System.out.println("Created On is  :" + game.getScoreList().get(i).getCreatedOn());
              System.out.println("scoreId is : " + game.getScoreList().get(i).getScoreId());
            }
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });

    // TODO Auto-generated method stub

  }