2012-09-10 18 views
0

我在我的新Android應用上使用GCM服務,我做了我的代碼,但是當我在移動設備上運行項目時,我有例外,該項目意外停止,但是當我評論代碼谷歌API沒有收到任何報告

GCMRegistrar.checkDevice(this); 
    GCMRegistrar.checkManifest(this); 

此行的錯誤停止,但是當我運行該項目出現錯誤,當我檢查了我的谷歌API來檢查,如果發到我的谷歌API的錯誤,但我沒有找到任何報告,爲什麼? ??

GCMIntenetService類

package com.example.elarabygroup; 

import com.google.android.gcm.GCMBaseIntentService; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 

public class GCMIntenetService extends GCMBaseIntentService { 
    public static String TAG = "GCMIntentService"; 

    public GCMIntenetService(String senderId) { 
     super(senderId); 
     Log.d("GCMIntentService", senderId); 
    } 

    @Override 
    protected void onError(Context arg0, String arg1) { 
     Log.d("onError", arg1); 
    } 

    @Override 
    protected boolean onRecoverableError(Context context, String errorId) { 
     Log.d("onRecoverableError", errorId); 
     return false; 
    } 

    @Override 
    /* 
    protected void onMessage(Context arg0, Intent arg1) { 
     Log.d("onMessage", String.valueOf(arg1)); 
    } 
    */ 
    protected void onMessage(Context arg0, Intent arg1) { 

     Log.d("GCM", "RECIEVED A MESSAGE"); 
     // Get the data from intent and send to notificaion bar 
     generateNotification(arg0, arg1.getStringExtra("**notificaion**")); 
    } 

    private void generateNotification(Context arg0, String stringExtra) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    protected void onRegistered(Context arg0, String arg1) { 
     Log.d("onRegistered", arg1); 
    } 

    @Override 
    protected void onUnregistered(Context arg0, String arg1) { 
     Log.d("onUnregistered", arg1); 
    } 
} 

清單

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.elarabygroup" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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

    <permission 
     android:name="com.example.elarabygroup.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="com.example.elarabygroup.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <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:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".ElarabyGroup" 
      android:label="@string/title_activity_elaraby_group" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

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

       <category android:name="com.example.elarabygroup" /> 
      </intent-filter> 
     </receiver> 

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

</manifest> 

活動

package com.example.elarabygroup; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.content.Intent; 
import android.net.ConnectivityManager; 
import android.net.NetworkInfo; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.webkit.WebView; 
import com.google.android.gcm.GCMRegistrar; 

public class ElarabyGroup extends Activity { 
    private String TAG; 
    private String SENDER_ID = "xxxxxxxx"; 
    private WebView webView; 

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

     GCMRegistrar.checkDevice(this); 
     GCMRegistrar.checkManifest(this); 

     final String regId = GCMRegistrar.getRegistrationId(this); 
     if (regId.equals("")) { 
      GCMRegistrar.register(this, "xxxxxxxx"); 
     } else { 
      Log.v(TAG, "Already registered"); 
     } 

     try { 

      ConnectivityManager con = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 

      if (con.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED 
        && con.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED) { 
       AlertDialog.Builder builder = new AlertDialog.Builder(this); 

       builder.setMessage("No Internet connection"); 
       AlertDialog alert = builder.create(); 
       alert.show(); 

      } else 

      { 

       webView = (WebView) findViewById(R.id.webView1); 
       webView.getSettings().setJavaScriptEnabled(true); 
       webView.loadUrl("http://m.elarabygroup.com"); 
      } 

     } catch (Exception e) { 

      AlertDialog.Builder builder = new AlertDialog.Builder(this); 

      builder.setMessage(e.getMessage().toString()); 

      AlertDialog alert = builder.create(); 

      String url = "http://m.elarabygroup.com/"; 

      Intent i = new Intent(Intent.ACTION_VIEW); 
      i.setData(Uri.parse(url)); 
      startActivity(i); 

     } 

    } 

} 
/* 
* @Override public boolean onCreateOptionsMenu(Menu menu) { 
* getMenuInflater().inflate(R.menu.activity_elaraby_group, menu); return true; 
* } } 
*/ 

回答