my problem is that my gcm works well and i am receiving notifications, but when the screen of my cellphone is off my GcmReceiver stop working and i do not receive notifications more
Any idea of why this is happening ? Thanks in advance!
this is my manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="schan.main"
>
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="17"/>
<permission android:name="schan.main.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="schan.main.permission.C2D_MESSAGE" />
<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:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:persistent="true"
android:theme="#style/Theme.Schan" >
<activity
android:name=".MainActivity"
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="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="schan.main" />
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</receiver>
<service
android:name="schan.main.MyGcmListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</service>
<service
android:name="schan.main.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<service
android:name="schan.main.RegistrationIntentService"
android:exported="false">
</service>
<activity
android:name=".LoginActivity"
android:icon="#mipmap/ic_launcher"
android:label="#string/login"
android:parentActivityName=".MainActivity"
android:theme="#style/Theme.Schan" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="schan.main.MainActivity" />
</activity>
<activity
android:name=".SigupActivity"
android:label="#string/joinus"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="schan.main.MainActivity" />
</activity>
<activity
android:name=".Alert"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/title_activity_alert_dialog" >
</activity>
</application>
Update
i found my real problem, is this one how can i put this configuration on my huawei cellphone?
First, you need 'Wakeful broadcast receiver' It help for the common pattern of implementing a BroadcastReceiver that receives a device wakeup event and then passes the work off to a Service, while ensuring that the device does not go back to sleep during the transition. This class takes care of creating and managing a partial wake lock for you; you must request the WAKE_LOCK permission to use it.
Second, you need to use 'delay_while_idle', it indicates that the messages not be sent immediately if the device is idle. The server will wait for the device to become active, and then only the last message for each collapse_key value will be sent. The default value is false.
Related
I'm doing my college project which was Parental Control app. In that I'm creating a Custom Receiver. I'm tested that app in jelly bean,kitkat,lollipop, marshmallow, naughat ,oreo. But it only works in jelly bean and kitkat. I'm tried reading all solutions in stackoverflow. Please give solution for me!
manifest.xml
<?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="com.nizam.training.parentalcontrol">
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application
android:fullBackupContent="false"
android:allowBackup="true"
android:icon="#mipmap/m"
android:label="#string/app_name"
android:logo="#mipmap/ico"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<service
android:name=".BlockService"
android:enabled="true"
android:exported="true"/>
<activity android:name=".AppSettingActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<activity
android:name=".BlockActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar" />
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="Login"
android:theme="#style/MyTheme" />
<activity
android:name=".SignupActivity"
android:label="Create Pin"
android:theme="#style/MyTheme" />
<activity
android:name=".TaskList"
android:label="Tasks"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true"
android:permission=""
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="StartupReceiver_Manual_Start" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<receiver android:name=".CheckRunningApplicationReceiver" />
</application></manifest>
Calling broabcast in TaskListActivity.java
getApplicationContext.sendBroadcast(new Intent("StartupReceiver_Manual_Start"))
LogCat
http://mnktalktech.blogspot.com/2019/02/logcat-for-parentalcontrol.html
I found this; it might be part of the issue. Are you getting any errors?
GET_TASKS Permission Deprecated
Please try with this.
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="false"
>
<intent-filter>
<action android:name="StartupReceiver_Manual_Start"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
and let me know.
After spending a week in this issue I have found solution for this.
What I put before (which is not working)...
getApplicationContext.sendBroadcast(new Intent("StartupReceiver_Manual_Start"))
Now I just changed.
MyReceiver mr=new MyReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("StarctupReceiver_Manual_Start");
registerReceiver(mr,intentFilter);
getBaseContext().getApplicationContext().sendBroadcast(new Intent("StarctupReceiver_Manual_Start"));
I don't know why it is working but it works.If anyone know the reason please comment. Thanks for all who tried to solve this issue.
I'm trying to setup Firebase notifications. I did changes in app level and root level build.gradle. But still, its giving me error in Manifest for MyFirebaseMessagingService. Error is Unresolved Class.
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".s" />
<activity android:name=".im" />
<activity android:name=".Main2Activity" />
<activity android:name=".sactivity" />
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<activity
android:name=".ScrollingActivity"
android:label="#string/title_activity_scrolling"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
Looks like the Android Manifest file can't locate the MyFirebaseMessagingService class. I'd suggest you to put the fully qualified package name of the class. See example below:
<service android:name="com.android.notification.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Oh! you haven't create any java class here, lets just get around it since |service| is instantiated to true on default.You should make android:enabled="false",i think this should work. see detail code below.
<service android:enabled="false" android:name="MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.fcm.MyFirebaseMessagingServices">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="com.fcm.MyFirebaseInstanceIdServices">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
I implemented GCM push notification with play services 8.4 and sending via php with high priority.
In my Android 4.3 I receive the message, even if after a few minutes while a J5 Samsung with Android 5.1 can take several hours and sometimes is not even received.
I followed the google implementation guidelines for the gcm.
In diagnosing GCM for the J5 of the message tracking token it is indicated as received by GCM but nothing else.
J5 on other applications (whatsapp) receive notifications even in standby but not mine. Now it is as I seek solutions.
I tried through alarm to wake up the manager app to input this, I tried with all the mechanisms suggested by Google but nothing.
I found the information about it of 'HeartBeat but I understood that only decreases the contact time (from 28 minutes to as many as you want in a mobile connection) of the device to the GCM but the situation would not change.
I do not care if the message comes after one hour, but the important thing is to arrive before my death.
Help!
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.customer.myapp"
android:installLocation="auto"
android:versionCode="20"
android:versionName="1.4.4" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="23"/>
<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.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"
/>
<permission android:name="com.customer.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.customer.myapp.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="23"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"
android:maxSdkVersion="23"/>
<application
android:allowBackup="true"
android:icon="#drawable/main_logo"
android:label="#string/app_name"
android:logo="#drawable/main_logo" >
<activity
android:name=".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>
<!-- .GcmBroadcastReceiver, Aggiunto exported -->
<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.customer.myapp" />
</intent-filter>
</receiver>
<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>
<receiver
android:name=".Boot"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".FBActivity"
android:label="#string/title_activity_fb"
android:parentActivityName=".Main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.customer.myapp.Main" />
</activity>
<activity
android:name="com.facebook.LoginActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<provider
android:name="com.facebook.NativeAppCallContentProvider"
android:authorities="com.facebook.app.NativeAppCallContentProviderXXXXXXXXX"
android:exported="true" />
<receiver android:name=".FacebookBroadcastReceiver" >
<intent-filter>
<action
android:name="com.facebook.platform.AppCallResultBroadcast" />
</intent-filter>
</receiver>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".WebviewAct"
android:label="#string/title_activity_webview"
android:parentActivityName=".Main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.customer.myapp.Main" />
</activity>
<activity
android:name=".ArgomentiActivity"
android:label="#string/title_activity_argomenti"
android:parentActivityName=".Main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.customer.myapp.Main" />
</activity>
<activity
android:name=".Luoghi"
android:label="#string/title_activity_luoghi" >
</activity>
<activity
android:name=".InfoActivity"
android:label="#string/title_activity_info" >
</activity>
<service android:name=".RegistrationIntentService"
android:exported="false"></service>
<receiver android:process=":remote" android:name=".BroadcastFormyapp">
</receiver>
<receiver android:name=".AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service
android:name=".ServiceAlarm"
android:enabled="true"
> <!-- android:process=":" -->
</service>
<service
android:name=".GcmIntentService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
Payload in PHP:
$fields=array(
"registration_ids"=>$registration_ids,
"delay_while_idle" => true,
"priority" => "high",
"data"=>$message
);
I have an app I'm working on where I have a broadcast receiver for outgoing calls. It works fine on the emulator, but not my Galaxy Note 2. It appears that either the Outgoing Call broadcast is never issued, or it's being consumed before I can get a hold of it.
I've heard rumours that Samsung does this funny. Hope someone knows specifically what.
Android Manifest follows.
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="OutgoingCallHandler" android:exported="true" android:enabled="true" >
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<activity
android:name="MainActivity"
android:label="#string/title_activity_main"
android:theme="#android:style/Theme.NoDisplay" >
</activity>
<activity
android:name="SettingsActivity"
android:label="#string/title_activity_settings" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
I am building a simple sms app , i want to open my app automaticaly when ever a new sms is received? is it even possible?
i am using broadcast receiver for this
what changes should i made in manifest?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.message"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MessageActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<receiver android:name=".SmsReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</activity>
<activity android:name=".Reply" >
</activity>
</application>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
</manifest>
you should move the receiver outside from the activity like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MessageActivity"
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=".Reply" >
</activity>
<receiver android:name=".SmsReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
Under Android 3.0 and later, your broadcast is not guaranteed to be received unless the user has opened your application. The application does not have to remain opened, just to have been started once. This is caused by a flag (FLAG_EXCLUDE_STOPPED_PACKAGES) which is now part of most system broadcasts, which says the broadcast should not start a stopped application.
This was already answered in How to make android launch an application on received specific sms to keep it short: it is possible with BroadcastReceiver.