How to get the content://mms-sms/conversations intent in Android? - java

Hi I want to know how to specify to a Broadcast Receiver that I want to listen for the content://mms-sms/conversations intent.
In Log cat you can see the Intent fired when you open the messages Application on the emulator or real device. I want to trigger an action when this Intent gets activated.
Thanks in advance for your help.

I want to know how to specify to a Broadcast Receiver that I want to listen for the content://mms-sms/conversations intent.
That is not possible.
In Log cat you can see the Intent fired when you open the messages Application on the emulator or real device.
Correct. However, that is starting an activity. You cannot register a BroadcastReceiver to find out when the user starts any particular activity.

Related

Foregound Service start action from MainActivity

I am working on an Android fall detection application. When user falls, alarm with timer turns on and if user not clik cancel within 15s, app send SMS to contact. Everything works fine when app is open but I don't know how my foreground service should work. Is it possible to make foreground service work like that- after fall detected foreground service open application and run timer from Main Activity?
Code from foreground service opening MainActivity:
Intent myIntent= new Intent(this, MainActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
There are two obstacles to your use case:
Firstly, starting from Android 10, there are new restrictions on starting an activity when your app is in the background (and as it's written on the android developer page, even with a foreground service, your app will be considered in the background if no activities are in foreground). So you won't be able to "pop" a view to the user, except if you target a version < 29 (but it's not very recommended).
Secondly, since the beginning of 2019, the Google Play Developer Policy has been updated and you cannot use anymore the SEND_SMS permission, unless if you can justify in the publish console that your app is an SMS handler and you will need the user to register it as the default one. So you won't be able to send an automatic text message directly.
You can try to change the notification message to alert the user and try to have him click on the notification to open an activity.

How Do I Use getWindow() In A Service or Broadcast Receiver Classes?

I am trying to create an app that will keep my device wake until I tell it to turn off via code. I can use the follow code in a application...
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
That will work until I tap on the home soft button and then the flags will clear. So, I thought of putting that code in a foreground notification service and broadcast receiver for my action buttons. I can't getWindow in a service or broadcast receiver classes unfortunately. Is there an easy way to get around this?
My goal is to setFlags to keep the screen on from the Activity, and then the service takes over from there so I can close the app, and the keep on screen stays on until the service is turned off.

Start Activity on Reboot Only

Basically I am trying to make an activity containing a button which reboots the device and after the reboot returns to the same activity.
I understand that this question may get confused with others about rebooting the device, but that is not the focus of this question as I can get the device to reboot fine.
I have made the button reboot the device but the only way I can get it to start the activity after it's finished rebooting is to register a broadcast receiver for BOOT_COMPLETED in the manifest. The trouble is that this method starts the activity every time the device boots which is undesirable. When I register the receiver on the button click listener it does not start the activity after the reboot.
I was wondering if there might be an extra in BOOT_COMPLETED that I could use to decide if it had been purposefully rebooted.
Any advice would be appreciated, thanks in advance!
Just save an integer corresponding to device purposely being rebooted through your activity. Use SharedPreference for the same. On reboot, in your broadcast receiver, check if the value is set. If it is set, start your activity, otherwise, let it go.
EDIT :
Always, unset this value when reboot is complete and your Activity is in front.
Your XML should be stored in a file named AndroidManifest.xml, not manifest.java.
Another reason your code is not being run, might be that your App is installed on external storage (sdcard). BOOT_COMPLETE is sent to applications before external storage is mounted. So if application is installed to external storage it won't receive BOOT_COMPLETE broadcast message.
If that isn't the problem, there is already a very good description of how to get boot completed receivers working on Android.
Trying to start a service on boot on Android

Controlling activity instance visibility through a service?

I have an activity which can be launched from two sources. Each source launches it's own instance of the activity:
1. From inside an application
2. From an external service
My problem is with the service. The service needs to be able to control the visibility of the activity on the Android screen (hide and show the activity).
Currently I start the activity from the service with the following intent:
Intent appIntent = new Intent("Custom_Action");
appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(appIntent);
My question is, how can I control the visibility of the activity. Maybe through binding the activity to the service?
I think you're misunderstanding how services and activities relate. A service runs in the background, doing it's thing. It has no UI and no way for the user to interact with it. The activity can send the service messages and query its state but the service has no way to push information to an activity. If you want the service to notify the user of something you can post a notification. Then have that notification launch your activity which will then connect to the service. There is no way to force open an activity from a service because there is no way to know if your user is even looking at their device at that time.

How to keep Listening for Push Notifications on Android in the background

I am working on Push Notifications in Android. Now the issue is that I want to keep running my Push Notifications on the back ground as soon as the app start because I have no idea when the server will push the data to the devices.
The main requirement is that our corporate app is having more than 10 activities and based on the notification received, I have to bring the related activity on the foreground so that user can preform action on that or do some silent action in the background regardless the activity is in foreground.
Can somebody suggest how can I implement this type of requirement. Do I need to do it in a Service.
Thanks
An Android application on an Android device doesn't need to be running to receive messages. The system will wake up the Android application via Intent broadcast when the message arrives, as long as the application is set up with the proper broadcast receiver and permissions.
take look at this;
http://developer.android.com/guide/google/gcm/gcm.html
when message received from gcm server
onMessage(Context context, Intent intent): method of GCMIntentService gets fire,
so you write your code there
take sample example from here
https://github.com/ketanpatel25/GCM-Demo/tree/master/gcm
What you're trying to do defeats the purpose of push notifications. In push notifications, the server sends the message through Google APIs. These APIs then send a broadcast message to your app, which you listen for. Continuously keeping the app open in the background and asking the server for new messages is called polling.
Read up on the GCM documentation. Whenever you receive a message, Android will ca the onMessage(); method of your GCMIntentService.

Categories