简体   繁体   English

Google Cloud Messaging开发人员android代码崩溃

[英]Google Cloud Messaging developer android code crashing

Im trying to make an application with Google Cloud Messaging and i followd all the exact steps for implementing GCMclient on developer page, code just seems to crash on launch. 我尝试使用Google Cloud Messaging制作应用程序,并且按照开发人员页面上实现GCMclient的所有确切步骤进行操作,代码似乎在启动时崩溃。 Is there any fault in activity main? 活动主体有任何故障吗? or some logical flaw of how android sets up its application on creation? 还是android如何在创建时设置其应用程序的逻辑缺陷? im new to android programming. 我是android编程的新手。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotproj.clandestine"
android:versionCode="1"
android:versionName="1.0" >

<meta-data android:name="com.google.android.gms.version"
       android:value="@integer/google_play_services_version" />

<uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="19" />

<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="com.google.android.c2dm.permission.RECEIVE" />


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.iotproj.clandestine.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver
        android:name="GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.iotproj.clandestine" />
        </intent-filter>
    </receiver>
    <service android:name="GcmIntentService" />

  </application>


  </manifest>



          public class MainActivity extends Activity {

private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;TextView mDisplay;
Button mButton;

GoogleCloudMessaging gcm;
Context appContext = getApplicationContext();

// this is quite important dude
String registrationId = null;


String SENDER_ID = "xxxxxxxxx";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mDisplay = (TextView) findViewById(R.id.pool);
    mButton  = (Button) findViewById(R.id.getid);

    // Check device for Play Services APK.
    if (!checkPlayServices()) {

        mDisplay.setText("device not supproted !");   button.setOnClickListener(new  View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            gcm = GoogleCloudMessaging.getInstance(appContext);
            try{
                registrationId = gcm.register(SENDER_ID);   
            }
            catch(IOException e){
                mDisplay.setText(e.getMessage());
            }               
        }
    });
}`

Register your broadcast receiver like this way. 这样注册您的广播接收器。

  <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.iotproj.clandestine" />
        </intent-filter>
 </receiver>

for Service 服务

 <service android:name=".GCMIntentService" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在谷歌云消息传递为Android - In Google cloud messaging for android 具有Android Java中的Google Cloud Messaging的Firebase - Firebase with Google Cloud Messaging in Android Java 带有Google Cloud消息传递的android推送通知库 - android push notifications library with google cloud messaging 如何在Qt的android客户端代码中调用Google-Cloud-Messaging API? - How do i call the Google-Cloud-Messaging API in my android client code from Qt? Google Cloud Messaging / GCM - Google Cloud Messaging / GCM 使用XMPP服务器和Google云消息传递(或更新的Firebase云消息传递)进行推送通知的Android应用程序App - Chat App for Android using a XMPP Server and Google Cloud Messaging (or the newer Firebase Cloud Messaging) for Push Notifications 使用Java将HTTP发布到Google Cloud Messaging(Android推送通知) - HTTP Post to Google Cloud Messaging (Android Push Notification) using Java 在Android SDK管理器中找不到Google云消息传递(GCM)库 - Google cloud messaging (GCM) library not found in Android SDK manager 错误-使用Google Cloud Messaging(GCM)的Android Push Notification - ERROR - Android Push Notification using Google Cloud Messaging (GCM) 无法将Google Cloud Messaging集成到Android库模块中 - Unable to integrate Google Cloud Messaging in an android library module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM