آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

کمک برای استفاده از GCM ( نوتیفیکیشن )

MyNewName  10 سال پیش  10 سال پیش
0 0

سلام

من با GCM تصمیم برای ارسال نوتیفیکیشن دارم

اما نمیدونم چرا Receiver که گذاشم کار نمی کنه

کلاس onReceive

public class MyGcmListenerService extends GcmListenerService {

    private static final String TAG = "MyGcmListenerService";


    @Override
    public void onMessageReceived(String from, Bundle data) {
        String message = data.getString("message");
        Log.d(TAG, "From: " + from);
        Log.d(TAG, "Message: " + message);

        if (from.startsWith("/topics/")) {
            // message received from some topic.
        } else {
            // normal downstream message.
        }

        sendNotification(message);
    }


    private void sendNotification(String message) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                //.setSmallIcon(R.drawable.ic_stat_ic_notification)
                .setContentTitle("GCM Message")
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
    }
}

Manifest

<receiver

            android:name="com.google.android.gms.gcm.GcmReceiver"

            android:exported="true"

            android:permission="com.google.android.c2dm.permission.SEND" >

            <intent-filter>

                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            </intent-filter>

        </receiver>

        <service android:name=".RegistrationIntentService"

             android:exported="false" />

        <service

            android:name=".MyGcmListenerService"

            android:exported="false" >

            <intent-filter>

                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            </intent-filter>

        </service>

        <service

            android:name=".MyInstanceIDListenerService"

            android:exported="false">

            <intent-filter>

                <action android:name="com.google.android.gms.iid.InstanceID" />

            </intent-filter>

        </service>

<permission android:name="com.aloonak.app.network.permission.C2D_MESSAGE"

        android:protectionLevel="signature" />

    <uses-permission android:name="com.aloonak.app.network.permission.C2D_MESSAGE" />

0 0
کدهای مربوطه و کدهای منیفست که اصل قضیه است رو قرار بدین که بشه راهنماییتون کرد ! (10 سال پیش)
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .