SlideShare uma empresa Scribd logo
1 de 41
Android C2DM開発に関して
 Developing Android C2DM applications.
     Overview and implementation.



              2011/10
      Keishi Hosoba @hosopy
        株式会社ガラパゴス
Overview
What is C2DM?
           • Cloud to Device Messaging
           • PUSH notification framework and
               service for android applications
              • It allows third-party application
                  servers to send lightweight messages
                  to their Android applications.


Galapagos Inc. http://www.glpgs.com/
PUSH



         Android                              Application server



Galapagos Inc. http://www.glpgs.com/
Target
         GoogleAccount(device) × Application



                                   PUSH(hoge, rearge)

     hoge@gmail.com


                                       PUSH(fuga, rearge)
                                           Registration ID
     fuga@gmail.com
Galapagos Inc. http://www.glpgs.com/
Flow overview
                                                             1. New data

                                   5. Request data

                                   6. Receive data



       4. Event                              2. Send
                                          (RegistrationID)


                           3. PUSH Notification



Galapagos Inc. http://www.glpgs.com/                 C2DM Servers
Flow overview
                                                             1. New data

                                   5. Request data

                                   6. Receive data



       4. Event                              2. Send
                                          (RegistrationID)


                           3. PUSH Notification
                                Don’t care!                   C2DM
                                                              Service
Galapagos Inc. http://www.glpgs.com/
Without C2DM

           • WebSocket
           • Comet
           • Polling
           • Other(Google Channel API...)

Galapagos Inc. http://www.glpgs.com/
Many things to care
           •   Designed for realtime web application
               •   WebSocket,Comet
           •   Infrastructure
               •   server and network
           •   Message queueing
               •   if target device is offline ...
           •   Security
           •   Connection management
Galapagos Inc. http://www.glpgs.com/
Flow overview
                                                             1. New data

                                   5. Request data

                                   6. Receive data



       4. Event                              2. Send
                                          (RegistrationID)


                                Don’t care!
                           3. PUSH Notification
                 Infrastructure / Queueing / SecurityC2DM
                                                      /
                       Connection Management         Service
Galapagos Inc. http://www.glpgs.com/
Other feature


           • Designed for lightweight message
           • No gurantee for message sequence


Galapagos Inc. http://www.glpgs.com/
Detail Flow
Lifecycle Flow

           • Enabling C2DM
           • Sending a message
           • Receiving a message


Galapagos Inc. http://www.glpgs.com/
1. Enabling C2DM



  Application                       AndroidOS              C2DM Server   Server

                      Intent
           com.google.android.c2dm.int
                 ent.REGISTER                        ?
                data[Sender ID]



                                                Registration ID

                Broadcast Intent
               REGISTRATION              With permission
              data[Registration ID]                                            hoge :
                                                                            RegistrationID



                  Registration ID




Galapagos Inc. http://www.glpgs.com/
2,3. Sending & Receiving a message



  Application                       AndroidOS C2DM Server                Server

                                                             Message
               BroadcatReceiver                            Registration ID
                                                            AuthToken
                                            Message
                                          RegistrationID
                 Broadcast Intent                          Queueing             hoge :
            com.google.android.c2dm.int                                      RegistrationID
                  ent.RECEIVE
                  data[Message]




                  With permission




Galapagos Inc. http://www.glpgs.com/
Implementation
Requirements

           • Android Application
            • OS 2.2
           • Application Server
            • SSL enabled

Galapagos Inc. http://www.glpgs.com/
Sign Up
as C2DM Sender
http://code.google.com/intl/ja/android/c2dm/signup.html




Galapagos Inc. http://www.glpgs.com/
Manifest
SDK & Permission

       <!-- 他のアプリのメッセージ登録・受信防止 -->
       <permission
               android:name="com.glpgs.android.study.c2dm.permission.C2D_MESSAGE"
               android:protectionLevel="signature" />
       <uses-permission android:name="com.glpgs.android.study.c2dm.permission.C2D_MESSAGE" />

       <!-- その他必要なパーミッション -->
       <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.GET_ACCOUNTS" />
       <uses-permission android:name="android.permission.WAKE_LOCK" />
       <uses-permission android:name="android.permission.USE_CREDENTIALS" />




