Failed to resolve target intent service. Push notifications Android - android

I am getting following error when trying to configure Push Notification:
Failed to resolve target intent service, skipping classname enforcement
Error while delivering the message: ServiceIntent not found.
Manifest:
<manifest package="com.packageName"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- support previous 4.4 KitKat devices-->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.packageName.permission.C2D_MESSAGE" />
<application
android:name="AppName"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#android:style/Theme.Black.NoTitleBar">
<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" />
<category android:name="com.packageName" />
</intent-filter>
<intent-filter> <!-- support previous 4.4 KitKat devices-->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.packageName" />
</intent-filter>
</receiver>
<service
android:name="com.packageName.activities.RegistrationIntentService"
android:exported="false" >
</service>
<service
android:name="com.packageName.activities.GcmIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name="com.packageName.activities.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
MyGcmListenerService:
public class MyGcmListenerService extends GcmListenerService {
#Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d("From", "From: " + from);
Log.d("Msg", "Message: " + message);
}
}
RegistrationIntentService
public class RegistrationIntentService extends IntentService {
private static String SENDER_ID = "MySenderID";
public RegistrationIntentService(){
super(SENDER_ID);
}
#Override
public void onHandleIntent(Intent intent){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
Log.i("TOKEN", "GCM Registration Token: " + token);
} catch (Exception e) {
Log.d("Fail token", "Failed to complete token refresh", e);
}
}
}
GcmIDListenerService
public class GcmIDListenerService extends InstanceIDListenerService {
#Override
public void onTokenRefresh() {
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
}
I have placed google-services.json in projectName/app
I send push notification from web http://techzog.com/development/gcm-notification-test-tool-android/ and the response is success:1 but it not received in Android device.

Related

Android, FireBase Cloud Messaging, (FCM)

I am using FCM with data-messaging and can handle both foreground and background notification, but can't receive them when a phone is rebooted or app is killed (task is terminated by swiping in task manager).
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tadad.firebasetestDOUBLE">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name="com.example.tadad.firebasetestDOUBLE.AndroidApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.tadad.firebasetestDOUBLE.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Notification -->
<service
android:name="com.example.tadad.firebasetestDOUBLE.notification.SomeInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.example.tadad.firebasetestDOUBLE.notification.SomeFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
Code:
public class SomeFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
int a = 4;
sendNotification("Smth", "Receive please!");
}
}
public class SomeInstanceIDListenerService extends FirebaseInstanceIdService {
#Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}

Android Manifest code for Parse Push Receiver

I have followed the guidelines mentioned in parse.com and tried all helps from stackoverflow. But I am unable to receive any Parse Push Notification. The Dashboard shows Pushes Sent 0. Can anyone help me out on this. The code for
manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.phpand"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.phpand.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.phpand.permission.C2D_MESSAGE" />
<application
android:name=".MainApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light" >
<activity android:name=".ParseMainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.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.phpand" />
</intent-filter>
</receiver>
<receiver
android:name=".MyCustomReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
</manifest>
where MainAppp initializes the Parse, ParseMainActivity's button click sends the push message and MyCustomReceiver is the BroadCastReceiver Class.
MyCustomReceiver class has:
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
public static final String intentAction = "SEND_PUSH";
#Override
public void onReceive(Context context, Intent intent) {
if (intent == null) {
Log.d(TAG, "Receiver intent null");
} else {
processPush(context, intent);
}
}
private void processPush(Context context, Intent intent) {
String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals(intentAction))
{
String channel = intent.getExtras().getString("com.parse.Channel");
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator<String> itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.equals("customdata")) {
launchSomeActivity(context, json.getString(key));
triggerBroadcastToActivity(context);
createNotification(context);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
} catch (JSONException ex) {
Log.d(TAG, "JSON failed!");
}
}
}
public static final int NOTIFICATION_ID = 45;
private void createNotification(Context context) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(
R.drawable.ic_launcher).setContentTitle("Successfully logged in");
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(45, mBuilder.build());
}
private void launchSomeActivity(Context context, String datavalue) {
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
pupInt.putExtra("customdata", datavalue);
context.getApplicationContext().startActivity(pupInt);
}
private void triggerBroadcastToActivity(Context context) {
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(intentAction));
}
}
Probably I must be missing something in the Manifest file, any help would save my week's due.

Why my custom receiver is not working?

