Android service not called - android

This is my service:
public class KeepAliveService extends Service {
Alarm alarm = new Alarm();
public void onCreate()
{
Log.i("","KEEPALIVE onCreate");
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onCreate start command");
return START_STICKY;
}
#Override
public void onStart(Intent intent, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onStart");
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
}
I have it declared like this in my manifest, after my :
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:icon="#drawable/ic_launcher"
android:name="com.vidyo.vidyomod.VidyoModApplication"
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:allowBackup="true"
android:supportsRtl="true"
tools:replace="android:icon">
<activity
android:name="com.vidyo.vidyomod.activities.BaseActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vidyocore" />
</intent-filter>
</activity>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:process=":remote" android:name="com.vidyo.vidyomod.utils.Alarm"></receiver>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
And on my onCreate of my BaseActivity, I do this:
Intent i= new Intent(BaseActivity.this, KeepAliveService.class);
startService(i);
I debugged, my breakpoint at startService does stop, but OnCreate is not called. why?

You have to put your Service and your BroadcastReceiver inside your application tag:
<application>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
Also, you are starting service in a different process.
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
The debugger is attached to your main process. When the new one starts, it has no debugger attached, so it will ignore your breakpoints.

Related

Background service using alarm manager

I have followed below example code for implementing Periodic background service. Periodic task executes correctly If app on foreground on 1st time. If, I close application then Background service is not working.
https://github.com/codepath/android_guides/wiki/Starting-Background-Services#using-with-alarmmanager-for-periodic-tasks
1) BroadcastReceiver service for Bootcomplete
public class BootBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Launch the specified service when this message is received
Intent startServiceIntent = new Intent(context, MyTestService.class);
context.startService(startServiceIntent);
}
}
2) BroadcastReceiver to start service
public class MyAlarmReceiver extends BroadcastReceiver {
public static final int REQUEST_CODE = 12345;
// Triggered by the Alarm periodically (starts the service to run task)
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyTestService.class);
i.putExtra("foo", "bar");
context.startService(i);
Toast.makeText(context, "Welcome --------1", Toast.LENGTH_LONG).show();
}
}
3) IntenetService class: To execute my background task
public class MyTestService extends IntentService {
// Must create a default constructor
public MyTestService() {
// Used to name the worker thread, important only for debugging.
super("test-service");
}
#Override
public void onCreate() {
super.onCreate(); // if you override onCreate(), make sure to call super().
}
#Override
protected void onHandleIntent(Intent intent) {
}
}
4) Service is started from activity as
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scheduleAlarm();
}
// Setup a recurring alarm every half hour
public void scheduleAlarm() {
// Construct an intent that will execute the AlarmReceiver
Intent intent = new Intent(getApplicationContext(), MyAlarmReceiver.class);
// Create a PendingIntent to be triggered when the alarm goes off
final PendingIntent pIntent = PendingIntent.getBroadcast(this, MyAlarmReceiver.REQUEST_CODE,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Setup periodic alarm every 5 seconds
long firstMillis = System.currentTimeMillis(); // alarm is set right away
AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
// First parameter is the type: ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC_WAKEUP
// Interval can be INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_DAY
alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis,
30000, pIntent);
}
}
5) Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="test.org.help">
<permission
android:name="test.org.help.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="au.com.KPS.companion.ACCESS_DATA" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="test.org.help.permission.UA_DATA" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- This app has permission to register with GCM and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="test.org.help.permission.C2D_MESSAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.flash"
android:required="false" />
<uses-feature android:name="android.hardware.screen.landscape" />
<application
android:name="test.org.help.KPSApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/ic_actionbar_logo"
android:theme="#style/AppTheme"
tools:replace="android:icon, android:logo">
<!-- Activities -->
<activity
android:name="test.org.help.ui.activity.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activity.JanRainLoginActivity"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activity.LinkListActivity"
android:screenOrientation="portrait" />
<activity
android:name="test.org.help.ui.activity.KPSFragmentActivity"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"></activity>
<activity
android:name="test.org.help.ui.activity.NotificationDialogActivity"
android:excludeFromRecents="true"
android:label=""
android:launchMode="singleInstance"
android:noHistory="true"
android:screenOrientation="portrait"
android:taskAffinity=""
android:theme="#style/AppTheme.Dialog.Notification"></activity>
<receiver
android:name="test.org.help.receivers.NotificationReceiver"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="test.org.help.util.ACTION_SHOW_AGENDA" />
<action android:name="test.org.help.util.ACTION_SNOOZE" />
<action android:name="test.org.help.util.ACTION_DISMISS" />
<action android:name="test.org.help.util.ACTION_SHOW_DIALOG" />
<data android:scheme="KPS" />
<data android:mimeType="text/plain" />
<data android:pathPattern="au\.org\.KPS\.util/.*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.Light.NoTitleBar"
tools:replace="android:theme,android:screenOrientation"></activity>
<activity
android:name="test.org.help.ui.activity.AppTutorialActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme"></activity>
<activity
android:name="test.org.help.ui.activity.TermsAndConditionsActivity"
android:label="#string/title_terms_and_conditions"
android:screenOrientation="portrait"></activity>
<activity
android:name="test.org.help.ui.activity.WarningActivity"
android:label="#string/title_Warning"
android:screenOrientation="portrait"></activity>
<activity
android:name="test.org.help.ui.activity.DifferentUserWarningActivity"
android:label="#string/title_Warning"
android:screenOrientation="portrait"></activity>
<activity
android:name="test.org.help.ui.activity.AppWhatsNewActivity"
android:label="#string/title_Warning"
android:screenOrientation="portrait"></activity>
<activity
android:name=".ui.activity.UserUpgradeActivity"
android:label="#string/title_upgrade"
android:screenOrientation="portrait"></activity>
<activity
android:name="eu.janmuller.android.simplecropimage.CropImage"
android:label=""
android:screenOrientation="portrait"></activity>
<!-- Facebook -->
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<!-- Services -->
<receiver android:name="com.mobileapptracker.Tracker">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service
android:name="test.org.help.service.DBUpdateService"
android:exported="false"
android:label="#string/app_name">
<intent-filter>
<action android:name="test.org.help.service.DBUpdateService"></action>
</intent-filter>
</service>
<receiver android:name="test.org.help.receivers.TimeChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
</receiver>
<activity
android:name="com.janrain.android.engage.ui.JRFragmentHostActivity"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.janrain.android.engage.ui.JRFragmentHostActivity$Fullscreen"
android:configChanges="orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateHidden" />
<!--Hockey app crash report-->
<meta-data
android:name="net.hockeyapp.android.appIdentifier"
android:value="#string/hockey_app_id" />
<receiver android:name="test.org.help.syncmanager.Network.NetworkAvailability">
<intent-filter>
<action android:name=".android.action.broadcast" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
</intent-filter>
</receiver>
<activity
android:name=".db.AndroidDatabaseManager"
android:theme="#style/Theme.AppCompat.Light" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service
android:name=".syncmanager.auto.MyTestService"
android:exported="false" />
<receiver
android:name=".syncmanager.auto.MyAlarmReceiver"
android:process=":remote"></receiver>
<receiver android:name=".syncmanager.auto.BootBroadcastReceiver">
</receiver>
</application>
</manifest>
If, implement above as sample project as separate then, background service is executing fine always. But If try to integrate with my existing code then not working...
Edited: Found Solution
It got resolved by adding full path android:name service in AndroidManifest.xml
<service
android:name="test.org.help.syncmanager.auto.MyTestService"
android:exported="false" />

Parse-Android ; Unable to receive 'action' in custom ParseBroadcastReceiver

Im sending a push message with a custom action but in the onPushReceive the action that I get is com.parse.push.intent.RECEIVE instead of com.hellboy.beat.STATUS_DONE
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hellboy.beat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<!-- permission required for Notification -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- permission required to Send SMS -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- permission required to get Location & Number -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- permission required to Vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- permission required to use Parse -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- permission required to use Parse Push -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.parse.starter.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hellboy.beat.permission.C2D_MESSAGE" />
<application
android:name="com.hellboy.beat.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hellboy.beat.main.Activity_main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.hellboy.beat.login.Activity_login" />
<activity android:name="com.hellboy.beat.requests.Activity_requests" />
<activity android:name="com.hellboy.beat.settings.Activity_settings" />
<!-- Register the Notification Receiver -->
<service android:name="com.parse.PushService" />
<!-- Regular Push Notification -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
<!-- Our Reciver -->
<receiver
android:name="com.hellboy.beat.PushRec"
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.hellboy.beat.STATUS_DONE" />
<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" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.hellboy.beat" />
</intent-filter>
</receiver>
</application>
</manifest>
PushRec.java
public class PushRec extends ParsePushBroadcastReceiver
{
private static final String TAG = "BEAT_PUSHREC";
Context context;
#Override
public void onPushReceive(Context context, Intent intent)
{
this.context = context;
Log.i(TAG, "Receiver");
if (intent == null)
{
Log.i(TAG, "Receiver intent null");
}else
{
Log.i(TAG, "Receiver intent not null");
String action = intent.getAction();
Log.i(TAG, "got action " + action );
if (action.equals("com.hellboy.beat.STATUS_DONE"))
{
//DOES NOT COME OVER HERE
}
}
}
}
Sending-Push:
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", subscriberQuery);
JSONObject obj=null;
obj =new JSONObject();
try
{
obj.put("action","com.hellboy.beat.STATUS_DONE");
obj.put("statusdone_message" , message);
} catch (JSONException e1) {
e1.printStackTrace();
}
//TODO move this to the 'cloud'
ParsePush pPush = new ParsePush();
pPush.setQuery(pushQuery);
pPush.setData(obj);
pPush.sendInBackground();
NOTE: My understanding is I'm making a mistake in the Manfiest since the notification arrives, but the wrong action is called
You can override onReceive method to dispatch your custom action.
#Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
switch (intentAction) {
case "com.hellboy.beat.STATUS_DONE":
onPushReceive(context, intent);
break;
case ACTION_PUSH_DELETE:
onPushDismiss(context, intent);
break;
case ACTION_PUSH_OPEN:
onPushOpen(context, intent);
break;
}
}
https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParsePushBroadcastReceiver.java
The error was in the Manifest; ParseBroadcastReceiver should be ParsePushBroadcastReceiver
Snippet:
<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.hellboy.beat.PushRec" >
<intent-filter>
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
And remove this from the Manifest:
<!-- Regular Push Notification -->
<!-- REMOVE THIS -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
Also in the Receiver:
public class PushRec extends ParsePushBroadcastReceiver
{
}
becomes
public class PushRec extends BroadcastReceiver
{
}

