folder Tahribat.com Forumları
linefolder Mobil Programlama
linefolder Gcm Registration Boş Geliyor



Gcm Registration Boş Geliyor

  1. KısayolKısayol reportŞikayet pmÖzel Mesaj
    ozgunlu
    ozgunlu's avatar
    Banlanmış Üye
    Kayıt Tarihi: 11/Kasım/2011
    Erkek
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="project.com.holobech" >
    
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
        <!-- GCM requires a Google account. -->
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    
        <!-- Keeps the processor from sleeping when a message is received. -->
        <uses-permission android:name="android.permission.WAKE_LOCK" />
    
        <uses-permission android:name="android.permission.VIBRATE" />
    
        <!-- Creates a custom permission so only this app can receive its messages. -->
        <permission
            android:name="project.com.holobech.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />
    
        <uses-permission android:name="project.com.holobech.permission.C2D_MESSAGE" />
    
        <!-- This app has permission to register and receive data message. -->
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    
        <!-- Network State Permissions to detect Internet status -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
        <!-- Permission to vibrate -->
        <uses-permission android:name="android.permission.VIBRATE" />
        <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
        <!--
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
             Google Maps Android API v2, but are recommended.
        -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
        <application
            android:name=".app.AppController"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/MyMaterialTheme" >
            <activity
                android:name=".activity.LoginActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name=".activity.RegisterActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" />
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" />
            <activity
                android:name=".activity.FullImageActivity"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Holo.NoActionBar" >
            </activity>
            <activity
                android:name=".activity.PrivacyActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" />
            <activity
                android:name=".activity.AboutUsActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" />
            <activity
                android:name=".activity.SupportActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" />
            <activity
                android:name=".activity.PaypalActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" >
            </activity>
            <activity
                android:name="com.paypal.android.MEP.PayPalActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" />
            <activity
                android:name=".activity.TermsActivity"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan" />
    
            <service
                android:name="com.paypal.android.sdk.payments.PayPalService"
                android:exported="false" />
    
            <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
            <activity android:name="com.paypal.android.sdk.payments.LoginActivity" />
            <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" />
            <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" />
            <activity
                android:name="io.card.payment.CardIOActivity"
                android:configChanges="keyboardHidden|orientation" />
            <activity android:name="io.card.payment.DataEntryActivity" />
    
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
    
            <receiver
                android:name=".services.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="project.com.holobech" />
                </intent-filter>
            </receiver>
    
            <service android:name=".services.GCMNotificationIntentService" />
        </application>
    
    </manifest>
    

     


    public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    ComponentName comp = new ComponentName(context.getPackageName(),
    GCMNotificationIntentService.class.getName());
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
    }
    }

     

    public class GCMNotificationIntentService extends IntentService {
    public static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;

    public GCMNotificationIntentService() {
    super("GcmIntentService");
    }

    public static final String TAG = "GCMNotificationIntentService";

    @Override
    protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) {
    if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
    .equals(messageType)) {
    sendNotification("Send error: " + extras.toString());
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
    .equals(messageType)) {
    sendNotification("Deleted messages: "
    + extras.toString());
    } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
    .equals(messageType)) {
    sendNotification(""
    + extras.get("price"));
    Log.i(TAG, "Received: " + extras.toString());
    }
    }
    GcmBroadcastReceiver.completeWakefulIntent(intent);
    }

    private void sendNotification(String msg) {
    Log.d(TAG, "Preparing to send notification...: " + msg);
    mNotificationManager = (NotificationManager) this
    .getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
    new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher)
    .setContentTitle("Holobech")
    .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
    .setContentText(msg)
    .setSound(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.holobech_not));

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    Log.d(TAG, "Notification sent successfully.");
    }
    }


    MAIN ACTIVITY :

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    GCMRegistrar.unregister(this);
    GCMRegistrar.register(this, SENDER_ID);
    String rregId = GCMRegistrar.getRegistrationId(this);
    // Check if regid already presents
    if (regId.equals("")) {
    // Registration is not present, register now with GCM
    GCMRegistrar.register(this, SENDER_ID);
    } else {
    // Device is already registered on GCM
    if (GCMRegistrar.isRegisteredOnServer(this)) {
    // Skips registration.
    } else {
    // Try to register again, but not in the UI thread.
    // It's also necessary to cancel the thread onDestroy(),
    // hence the use of AsyncTask instead of a raw thread.
    final Context context = this;
    mRegisterTask = new AsyncTask<Void, Void, Void>() {

    @Override
    protected Void doInBackground(Void... params) {
    // Register on our server
    // On server creates a new user
    ServerUtilities.register(context, PROFILE_UID, regId);
    return null;
    }

    @Override
    protected void onPostExecute(Void result) {
    mRegisterTask = null;
    }

    };
    mRegisterTask.execute(null, null, null);
    }
    }


    GCM register her seferinde boş geliyor, sebebini bulamadım. Kanser etti. Yardımcı olabilecek var mıdır ?
    Ek olarak :
    project.com.holobech, main package adı
    project.com.holobech.services ise, gcmintentservice ile broadcast' ın bulunduğu package.
    mainactivity, main package' da.


    ozgunlu tarafından 06/Oca/16 15:49 tarihinde düzenlenmiştir

    Hello, i am nothing. I come from Neverland.
Toplam Hit: 1777 Toplam Mesaj: 1
android gcm