2012-06-22 66 views
18

我不知道任何推送通知。我在尝试学习。但我无法理解。 我有服务器的一个表mysql数据库system.if任何更改都在表中进行意味着我要显示为通知到Android手机 请给我的建议,我如何从服务器推送通知到Android手机

+1

http://stackoverflow.com/questions/1378671/push-notifications-in-android-platform – user370305

+0

我登录在c2dm应用程序我填充singup然后我得到消息来自谷歌。之后,我可以做些什么。我不知道请告诉我解决方案。我面临的问题过去7天..请帮我 – naveen

+0

看看我给上述评论的链接.. – user370305

回答

1

这里是这个一个很好的解释:
http://quickblox.com/developers/SimpleSample-messages_users-android

总的步骤是:

  1. 创建一个谷歌的API项目
  2. 启用项目推送通知,并获得APIķ EY
  3. 获取通过Android应用的注册ID(每个装置具有用于特定应用的注册ID)
  4. 创建一个服务器应用程序通过谷歌服务器通过GSM
  5. 创建通知何时发送你的推送消息作为推送通知你在应用程序端得到推送通知

这不是我可以在这里写的所有细节。每一步都使用Google。

0

第一件事 - Google推送通知称为GCM(Google Cloud Messaging)。错误的名称使用可能会导致您输入错误的信息或教程。另一方面,你应该依赖开发人员。在这种情况下,您可以从Google Developers网站开始,在那里您可以找到大部分基本信息和代码示例。 https://developers.google.com/cloud-messaging/

0

其实现在大部分最近使用的,ü项目中推送通知FCM ....用于构建 最好的链接推送商品通知:link

步骤进行推送通知 - 火力地堡云端通讯教程为Android

  1. 转到Firebase控制台并创建一个新项目。
  2. 现在把你的应用程序名称,并选择你的国家。
  3. 现在点击向您的Android应用添加Firebase。
  4. 现在您必须输入您的项目包名称并点击添加应用程序。
  5. 点击添加应用后,您将获得google-services.json文件。

在应用程序方面

  1. 现在回到你的Android项目。转到应用程序文件夹并粘贴google-services.json文件
  2. 现在转到您的根级build.gradle文件并添加以下代码。

    a。添加此行 classpath'com.google.gms:google-services:3.0.0'

    b。添加此行 compile'c​​om.google.firebase:firebase-messaging:9.0.0'

  3. 现在同步您的项目。

  4. 创建一个名为MyFirebaseInstanceIDService.java类,并用下面的代码:

    public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { 
    
        private static final String TAG = "MyFirebaseIIDService"; 
    
        @Override 
        public void onTokenRefresh() { 
    
         //Getting registration token 
         String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
    
         //Displaying token on logcat 
         Log.d(TAG, "Refreshed token: " + refreshedToken); 
    
        } 
    
        private void sendRegistrationToServer(String token) { 
         //You can implement this method to store the token on your server 
         //Not required for current project 
        } 
    } 
    
  5. 现在创建MyFirebaseMessagingService.java和写下面的代码:

    import android.app.NotificationManager; 
    import android.app.PendingIntent; 
    import android.content.Context; 
    import android.content.Intent; 
    import android.media.RingtoneManager; 
    import android.net.Uri; 
    import android.support.v4.app.NotificationCompat; 
    import android.util.Log; 
    
    import com.google.firebase.messaging.FirebaseMessagingService; 
    import com.google.firebase.messaging.RemoteMessage; 
    
    /** 
    * 
    */ 
    
    public class MyFirebaseMessagingService extends FirebaseMessagingService { 
    
        private static final String TAG = "MyFirebaseMsgService"; 
    
        @Override 
        public void onMessageReceived(RemoteMessage remoteMessage) { 
         //Displaying data in log 
         //It is optional 
         Log.d(TAG, "From: " + remoteMessage.getFrom()); 
         Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 
    
         //Calling method to generate notification 
         sendNotification(remoteMessage.getNotification().getBody()); 
        } 
    
        //This method is only generating push notification 
        //It is same as we did in earlier posts 
        private void sendNotification(String messageBody) { 
         Intent intent = new Intent(this, MainActivity.class); 
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 
           PendingIntent.FLAG_ONE_SHOT); 
    
         Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
         NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
           .setSmallIcon(R.mipmap.ic_launcher) 
           .setContentTitle("Firebase Push Notification") 
           .setContentText(messageBody) 
           .setAutoCancel(true) 
           .setSound(defaultSoundUri) 
           .setContentIntent(pendingIntent); 
    
         NotificationManager notificationManager = 
           (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    
         notificationManager.notify(0, notificationBuilder.build()); 
        } 
    } 
    
  6. 现在我们要定义上述服务在我们的AndroidManifest.xml文件中。因此请按照以下方式进行修改和修改。

    <!-- Adding Internet Permission --> 
    
    <uses-permission android:name="android.permission.INTERNET"/> 
    <application 
        android:allowBackup="true" 
        android:icon="@mipmap/ic_launcher" 
        android:label="@string/app_name" 
        android:supportsRtl="true" 
        android:theme="@style/AppTheme"> 
        <activity android:name=".MainActivity"> 
         <intent-filter> 
          <action android:name="android.intent.action.MAIN" /> 
    
          <category android:name="android.intent.category.LAUNCHER" /> 
         </intent-filter> 
        </activity> 
    
        <!-- 
         Defining Services 
        --> 
        <service 
         android:name=".MyFirebaseMessagingService"> 
         <intent-filter> 
          <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
         </intent-filter> 
        </service> 
    
        <service 
         android:name=".MyFirebaseInstanceIDService"> 
         <intent-filter> 
          <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> 
         </intent-filter> 
        </service> 
    </application> 
    

终于

转到火力平台,然后选择您所创建的应用程序。 从左侧菜单中选择通知。 点击新消息。 输入消息,选择单个设备并粘贴您复制的令牌,然后单击发送。与我在视频上一样,并检查您的设备

相关问题