I am trying to do something that I am not sure is possible or not . I have created my android application "ABC" . I have used GCM to issue notifications from my 3rd party service.
Now my client asks that he wants a history of all notifications issued by the 3rd party server . I am sceptical about this .
I believe I might be able to show a list of all notifications issued by the server WHICH ARE RESPONDED upon by the user . However I think the notifications on which the user has not responded cannot be recorded by my application .
Is this true ?
I have this broadcast receiver in my code that responds to GCM messages.
<receiver
android:name="com.mob.uae.notifications.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.evento.uae" />
</intent-filter>
</receiver>
Shouldn't this be called regardless of the user's action upon the notification ? . If this is called even when my application is shut down , then I think we do have a way to record all notifications targeted for me .
Any idea geniuses ?
The broadcast receiver is activated every time a GCM message reaches the device, regardless of the user's action. Therefore, if you wish to record the message locally on each device, you can do it.
You can even record it in the server side, if the code in the broadcast receiver would trigger a call to your server to notify it that the message was received by the app (in this case it would be better to start an intent service from the receiver, and let the service do the communication with the server).
Related
I have been scratching my head for the past few days. I am trying to intercept incoming calls in Android. For that I have used a BroadcastReceiver and registered it in my AndroidManifest.xml as follows
<receiver android:name="org.myapp.IncomingCallReceiver"
android:permission="android.permission.READ_PHONE_STATE" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
I am able to get the incoming call number in the onReceive method of my IncomingCallReceiver. But the broadcast receiver does not work if I close my app. I have seen some libraries that does work in the background. For example telephony is a flutter plugin that receives incoming SMSs using broadcast receiver. When my app using the telephony plugin is killed, it continues to receives messages in its IncomingSmsReceiver. I am not quite sure how this is happening. From adb logcat I have seen that a new proecess is created with the broadcast receiver when a new Sms is received (and the app is closed).
D Zygote : Forked child process 6287
I ActivityManager: Start proc 6287:org.sudipta.sms_handler_example/u0a525 for broadcast {org.sudipta.sms_handler_example/com.shounakmulay.telephony.sms.IncomingSmsReceiver}
One thing to notice is that the plugin does not use any Service. There is a closed issue in github regarding this. The author of the plugin replied that
Yes listening in the background will work even if you don't open the app. The reason this works is we are registering a static broadcast receiver in the app's manifest file. That means the android system can initialize that broadcast receiver independent of the app.
My question is that if this really is the case. Will Android system keep the broadcast receiver alive (by forking a new process)? My understanding is that by default this is not going to work, al least that is not happening with my code, the receiver does not get hit when a call is received and the app is not running.
The author of the plugin further replied that
In most cases the device manufacturers and custom android OS environments block most of the app from performing operations in the background. That means your app won't receive any broadcasts and if it tries to start services in the background those will be killed as well.
But I have created a single sample app and using Telephony plugin and my own code (a simple receiver with the above manifest entry). While the plugin works in the background, my code doesn't.
Some help would be nice.
Thanks
I've been parsing the web for a way to create a VPN client on Android. I can't seem to find any good resources on how to do this.
The goal is , I would like to be able to setup a VPN using either the built in VPN feature in Android (perhaps programatically adding a new connection) or otherwise.
I did come across the VpnService in the docs but its unclear on how to use it. Does anyone have a good example of doing this and is this possible with the Android SDK as at this time?
Android gives a sample code ToyVpn which you can look and reuse logic for your need.
And here is some details from documentation
There are two primary methods in this class: prepare(Context) and VpnService.Builder.establish(). The former deals with user action and stops the VPN connection created by another application. The latter creates a VPN interface using the parameters supplied to the VpnService.Builder. An application must call prepare(Context) to grant the right to use other methods in this class, and the right can be revoked at any time. Here are the general steps to create a VPN connection:
When the user presses the button to connect, call prepare(Context) and launch the returned intent, if non-null.
When the application becomes prepared, start the service.
Create a tunnel to the remote server and negotiate the network parameters for the VPN connection.
Supply those parameters to a VpnService.Builder and create a VPN interface by calling VpnService.Builder.establish().
Process and exchange packets between the tunnel and the returned file descriptor.
When onRevoke() is invoked, close the file descriptor and shut down the tunnel gracefully.
Services extending this class need to be declared with an appropriate permission and intent filter. Their access must be secured by Manifest.permission.BIND_VPN_SERVICE permission, and their intent filter must match SERVICE_INTERFACE action. Here is an example of declaring a VPN service in AndroidManifest.xml:
<service android:name=".ExampleVpnService"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="android.net.VpnService"/>
</intent-filter>
</service>
I want to give the user the option to import the his WhatsApp chats in my app. The chats can be exported in WhatsApp as Txt-File sent in an email as attachment with the option "Send chat by email". The problem is, I don't know how to receive the Intent WhatsApp is sending to get avaivable email apps. The java code is already finished, but in the AndroidManifest.xml file I dont know what to write to be known as email app.
Edit
I don't want to send E-Mails, but I want that the user has the possibility to import Chat-Data for the chatbot App I am programming.
In order to list your app as an option to receive Intent.ACTION_SEND, you have to do:
1: Register your app as an e-Mail client, you can use Gmail API from Google to send and receive e-Mails.
2: Use intent-filter in your Mainifest.xml as
<action android:name="android.intent.action.SEND" />
Simple tutorial at: Android Developer | Receiveing simple data
Since WhatsApp sends chats as a .txt attachment, so you need to register for that data-type in your intent-filter too.
I use NotificationListenerService to catch notifications and elaborate them in my application. App works great and onNotificationPosted is always called, but after a while (Few hours) it stops being called and the app stops working.
It gets back to work only if I reboot my device or if I revoke and grant again notification access to the application.
Important info
App does have notification access enabled.
App does have service on AndroidManifest.
<service
android:name=".NotificationService"
android:label="#string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>
App is a release version (Same problem on debug version though).
It has been tested on Android Lollipop, Marshmallow and Nougat, same result.
It has been tested in different devices running the same Android version.
App stops working in both background and activity displayed on screen.
It works again if I reinstall the application, but this is already included in 'revoke and grant notification access again' previously mentioned.
App includes AdMob banner on bottom, is it a possible problem?
I read Android has a cache problem or something like that. Is this the problem? Is there any permanent solution that I couldn't find anywhere?
I found the answer myself here:
https://gist.github.com/xinghui/b2ddd8cffe55c4b62f5d8846d5545bf9
Just create a new class as in the link above, then put in onCreate:
startService(new Intent(this, NotificationCollectorMonitorService.class));
And in AndroidManifest:
<service android:name=".NotificationCollectorMonitorService"/>
This will restart your NotificationListenerService whenever Android kills it.
I have been following TheNewBoston tutorials on Broadcast intents, but I have an issue. Basically, I have two apps:
1) Recieve Broadcast
2)Send_Broadcast.
They do what their name suggests using intents, and Recieve Broadcast responds to the broadcast by displaying a toast on the screen. At this point of time, I have built both apps, and am getting no errors. After running both though, nothing happens when I send the broadcast by pushing the button. Please help me with this issue, as I have been trying to fix this for almost two hours now! (I have also re-set the api from 8-14)
This is the java class for send broadcast, it sends the broadcast when you push this button:
This is the XML for send broadcast, it sends the broadcast when you push this button:
Here is the receiver:
And the manifest which filters out certain broadcasts:
I have not added a layout to recieve broadcast, it works behind the scenes. Thank you so much for all of your help, I really appreciate it. If you need more information, feel free to ask!
I would appreciate any feedback! :)
Did you intend to put your filter on your receiver?
<receiver android:name=".RecieveBroadcast">
<intent-filter>
<action android:name="com.example.xxx.send_broadcast" />
</intent-filter>
</receiver>