Galapagos Inc. http://www.glpgs.com/
BroadcastReceiver
           <application android:icon="@drawable/icon" android:label="@string/app_name">
                    <!-- Only C2DM servers can send messages for the app. -->
                    <!-- If permission is not set - any other app can generate it -->
                    <receiver
                               android:name=".C2DMReceiver"
                               android:permission="com.google.android.c2dm.permission.SEND">
                               <!-- Receive the actual message -->
                               <intent-filter>
                                          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                                          <category android:name="com.glpgs.android.study.c2dm" />
                               </intent-filter>
                               <!-- Receive the registration id -->
                               <intent-filter>
                                          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                                          <category android:name="com.glpgs.android.study.c2dm" />
                               </intent-filter>
                    </receiver>




Galapagos Inc. http://www.glpgs.com/
Implement
Enabling C2DM Flow
1. Enabling C2DM



 Application                  AndroidOS           C2DM Server Server

                    Intent
           com.google.android.c2d
             m.intent.REGISTER                  ?
              data[Sender ID]


                                           Registration ID

               Broadcast Intent
                                                                   hoge :
               REGISTRATION          With permission             RegistrationI
             data[Registration ID]
                                                                      D


                 Registration ID



Galapagos Inc. http://www.glpgs.com/
Register, Unregister

                      OnClick

            private void registerC2DM(){
                     Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
                     intent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
                     intent.putExtra("sender", "hoge@example.com");
                     startService(intent);
            }                                                                    Sender ID
            private void unregisterC2DM(){
                     Intent intent = new Intent("com.google.android.c2dm.intent.UNREGISTER");
                     intent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
                     startService(intent);
            }

Galapagos Inc. http://www.glpgs.com/
1. Enabling C2DM



  Application                       AndroidOS              C2DM Server   Server

                      Intent
           com.google.android.c2dm.int
                 ent.REGISTER                        ?
                data[Sender ID]



                                                Registration ID

                Broadcast Intent
               REGISTRATION              With permission
              data[Registration ID]                                            hoge :
                                                                            RegistrationID



                  Registration ID




Galapagos Inc. http://www.glpgs.com/
Receive Intent
        public class C2DMReceiver extends BroadcastReceiver {
                  @Override
                  public void onReceive(Context context, Intent intent) {
                           if (intent.getAction().equals(
                                                "com.google.android.c2dm.intent.REGISTRATION")) {
                                      // Registration IDの発行が完了した
                                      handleRegistration(context, intent);
                           }
                  }




Galapagos Inc. http://www.glpgs.com/
Retrieve
                     RegistrationID
              private void handleRegistration(Context context, Intent intent) {
                       String registration = intent.getStringExtra("registration_id");
                       if (intent.getStringExtra("error") != null) {
                                   // エラーだよ, リトライとか検討しましょう
                       } else if (intent.getStringExtra("unregistered") != null) {
                                   // 登録解除が完了したよ
                       } else if (registration != null) {
                                   // Registration IDの発行が完了したので、保存して自分のサーバに登録します
                                   // ここからは各アプリの仕様に応じてお好きに
                                   saveRegistrationId(registration);
                                   postRegistrationId(registration);
                       }
              }




Galapagos Inc. http://www.glpgs.com/
Implement
Sending message
      Flow
2,3. Sending & Receiving a message



 Application                       AndroidOS C2DM Server                Server

                                                            Message
              BroadcatReceiver                            Registration ID
                                                           AuthToken
                                           Message
                                         RegistrationID
                Broadcast Intent                          Queueing              hoge :
           com.google.android.c2dm.int                                       RegistrationID
                 ent.RECEIVE
                 data[Message]




                 With permission




Galapagos Inc. http://www.glpgs.com/
[API]POST:https://android.apis.google.com/c2dm/send

              Field                                            Content

 registration_id                  Registration ID

                                  An arbitrary string that is used to collapse a group of like messages
 collapse_key                     when the device is offline, so that only the last message gets sent to
                                  the client.

                                  Message content (key-value pair)
 data.<key>
                                  1024 bytes limit

                                  If included, indicates that the message should not be sent
 delay_while_idle                 immediately if the device is idle.


 Authorization: GoogleLogin       Header with a ClientLogin Auth token. The cookie must be associated
 auth=[AUTH_TOKEN]                with the ac2dm service.




Galapagos Inc. http://www.glpgs.com/
collapse_key

                                        message
                                       ckey=hoge

                                        message
                                       ckey=hoge

                                        message
                                       ckey=hoge


                         Only the last message is sent to the device when the
                         device is online.

Galapagos Inc. http://www.glpgs.com/
AuthToken

           • Authentication token required to use
               Goolge API.
              • http://code.google.com/intl/ja/apis/acc
                  ounts/docs/AuthForInstalledApps.html




Galapagos Inc. http://www.glpgs.com/
Send message
                          @Server
       def send_c2dm(message)
        if auth_token = get_auth_token
          uri = URI.parse("http://android.apis.google.com/c2dm/send")
          body = URI.encode_www_form({
            "registration_id" => message.registration_id,
            "collapse_key" => rand(100000).to_s,
            "data.content" => message.content})
          header = {
            'Content-Type' => "application/x-www-form-urlencoded;charset=UTF-8",
            'Content-Length' => body.bytesize.to_s,
            'Authorization' => "GoogleLogin auth=#{auth_token}"}
          Net::HTTP.start(uri.host, uri.port) do |http|
            http.post(uri.path, body, header)
          end
        end
       end




Galapagos Inc. http://www.glpgs.com/
Implement
Receiving message
       Flow
2,3. Sending & Receiving a message



  Application                       AndroidOS C2DM Server                Server

                                                             Message
               BroadcatReceiver                            Registration ID
                                                            AuthToken
                                            Message
                                          RegistrationID
                 Broadcast Intent                          Queueing             hoge :
            com.google.android.c2dm.int                                      RegistrationID
                  ent.RECEIVE
                  data[Message]




                  With permission




Galapagos Inc. http://www.glpgs.com/
Receive Intent
  public class C2DMReceiver extends BroadcastReceiver {

          @Override
          public void onReceive(Context context, Intent intent) {
                   if (intent.getAction().equals(
                                         "com.google.android.c2dm.intent.REGISTRATION")) {
                               Log.d("C2DMReceiver", "REGISTRATION");
                               // Registration IDの発行が完了した
                               handleRegistration(context, intent);
                   } else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
                               // Messageを受信した
                               Log.d("C2DMReceiver", "RECEIVE");
               handleMessage(context, intent);
            }
          }




Galapagos Inc. http://www.glpgs.com/
Demo
Other

           •   Spec
               •   http://code.google.com/intl/ja/android/c2dm/
           •   Memo about server-side
               •   http://d.hatena.ne.jp/hosopy/20111030




Galapagos Inc. http://www.glpgs.com/
PR

Entrust Galapagos your C2DM enabled
  Android applications development.

C2DMを使ったアプリの開発承ります!
     http://www.glpgs.com
END



Galapagos Inc. http://www.glpgs.com/

Mais conteúdo relacionado

Último

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Developing android c2_dm_applications(android c2dm開発に関して)

  • 1. Android C2DM開発に関して Developing Android C2DM applications. Overview and implementation. 2011/10 Keishi Hosoba @hosopy 株式会社ガラパゴス
  • 3. What is C2DM? • Cloud to Device Messaging • PUSH notification framework and service for android applications • It allows third-party application servers to send lightweight messages to their Android applications. Galapagos Inc. http://www.glpgs.com/
  • 4. PUSH Android Application server Galapagos Inc. http://www.glpgs.com/
  • 5. Target GoogleAccount(device) × Application PUSH(hoge, rearge) hoge@gmail.com PUSH(fuga, rearge) Registration ID fuga@gmail.com Galapagos Inc. http://www.glpgs.com/
  • 6. Flow overview 1. New data 5. Request data 6. Receive data 4. Event 2. Send (RegistrationID) 3. PUSH Notification Galapagos Inc. http://www.glpgs.com/ C2DM Servers
  • 7. Flow overview 1. New data 5. Request data 6. Receive data 4. Event 2. Send (RegistrationID) 3. PUSH Notification Don’t care! C2DM Service Galapagos Inc. http://www.glpgs.com/
  • 8. Without C2DM • WebSocket • Comet • Polling • Other(Google Channel API...) Galapagos Inc. http://www.glpgs.com/
  • 9. Many things to care • Designed for realtime web application • WebSocket,Comet • Infrastructure • server and network • Message queueing • if target device is offline ... • Security • Connection management Galapagos Inc. http://www.glpgs.com/
  • 10. Flow overview 1. New data 5. Request data 6. Receive data 4. Event 2. Send (RegistrationID) Don’t care! 3. PUSH Notification Infrastructure / Queueing / SecurityC2DM / Connection Management Service Galapagos Inc. http://www.glpgs.com/
  • 11. Other feature • Designed for lightweight message • No gurantee for message sequence Galapagos Inc. http://www.glpgs.com/
  • 13. Lifecycle Flow • Enabling C2DM • Sending a message • Receiving a message Galapagos Inc. http://www.glpgs.com/
  • 14. 1. Enabling C2DM Application AndroidOS C2DM Server Server Intent com.google.android.c2dm.int ent.REGISTER ? data[Sender ID] Registration ID Broadcast Intent REGISTRATION With permission data[Registration ID] hoge : RegistrationID Registration ID Galapagos Inc. http://www.glpgs.com/
  • 15. 2,3. Sending & Receiving a message Application AndroidOS C2DM Server Server Message BroadcatReceiver Registration ID AuthToken Message RegistrationID Broadcast Intent Queueing hoge : com.google.android.c2dm.int RegistrationID ent.RECEIVE data[Message] With permission Galapagos Inc. http://www.glpgs.com/
  • 17. Requirements • Android Application • OS 2.2 • Application Server • SSL enabled Galapagos Inc. http://www.glpgs.com/
  • 18. Sign Up as C2DM Sender
  • 21. SDK & Permission <!-- 他のアプリのメッセージ登録・受信防止 --> <permission android:name="com.glpgs.android.study.c2dm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.glpgs.android.study.c2dm.permission.C2D_MESSAGE" /> <!-- その他必要なパーミッション --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> Galapagos Inc. http://www.glpgs.com/
  • 22. BroadcastReceiver <application android:icon="@drawable/icon" android:label="@string/app_name"> <!-- Only C2DM servers can send messages for the app. --> <!-- If permission is not set - any other app can generate it --> <receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <!-- Receive the actual message --> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.glpgs.android.study.c2dm" /> </intent-filter> <!-- Receive the registration id --> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.glpgs.android.study.c2dm" /> </intent-filter> </receiver> Galapagos Inc. http://www.glpgs.com/
  • 24. 1. Enabling C2DM Application AndroidOS C2DM Server Server Intent com.google.android.c2d m.intent.REGISTER ? data[Sender ID] Registration ID Broadcast Intent hoge : REGISTRATION With permission RegistrationI data[Registration ID] D Registration ID Galapagos Inc. http://www.glpgs.com/
  • 25. Register, Unregister OnClick private void registerC2DM(){ Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER"); intent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); intent.putExtra("sender", "hoge@example.com"); startService(intent); } Sender ID private void unregisterC2DM(){ Intent intent = new Intent("com.google.android.c2dm.intent.UNREGISTER"); intent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); startService(intent); } Galapagos Inc. http://www.glpgs.com/
  • 26. 1. Enabling C2DM Application AndroidOS C2DM Server Server Intent com.google.android.c2dm.int ent.REGISTER ? data[Sender ID] Registration ID Broadcast Intent REGISTRATION With permission data[Registration ID] hoge : RegistrationID Registration ID Galapagos Inc. http://www.glpgs.com/
  • 27. Receive Intent public class C2DMReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals( "com.google.android.c2dm.intent.REGISTRATION")) { // Registration IDの発行が完了した handleRegistration(context, intent); } } Galapagos Inc. http://www.glpgs.com/
  • 28. Retrieve RegistrationID private void handleRegistration(Context context, Intent intent) { String registration = intent.getStringExtra("registration_id"); if (intent.getStringExtra("error") != null) { // エラーだよ, リトライとか検討しましょう } else if (intent.getStringExtra("unregistered") != null) { // 登録解除が完了したよ } else if (registration != null) { // Registration IDの発行が完了したので、保存して自分のサーバに登録します // ここからは各アプリの仕様に応じてお好きに saveRegistrationId(registration); postRegistrationId(registration); } } Galapagos Inc. http://www.glpgs.com/
  • 30. 2,3. Sending & Receiving a message Application AndroidOS C2DM Server Server Message BroadcatReceiver Registration ID AuthToken Message RegistrationID Broadcast Intent Queueing hoge : com.google.android.c2dm.int RegistrationID ent.RECEIVE data[Message] With permission Galapagos Inc. http://www.glpgs.com/
  • 31. [API]POST:https://android.apis.google.com/c2dm/send Field Content registration_id Registration ID An arbitrary string that is used to collapse a group of like messages collapse_key when the device is offline, so that only the last message gets sent to the client. Message content (key-value pair) data.<key> 1024 bytes limit If included, indicates that the message should not be sent delay_while_idle immediately if the device is idle. Authorization: GoogleLogin Header with a ClientLogin Auth token. The cookie must be associated auth=[AUTH_TOKEN] with the ac2dm service. Galapagos Inc. http://www.glpgs.com/
  • 32. collapse_key message ckey=hoge message ckey=hoge message ckey=hoge Only the last message is sent to the device when the device is online. Galapagos Inc. http://www.glpgs.com/
  • 33. AuthToken • Authentication token required to use Goolge API. • http://code.google.com/intl/ja/apis/acc ounts/docs/AuthForInstalledApps.html Galapagos Inc. http://www.glpgs.com/
  • 34. Send message @Server def send_c2dm(message) if auth_token = get_auth_token uri = URI.parse("http://android.apis.google.com/c2dm/send") body = URI.encode_www_form({ "registration_id" => message.registration_id, "collapse_key" => rand(100000).to_s, "data.content" => message.content}) header = { 'Content-Type' => "application/x-www-form-urlencoded;charset=UTF-8", 'Content-Length' => body.bytesize.to_s, 'Authorization' => "GoogleLogin auth=#{auth_token}"} Net::HTTP.start(uri.host, uri.port) do |http| http.post(uri.path, body, header) end end end Galapagos Inc. http://www.glpgs.com/
  • 36. 2,3. Sending & Receiving a message Application AndroidOS C2DM Server Server Message BroadcatReceiver Registration ID AuthToken Message RegistrationID Broadcast Intent Queueing hoge : com.google.android.c2dm.int RegistrationID ent.RECEIVE data[Message] With permission Galapagos Inc. http://www.glpgs.com/
  • 37. Receive Intent public class C2DMReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals( "com.google.android.c2dm.intent.REGISTRATION")) { Log.d("C2DMReceiver", "REGISTRATION"); // Registration IDの発行が完了した handleRegistration(context, intent); } else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) { // Messageを受信した Log.d("C2DMReceiver", "RECEIVE"); handleMessage(context, intent); } } Galapagos Inc. http://www.glpgs.com/
  • 38. Demo
  • 39. Other • Spec • http://code.google.com/intl/ja/android/c2dm/ • Memo about server-side • http://d.hatena.ne.jp/hosopy/20111030 Galapagos Inc. http://www.glpgs.com/
  • 40. PR Entrust Galapagos your C2DM enabled Android applications development. C2DMを使ったアプリの開発承ります! http://www.glpgs.com