Skip to content

Instantly share code, notes, and snippets.

View sab99r's full-sized avatar

Sabeer sab99r

View GitHub Profile
@sab99r
sab99r / MY_Controller.php
Last active April 8, 2016 18:29
Codigniter Extend CI_Controller
<?php
class MY_Controller extends CI_Controller {
public function __construct(){
parent::__construct();
//check your login login here then redirect to login screen if not logged in
}
}
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('session');
//For example I have set logged_in = true in authentication on success
//Checking whether userdata logged_in not set ... if true redirecting to login screen
if(!$this->session->has_userdata('logged_in') || !$this->session->logged_in){
@sab99r
sab99r / build.gradle
Created June 16, 2016 08:15
Google Services Plugin in Project Level build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:3.0.0'
}
}
@sab99r
sab99r / build.gradle
Last active June 16, 2016 08:19
Apply Google Services Plugin in app level build.gradle
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
//includes Firebase Analytics by default
@sab99r
sab99r / build.gradle
Created June 16, 2016 08:36
Firebase Available Gradle Libraries (Add required one in app level build.gradle)
//Analytics
com.google.firebase:firebase-core:9.0.2
//Realtime Database
com.google.firebase:firebase-database:9.0.2
//Storage
com.google.firebase:firebase-storage:9.0.2
//Crash Reporting
com.google.firebase:firebase-crash:9.0.2
//Authentication
com.google.firebase:firebase-auth:9.0.2
@sab99r
sab99r / build.gradle
Last active June 16, 2016 08:43
FCM - Firebase Cloud Messaging app level build.gradle
//Cloud Messaging / Notifications
compile 'com.google.firebase:firebase-messaging:9.0.2'
@sab99r
sab99r / AndroidManifest.xml
Created June 16, 2016 10:38
FCM Services in manifest.xml
<service
android:name=".fcm.FcmMessageService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".fcm.FcmInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
@sab99r
sab99r / FcmInstanceIdService.java
Created June 16, 2016 10:49
FirebaseInstanceIdService extended class
public class FcmInstanceIdService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
String token = FirebaseInstanceId.getInstance().getToken();
Log.d("TOKEN",token);
sendFcmTokenToServer(token);
}
private void sendFcmTokenToServer(String token){
@sab99r
sab99r / FcmMessageService.java
Last active June 21, 2016 16:36
FirebaseMessagingService extended class
public class FcmMessageService extends FirebaseMessagingService{
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//onMessageReceived will be called when ever you receive new message from server.. (app in background and foreground )
Log.d("FCM", "From: " + remoteMessage.getFrom());
if(remoteMessage.getNotification()!=null){
Log.d("FCM", "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
@sab99r
sab99r / fcm.php
Last active May 4, 2021 19:08
PHP Function to Send FCM Message to Android
<?php
/*
Parameter Example
$data = array('post_id'=>'12345','post_title'=>'A Blog post');
$target = 'single tocken id or topic name';
or
$target = array('token1','token2','...'); // up to 1000 in one request
*/
public function sendMessage($data,$target){
//FCM api URL