Android Parse Push Notifications Not Working - Outdated Device

I just updated the latest Parse SDK (1.11.0) and now I'm not receiving push notifications. I am able to register successfully and can see on the parse site that that my "developer" channel has been subscribed but pushes never get sent and I get this error:
PPNS - Outdated device - The records on this installation are
outdated, the user might have uninstalled the app.
Can someone please take a look at my code and see if you notice anything incorrect?
public class LSIApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "********", "********");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("developer", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
}
}`
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="${applicationId}.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="${applicationId}.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<permission android:protectionLevel="signature"
android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:name=".LSIApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="********" />
<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=".startup.PushBroadcastReceiver"
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>
</application>
Note: The ${applicationId} is 'com.broker.schlisimobile.dev' and/or 'com.broker.schlisimobile' depending on whether it's a production or developer build.
Here is my custom PushBroadcastReceiver class:
public class PushBroadcastReceiver extends ParsePushBroadcastReceiver {
#Override
protected void onPushOpen(Context context, Intent intent) {
if ( storyJSONExists(intent) ) {
if (!DataController.getInstance().getCurrentUser().isGuestUser() ) {
Intent i = new Intent(context, PushLoadingActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Intent i = new Intent(context, HomeActivity.class);
i.putExtra("promptForLogin", true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
} else {
Intent i = new Intent(context, HomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtras(i);
context.startActivity(i);
}
}
private boolean storyJSONExists(Intent intent) {
try {
String jsonString = intent.getExtras().getString("com.parse.Data");
JSONObject json = new JSONObject(jsonString);
if ( json.has("postID") ) {
return true;
}
} catch (JSONException jsonE) {
jsonE.printStackTrace();
}
return false;
}
}
In your manifest.xml comment/delete below code,
<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>
then add below code in manifest.xml
<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" />
<!--IMPORTANT: Change "com.parse.starter" to match your app's package name.-->
<category android:name="your_application_id" />
</intent-filter>
</receiver>
hope it works.

BroadcastReceiver not receiving the broadcast from IntentService when device is in sleep mode

I have a GCMBroadcastReceiver, which is receiving GCM broadcast and starting intentservice
public class GCMBroadcastReceiver extends WakefulBroadcastReceiver{
public static final String TAG = "GCMBroadcastReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "Recieved GCM broadcast, starting GCM intent service");
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GCMIntentService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
And the IntentService is sending a Broadcast (broadcast receiver is GCMNotificationObserver) before calling completeWakefulIntent on GCMBroadcastReceiver
protected void onHandleIntent(Intent intent) {
if (intent == null) {
return;
}
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String messageType = gcm.getMessageType(intent);
Log.e(TAG, "GCM message type: " + messageType);
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.
MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
onError(intent);
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_DELETED.equals(messageType)) {
onDeletedMessages(intent);
} else if (GoogleCloudMessaging.
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
onMessage(intent);
}
}
GCMBroadcastReceiver.completeWakefulIntent(intent);
}
In onMessage method I'm broadcasting
protected void onMessage(Intent intent) {
String payload = intent.getStringExtra("cm_data");
Intent broadCastIntent = new Intent(
GCMNotificationObserver.ACTION_GCM_NOTIFICATION_MESSAGE_RECEIVED);
broadCastIntent.putExtra("payload", payload);
sendBroadcast(broadCastIntent);
}
The issue I'm facing is that GCMNotificationObserver is not receiving the broadcast.
I'm suspecting the device is returning to sleep mode before broadcast is received.
Update:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=“com.test.push"
android:versionCode="126"
android:versionName=“1.0.0.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="com.android.vending.BILLING" />
<permission
android:name=“com.test.push.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.test.push.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<application
android:name="com.test.android.GlobalData"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:logo="#drawable/ab_icon"
android:theme="#style/MainTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=“com.test.push.TestActivity"
android:label="#string/app_name" >
</activity>
<receiver android:name="com.test.push.observers.NetworkStateReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<receiver
android:name=".GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.test.push" />
</intent-filter>
</receiver>
<receiver
android:name="com.test.push.observers.GCMNotificationObserver"
android:exported="false" >
<intent-filter>
<action android:name="com.test.push.observers.GCM_REGISTER" />
<action android:name="com.test.push.observers.GCM_MESSAGE_RECEIVED" />
<action android:name="com.test.push.observers.GCM_MESSAGE_DELETED" />
<action android:name="com.test.push.observers.GCM_NOTIFICATION_DISMISS" />
<category android:name="com.test.push" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>

Homescreen/launcher with Monodroid crash

I'm trying to create a launcher/homescreen. The application crashes on restart.
Debugger displays : "Unable to get provider mono.MonoRuntimeProvider". You have to wait a long time before the MonoRuntimeProvider is started, and then the app works. Any ideas to resolve this problem?
Activity1.cs
[Activity(Label = "Test application", MainLauncher = true, Icon = "#drawable/icon")]
public class Activity1 : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
try
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.NoTitle);
Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
}
catch (Exception ex)
{
Log.Error("TestError","Test Error:" + ex.Message);
}
//
}
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="Test.AndroidMono" android:versionCode="1" android:versionName="test">
<application android:label="Test AndroidMono" >
<activity android:name="monoandroidapplication2.Activity1"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.CATEGORY_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.DEVICE_POWER" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
Find the solution:
MonoRuntimeProvider is required for debugging. Once I made a release, it worked perfectly...

Categories

Resources