मेरा एंड्रॉइड ऐप कभी भी 2.3 डिवाइस पर जीसीएम संदेश प्राप्त नहीं करता है, लेकिन यह 4.x डिवाइस पर करता है। मैं सफलतापूर्वक सभी डिवाइस (2.3 और 4.x) पंजीकृत कर सकता हूं। मैंने सोचा कि इसका this issue के साथ कुछ करना पड़ सकता है, लेकिन ऐसा लगता है कि मेरे एंड्रॉइड मेनिफेस्ट को ठीक से कॉन्फ़िगर किया गया है। क्या कोई मेरी मंशा सेवा और ब्रॉडकास्ट रिसीवर को नजरअंदाज कर पाएगा और देखें कि क्या उन्हें कोई समस्या है? किसी भी तरह की सहायता का स्वागत किया जाएगा। ध्यान दें कि जब डिबगर संलग्न होता है तो नोटिफिकेशन भेजते समय HandeIntent() को Android 2.3 के लिए कभी भी नहीं कहा जाता है। मैंने 4.x डिवाइसों की जांच की, और वे डीडगर को हैंडलइन्टेंट() पर ट्रिगर करते हैं। धन्यवाद!एंड्रॉइड 4.x डिवाइस जीसीएम संदेश प्राप्त करते हैं, लेकिन एंड्रॉइड 2.3 डिवाइस
एंड्रॉयड Manfest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="17" />
<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="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="my.package.matchtracker.permission.C2D_MESSAGE" />
<permission android:name="my.package.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver
android:name=".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="my.package" />
</intent-filter>
</receiver>
<service android:name=".NotificationIntentService" android:enabled="true" />
<activity android:name="com.gigya.socialize.android.GSWebViewActivity" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
प्रसारण रिसीवर:
package my.package;
import android.app.*;
import android.content.*;
public class GcmBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationIntentService.runIntentInService(context, intent);
setResultCode(Activity.RESULT_OK);
}
}
अधिसूचना आशय सेवा
public class NotificationIntentService extends IntentService {
private String TAG = "NotificationIntentService";
public NotificationIntentService() {
super(AppConstants.GCM_SENDER_ID);
}
public NotificationIntentService(String name) {
super(name);
// TODO Auto-generated constructor stub
}
private static PowerManager.WakeLock sWakeLock;
private static final Object LOCK = NotificationIntentService.class;
static void runIntentInService(Context context, Intent intent) {
synchronized(LOCK) {
if (sWakeLock == null) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "my_wakelock");
}
}
sWakeLock.acquire();
intent.setClassName(context, NotificationIntentService.class.getName());
context.startService(intent);
}
public final void onHandleIntent(Intent intent) {
try {
String action = intent.getAction();
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
//don't care.
} else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(intent);
}
} finally {
synchronized(LOCK) {
sWakeLock.release();
}
}
}
private void handleMessage(Intent intent) {
Bundle b = intent.getExtras();
String text = b.getString("text"),
title = b.getString("title"),
largeImageUrl = b.getString("largeImageUrl");
Log.i(TAG, "Message is " + text);
NotificationManager nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap bit=null;
if (largeImageUrl != null && !largeImageUrl.isEmpty()) {
try{bit = BitmapFactory.decodeStream((InputStream)new URL(largeImageUrl).getContent());
} catch (Exception e){}
}
NotificationCompat.Builder nc = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.ic_launcher)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true) //notification disappears when clicked
.setContentIntent(PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
//bit = Bitmap.createScaledBitmap(bit, android.R.dimen.notification_large_icon_width, android.R.dimen.notification_large_icon_height, true);
if (bit != null) nc.setLargeIcon(bit);
nm.notify(0, nc.build());
}
}
हाँ, आप सही हैं। मैंने किसी भी तरह सोचा था कि matchtracker इस [पोस्ट] के दूसरे जवाब से एक आवश्यक विन्यास का हिस्सा था (http://stackoverflow.com/questions/5660460/push-notifications-on-emulator-working-but-not-on-real -device # जवाब-10,723,301)। अब मैं बेहतर जानता हूँ। इस के साथ मेरी मदद करने के लिए धन्यवाद! – Daniel
आपका स्वागत है! – Eran
@Eran मैं आपको अधिकांश जीसीएम प्रश्नों पर टिप्पणी करता हूं, और यह मुझे एक निष्कर्ष पर ले जाता है कि आपको जीसीएम की बहुत अच्छी समझ होनी चाहिए। तो, मैं आपको जीसीएम के बारे में कुछ जानकारी प्रदान करने के लिए कहूंगा। मैंने एंड्रॉइड हाइव ट्यूटोरियल किया था, लेकिन उनमें से कई का सामना करना पड़ रहा है ** सर्वर पर सफल पंजीकरण के बावजूद, मैं डिवाइस पर नोटिफिकेशन प्राप्त करने में असमर्थ हूं **। आगे के लेख पढ़ना मैं अनुमान लगा रहा हूं कि एंड्रॉइड हाइव ट्यूटोरियल की तुलना में उनका जीसीएम में कुछ अपडेट है, इसलिए कृपया मुझे बताएं कि अपडेट क्या हैं और उस ट्यूटोरियल में क्या बदलाव करना है। –