I use parse.com api.
What my problem is :
When other client send push notification I did not receive anything on my broadcastreceiver.
My manifest
<service android:name="com.parse.PushService" />
<receiver
android:name=".MainActivity$MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.yy.xx.UPDATE_STATUS" />
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
and my receiver in mainactivity is here:
public static class MyReceiver extends BroadcastReceiver {
public final String TAG = "MyReceiver";
#Override
public void onReceive(Context context, Intent intent) {
//this is not working,
try {
if (intent == null)
{
Log.d(TAG, "Receiver intent null");
}
else
{
String action = intent.getAction();
if (action.equals("com.yy.xx.UPDATE_STATUS"))
{
//....
}
}
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
and my push notification send code is here:
JSONObject obj;
try {
obj =new JSONObject();
obj.put("action","com.yy.xx.UPDATE_STATUS");
obj.put("customdata","message...");
push_p = new ParsePush();
#SuppressWarnings("rawtypes")
ParseQuery query = ParseInstallation.getQuery();
// Notification for Android users
//query.whereEqualTo("deviceType", "android");
push_p.setQuery(query);
push_p.setData(obj);
push_p.setChannel("channel_111");
push_p.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I read parse.com api and tutorial but I do not understand what is the problem.
thanks in advance
Add all this declarations in manifest
<!-- PARSE SERVICE AND RECEIVERS -->
<service
android:name="com.parse.PushService"
android:enabled="true" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:enabled="true"
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.app" />
</intent-filter>
</receiver>
<receiver android:name=".MainActivity$MyReceiver" >
<intent-filter>
<action android:name="com.example.update.UPDATE_STATUS" />
</intent-filter>
</receiver>
And add permissions
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
<permission
android:name="com.example.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />

Error:- getting error while getting registration id for c2dm

I have Written the application for getting registration id for c2dm. but i am getting Exception as unable to start activity component info at line startService(intent);
My main class is
public class IdTestActivity extends Activity {
static TextView mytext = null;
Context context = null;
Intent intent = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.putExtra("app",PendingIntent.getBroadcast(this, 0, new Intent(), 0));
intent.putExtra("sender", "dvimayandroid#gmail.com");
startService(intent);
}
}
My Receiver class is
public class c2dmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Registration Receiver called");
if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
Log.w("C2DM", "Received registration ID");
final String registrationId = intent
.getStringExtra("sender");
String error = intent.getStringExtra("error");
Log.d("C2DM", "dmControl: registrationId = " + registrationId
+ ", error = " + error);
// TODO Send this to my application server
}
}
}
and my manifest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.IdTest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application>
<permission
android:name="com.IdTest.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.IdTest.permission.C2D_MESSAGE" />
<activity
android:name=".IdTestActivity"
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=".c2dmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter >
<action android:name="com.google.android.c2dm.intent.RECEIVE" >
</action>
<category android:name="com.IdTest" />
</intent-filter>
</receiver>
</application>
</manifest>
It looks like you need to add a permission to your manifest. Check what's needed here, and make sure your app includes everything:
http://code.google.com/android/c2dm/#manifest
you should add the permission to reveive messages from C2DM Servers like this in your manifest :
<!-- This app has permission to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
i think you should add the registration intent filter to your service by this you could get the registration id
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="your pacakge" />
</intent-filter>
also you to get the coming registration id you use
intent.getStringExtra("registration_id");
hope that could help you

How to get the registration id for c2dm

I am trying to get the registration ID for C2DM in android for mobile app. I have tried some code but its not working properly not providing any registration id can someone help me in this case so i can get the registration id successfully for c2dm.
My main activity is
public class IdTest1Activity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent("com.google.android.c2dm.intent.REGISTER");
intent.putExtra("app",PendingIntent.getBroadcast(this, 0, new Intent(), 0));
intent.putExtra("sender", "youruser#gmail.com");
startService(intent);
}
}
my receiver class is
public class C2dmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Registration Receiver called");
if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
Log.w("C2DM", "Received registration ID");
final String registrationId = intent
.getStringExtra("registration_id");
String error = intent.getStringExtra("error");
Log.d("C2DM", "dmControl: registrationId = " + registrationId
+ ", error = " + error);
// TODO Send this to my application server
}
}
}
My Manifest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.IdTest1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<permission
android:name="com.IdTest1.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.IdTest1.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".IdTest1Activity"
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=".C2dmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" >
</action>
<category android:name="com.IdTest1" />
</intent-filter>
</receiver>
</application>
</manifest>
Change com.google.android.c2dm.intent.REGISTRATION in your receiver - .C2dmReceiver to com.google.android.c2dm.intent.RECEIVE, and it should be ok then.

Categories

Resources