Here´s my problem:
my Android app registers a boot receiver, which initializes a PushNotification-Manager (PushWoosh).
This is because even after a reboot of the device, the user should be able to receive push notifications without having to start the app manually.
This works, but when the device is rebooted, the apps main activity (MainMenuActivity) is launched and brought to the foreground, which should not happen.
Here´s the involved code:
AndroidManifest.xml:
<!-- Re-register PushManagers after reboot -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar">
<!-- PushWoosh -->
<activity android:name="com.arellomobile.android.push.PushWebview"/>
<activity android:name="com.arellomobile.android.push.MessageActivity"/>
<activity android:name="com.arellomobile.android.push.PushHandlerActivity"/>
<!-- PushWoosh -->
<receiver
android:name="com.google.android.gcm.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="de.myapp.android"/>
</intent-filter>
</receiver>
<!-- PushWoosh -->
<service android:name="com.arellomobile.android.push.PushGCMIntentService"/>
<!-- Boot-Receiever -->
<receiver android:name="de.myapp.android.startup.BootCompleteReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity
android:name="de.myapp.android.activity.MainMenuActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<!-- Starten bei Klick auf Launcher Icon -->
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<!-- Starten bei Erhalt einer Push Notification -->
<action android:name="de.myapp.android.MESSAGE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
BootCompleteReceiver.java:
public class BootCompleteReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent i) {
PushWooshHelper.setupPushNotifications(context.getApplicationContext());
}
}
PushWooshHelper.java:
public class PushWooshHelper {
public static void setupPushNotifications(Context context) {
PushManager pushManager = new PushManager(context, AppIDs.PUSHWOOSH_APP_ID, AppIDs.GCM_PROJECT_ID);
pushManager.onStartup(context);
pushManager.startTrackingGeoPushes();
}
}
MainMenuActivity.java:
public class MainMenuActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
...
}
private void checkMessage(Intent intent) {
if (intent != null) {
String log = "PUSH NOTIFICATION RECEIVED.";
if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT)) {
log += "message: " + intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT);
}
else if (intent.hasExtra(PushManager.REGISTER_EVENT)) {
log += "<register>";
}
else if (intent.hasExtra(PushManager.UNREGISTER_EVENT)) {
log += "<unregister>";
}
else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) {
log += "<register error>";
}
else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) {
log += "<unregister error>";
}
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
checkMessage(intent);
setIntent(new Intent());
}
}
Please note: I do not have access to PushManager.onStartup(), since it is provided by PushWoosh.
Any help is greatly appreciated!
That's strange. Pushwoosh uses GCM which works after restart of the device out of the box. You just have to register for the push notifications once and then after restart GCM takes care about that itself.
Related
I have my manifest in check, my services in check, my dependencies in check, class variables in check and still no notifications on my device. I'm using my computer to send firebase cloud messages and I should be receiving them on my android phone. However,my android phone is not picking up the notifications. And yes, my android device is in the background as I send the message. Anyone know what my problem is?
Here's the source code:
My Service
public class FirebaseIDMessage extends FirebaseMessagingService {
private static final String TAG = "FirebaseIDMessage";
#Override
public void onNewToken(String s) {
super.onNewToken(s);
String token = s;
Log.d(TAG, "Registered token: = " + token);
sendRegistrationToServer(token);
}
private void sendRegistrationToServer(String token){
}
}
My Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.messaging">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!-- Services -->
<service android:name=".FirebaseIDMessage"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<activity android:name=".MessagingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My Activity
public class MessagingActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messaging);
}
}
In your manifest file, you are missing INSTANCE_ID_EVENT
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
This is the intent-filter for the Class extended with FirebaseInstanceIdService
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService
{
public static final String REGISTRATION_TOKEN = "REG_TOKEN";
#Override
public void onTokenRefresh()
{
String token = FirebaseInstanceId.getInstance().getToken();
Log.e(REGISTRATION_TOKEN,token);
}
}
So, finally the manifest service will be like
<service android:name=".Utils.PushNotification.MyFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
On the log you would have got registered Token. Your all set only if you receive that token.
Goto Firebase console : https://console.firebase.google.com
Choose your project -> From the left side menu -> Choose Cloud Messaging -> New Message
Type your message and then in the TARGET choose Single Device and then copy paste your received token and check on your device for this notification by this way we can confirm you have set all notification related code correctly. If you still face any problem please let know so that I can share some samples.
I am working on deeplinking part in android, I have found branch.io provides deeplinking support. I followed everything as per documentation but still it is opening custom link instead of app.
code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="branch.next.com.newbranchapp">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:name="io.branch.referral.BranchApp""
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Branch URI scheme -->
<intent-filter>
<data android:scheme="branch" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<!-- Branch init -->
<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_abFuXvh4EU7Yocf2FB4jJpccAEcz3sZT" />
<meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_cbvEXCcXuJ27ojf1yu9sTkaitsoF0v9X" />
<!-- Branch testing (TestMode "true" to simulate fresh installs on dev environment) -->
<meta-data android:name="io.branch.sdk.TestMode" android:value="true" />
<!-- Branch install referrer tracking -->
<receiver android:name="io.branch.referral.InstallListener" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
public class MainActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();
branch.initSession(new Branch.BranchUniversalReferralInitListener() {
#Override
public void onInitFinished(BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) {
if (error == null) {
Log.i("MyApp","not working");
} else {
Log.i("MyApp", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
#Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}
}
// application
public class CustomApplication extends Application
{
#Override
public void onCreate()
{
super.onCreate();
Branch.getAutoInstance(this);
}
}
Amruta from Branch.io here:
Two things:
The name of your Application class is "CustomApplication" but in your Manifest I see the name for your Application class set to "android:name="io.branch.referral.BranchApp"". I am not sure but I believe this should give you errors in your App. This should be set to ".CustomApplication"
I just took a quick look at your Branch dashboard. Since you are testing with a link from the test version of your app (Links from the test version have the link domain of the type ".test-app.link") you should populate the Android URL for the test version in your Link Settings. You can switch between the 'Live' and 'Test' using the flipper on the top-left corner of the dashboard.
My Broadcast receiver for PHONE_STATE is working for kitkat and Lollipop version even if App is Closed but when I am using Lollipop version its not working when app is Closed
Here is my Manifest file
<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"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".BlockCallReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.USER_PRESENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
Some new android devices have security application by default. some times these apps lock your auto-start mode can you please check in settings it may be preventing boot broadcast receiver ?
Create a new app and try this;
Broadcast Receiver
public class PhoneStateReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String str = intent.getAction();
if ("android.intent.action.PHONE_STATE".equals(str))
inComing(context, intent);
if ("android.intent.action.NEW_OUTGOING_CALL".equals(str))
outGoing(context, intent);
}
private void inComing(Context context, Intent intent){
String callState = intent.getStringExtra("state");
if ("RINGING".equals(callState)){
Log.i(TAG, "RINGING SENDS BUSY");
}else if ("OFFHOOK".equals(callState)){
Log.i(TAG, "OFFHOOK SENDS BUSY");
}else if("IDLE".equals(callState)){
Log.i(TAG, "IDLE SENDS AVAILABLE");
}
}
private void trueCallerOutgoing(Context context, Intent intent)
{
String callState = intent.getStringExtra("state");
if ("RINGING".equals(callState)){
Log.i(TAG, "RINGING SENDS BUSY");
}else if ("OFFHOOK".equals(callState)){
Log.i(TAG, "OFFHOOK SENDS BUSY");
}else if("IDLE".equals(callState)){
Log.i(TAG, "IDLE SENDS AVAILABLE");
}
}
}
Manifest
<receiver android:name="PhoneStateReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
And Dont forget permission
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Is it possible to develop one application that if incoming call is coming I need to open my android app, in that I have to answer/reject the call and another option that is divert call. If i click on divert button call needs to transfer to another person. I dont have idea on this concept. Can we do it like this?
Manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<receiver android:name="MyPhoneReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
</action>
</intent-filter>
</receiver>
<receiver android:name="MyPhoneReceiver" >
<intent-filter>
<action android:name="tuet" >
</action>
</intent-filter>
</receiver>
<activity android:name="StartActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MyPhoneReceiver.JAVA
public class MyPhoneReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.e("DEBUG", phoneNumber);
}
}
}
}
StartActivity.JAVA
public class StartActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent("tuet");
sendBroadcast(intent);
}
}
Thank you!
I was debugging my app and I have experienced an interesting issue. I had a breakpoint in my onReceive method and the program has stopped there only when screen of my phone was turned on (awake).
Why is that?
If by any chance you would need my code:
private void gcmInit() {
mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
SharedPreferences sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context);
boolean sentToken = sharedPreferences
.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
if (sentToken) {
// mInformationTextView.setText(getString(R.string.gcm_send_message));
} else {
// mInformationTextView.setText(getString(R.string.token_error_message));
}
}
};
if (checkPlayServices()) {
// Start IntentService to register this application with GCM.
Intent intent = new Intent(this, RegistrationIntentService.class);
startService(intent);
}
}
Plus I have also these 2 methods in my MainActivity:
#Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(QuickstartPreferences.REGISTRATION_COMPLETE));
}
#Override
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
super.onPause();
}
My Manifest, where I register the receiver:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<!-- GCM START -->
<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.example.android.bluetoothchat" />
</intent-filter>
</receiver>
<service
android:name="com.example.android.gcm.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="com.example.android.gcm.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name="com.example.android.gcm.RegistrationIntentService"
android:exported="false">
</service>
<!-- GCM END -->
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
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=".DeviceListActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/select_device"
android:theme="#android:style/Theme.Holo.Dialog"/>
</application>