Android Open Source - friendica-for-android G C M Intent Service






From Project

Back to project page friendica-for-android.

License

The source code is released under:

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

If you think the Android project friendica-for-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.wikilab.android.friendica01;
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
/*from  www.  jav a2  s . c o m*/
import com.google.android.gcm.GCMBaseIntentService;

import de.wikilab.android.friendica01.activity.HomeActivity;

public class GCMIntentService extends GCMBaseIntentService {
  private static final String TAG = "Friendica.GCMIntentService";
  
  public GCMIntentService() {
    super(HomeActivity.SENDER_ID);
    Log.i(TAG,"instance of GCMIntentService created");
  }
  
  @Override
  protected void onError(Context arg0, String arg1) {
    Log.e(TAG,"onError got called!!! "+arg1);
    Toast.makeText(arg0, arg1, Toast.LENGTH_LONG).show();
  }

  private void setNotificationProps(Intent i, Context ctx, Notification nb) {
    //String type = i.getStringExtra("cat")+"."+i.getStringExtra("type")+"."+i.getStringExtra("subtype");
    
    String contentTitle="",contentText="";
    
    //if (type.equals("USER.SHORTMESSAGE.")) {
    //  contentTitle=i.getStringExtra("actor_fullname") + " messaged you:"; contentText=i.getStringExtra("text");
    //} else if (type.equals("USER.POKE.")) {
    //  contentTitle=i.getStringExtra("actor_fullname") + " poked you"; contentText=null;
    //} else {
    //  contentTitle=i.getStringExtra("actor_fullname"); contentText=type;
    //}
    contentTitle = i.getStringExtra("name");

    contentText = "New Friendica Notification (" +  i.getStringExtra("otype") + ")";
    
    Intent notificationIntent = new Intent(ctx, HomeActivity.class);
    //for(String key : arg1.getExtras().keySet()) {
    //  notificationIntent.putExtra("MSG_" + key, arg1.getStringExtra(key));
    //}
    //notificationIntent.setFlags(Intent.FL)
    PendingIntent contentIntent = PendingIntent.getActivity(ctx,
        (int) (System.currentTimeMillis()/1000), notificationIntent, 0);
    //PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, null, 0);
    nb.setLatestEventInfo(ctx, contentTitle, contentText, contentIntent);
  }
  
  @Override
  protected void onMessage(Context ctx, Intent arg1) {
    Log.i(TAG, "Message received");
    Toast.makeText(ctx, "Test!!!", Toast.LENGTH_LONG).show();
    
    try {
      NotificationManager noti = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      
      Notification not = new Notification();
      //.setContentTitle(arg1.getStringExtra("cat")+"."+arg1.getStringExtra("type")+"."+arg1.getStringExtra("subtype"))
      //.setContentText(arg1.getStringExtra("actor_fullname"))
      setNotificationProps(arg1, ctx, not);
      not.vibrate = new long[]{0,200,100,400};
      not.icon = android.R.drawable.ic_popup_reminder;
      //.setAutoCancel(true)
      not.sound = Uri.parse("android.resource://de.wikilab.android.friendica01/" + R.raw.doorbell2);
      not.when = System.currentTimeMillis();
      
      noti.notify((int) (System.currentTimeMillis()/1000), not);
      
    } catch (Exception e) {
      Log.w(TAG, "exception in Message-receiver");
      e.printStackTrace();
    }
  }

  @Override
  protected void onRegistered(Context arg0, String registration_id) {
    Log.i(TAG, "onRegistered got called! :-)");
    Toast.makeText(arg0, "GCM Registration successful", Toast.LENGTH_SHORT).show();
    TwAjax regsvr = new TwAjax(arg0, true, true);
    regsvr.addPostData("registration_id", registration_id);
    regsvr.postData(Max.getServer(arg0) + "/api/gcm/register", null);
    Log.i(TAG, "gcmRegister returned "+regsvr.getResult());
  }

  @Override
  protected void onUnregistered(Context arg0, String registration_id) {
    Toast.makeText(arg0, "Unregistered from GCM", Toast.LENGTH_SHORT).show();
    TwAjax regsvr = new TwAjax(arg0, true, true);
    regsvr.addPostData("registration_id", registration_id);
    regsvr.postData(Max.getServer(arg0) + "/api/gcm/unregister", null);
    Log.i(TAG, "gcmUnregister returned "+regsvr.getResult());
  }

}




Java Source Code List

com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.java
com.handmark.pulltorefresh.library.PullToRefreshBase.java
com.handmark.pulltorefresh.library.PullToRefreshExpandableListView.java
com.handmark.pulltorefresh.library.PullToRefreshGridView.java
com.handmark.pulltorefresh.library.PullToRefreshListView.java
com.handmark.pulltorefresh.library.PullToRefreshWebView.java
com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor.java
com.handmark.pulltorefresh.library.internal.IndicatorLayout.java
com.handmark.pulltorefresh.library.internal.LoadingLayout.java
de.wikilab.android.friendica01.FileUploadService.java
de.wikilab.android.friendica01.FragmentParentListener.java
de.wikilab.android.friendica01.GCMIntentService.java
de.wikilab.android.friendica01.HtmlImageHelper.java
de.wikilab.android.friendica01.LoginListener.java
de.wikilab.android.friendica01.Max.java
de.wikilab.android.friendica01.NotificationCheckerService.java
de.wikilab.android.friendica01.Notification.java
de.wikilab.android.friendica01.TwAjax.java
de.wikilab.android.friendica01.ViewServer.java
de.wikilab.android.friendica01.activity.FriendicaImgUploadActivity.java
de.wikilab.android.friendica01.activity.GenericContentActivity.java
de.wikilab.android.friendica01.activity.HomeActivity.java
de.wikilab.android.friendica01.activity.MainScreenActivity.java
de.wikilab.android.friendica01.activity.MessageDetailActivity.java
de.wikilab.android.friendica01.activity.MessagesActivity.java
de.wikilab.android.friendica01.activity.PreferenceContainerActivity.java
de.wikilab.android.friendica01.activity.PreferencesActivity.java
de.wikilab.android.friendica01.activity.UserProfileActivity.java
de.wikilab.android.friendica01.activity.WritePostActivity.java
de.wikilab.android.friendica01.adapter.HtmlStringArrayAdapter.java
de.wikilab.android.friendica01.adapter.MessageContentAdapter.java
de.wikilab.android.friendica01.adapter.MessageListAdapter.java
de.wikilab.android.friendica01.adapter.PhotoGalleryAdapter.java
de.wikilab.android.friendica01.adapter.PostListAdapter.java
de.wikilab.android.friendica01.fragment.ContentFragment.java
de.wikilab.android.friendica01.fragment.FriendListFragment.java
de.wikilab.android.friendica01.fragment.MainMenuFragment.java
de.wikilab.android.friendica01.fragment.MessageViewFragment.java
de.wikilab.android.friendica01.fragment.MessageWriteFragment.java
de.wikilab.android.friendica01.fragment.PhotoGalleryFragment.java
de.wikilab.android.friendica01.fragment.PostDetailFragment.java
de.wikilab.android.friendica01.fragment.PostListFragment.java
de.wikilab.android.friendica01.fragment.WelcomeFragment.java
de.wikilab.android.friendica01.fragment.WritePostFragment.java