I have two applications installed on the device: from one app I want to start a service as follows:
Intent i = new Intent();
i.setComponent(new ComponentName("com.app.service", "com.app.service.NotificationService"));
context.startService(i);
The second app is only installed but not started.
What I want is to start the notification service(which should create a notification) from the second service by using the above code.
In the manifest file of the second app I declare the service as follows:
<service
android:name=".service.NotificationService"
android:exported="true" />
The problem is that the Notification Service from the second app does not start.
Any ideas on why this happens?
Just to be clear, the second app is the Notifications one right?
If so, what I would try is loading both apps individually first, and then creating a method in your second one to access the information from the first one.
I had a similar scenario, let me just find the solution (somewhere on my laptop) and get back to you more specifically.
Not exactly a great solution but I have fixed my problem by removing the NotificationService file from the com.app.service directory, and adding it to the com.app directory.
This fixed the issue for me, meaning that I managed to start the service of the second application from the first application.
Related
Originally, it received the BootComplete Action and tried to start automatically when the app completes booting. However, while checking because startActivity did not work, I found out that context.startActivity executed by the Action received from BoradcastReceiver does not work.
BroadcastReceiver
Intent startIntent = new Intent(context.getApplicationContext(),MainActivity.class);
startIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startIntent);
It's a very simple code that I can't explain, but it gets Received, but the app doesn't start. The existing apps seem to work without problems. It feels like a ghost.
There is a log like this, but I don't know what the problem is.
D/BootReceiver: BootRecived
D/ZLA: Setting app side flag to false due to ActivityStarter-Normal Launch
Please add the following permission to manifest and ask for user permission once when the app opened the first time by calling
startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)); somewhere in your app :
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
if you are targeting/running on Android 10 then it isn't possible to startActivity, thats Android new policy (check out HERE)
now docs suggest to show Notification and user may pick it and this will start your Activity (or may remove it and your app won't start)
How can an apps application class run at once the device starts?
Hello,
I have an application where the application class is running it's onCreate, but no activites on device startup. And i don't mean when the BOOT broadcast is sent, i mean at once the device is started.
I can see this since i've added file logging to the appliation class, but i cannot see that it comes any further (into any activities).
My manifest has
No receivers
No services with their own process id
Is there anything else that could start my application class on device start?
When i click and start the application on my device, i see logs in the application class again, but this time it has another process id than it had.
Thanks in advance!
===================
ok, so after commenting out all obvious code and manifest entries, i finally set my Sync Adapter Service to enabled=false, and then the problem did not occur. Is this normal behaviour of a sync adapter service?
I'm currently create an application that have the possibility to updated from own code thanks to a downloaded .apk from a server.
I would like to know if the update/Install of the app is successfull. Because currently the update working fine but i don't know if the installation/update is ok or not, if the installation face a problem or if the user cancel install or somethings else. So i need to have a callback "installFinish(boolean isOk)".
i search for a day but i don't find solution for my problem.
I read lot of things, particulary this :
How to find out when an installation is completed
or this :
Android - Install Application programmatically with result
but is not what i seach.
This is my code for update my app
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file.getAbsoluteFile()), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity) context).startActivity(intent);
EDIT
I tried this https://stackoverflow.com/questions/29175722/how-to-get-onactivityresult-called-from-action-view-intent
but it's not working for me for two reason i think:
I don't know whether the user pressed Cancel
onActivityResult is never call after updated the same app, maybe because it's the same app which updated the app who launch the intent is kill. ?
Maybe the last reason it's the same reason why i don't receive broadcastevent such as listening for ACTION_PACKAGE_ADDED in the app who launch the update.
Maybe i can call the method when the first time the application is launch, it's like install is successfully because the app is started.
Heres a work around which we use:
Implement a dummy provider and override onUpgrade().onUpgrade is called whenever database is upgraded.U will need maintain one to one mapping between database version and app version.
This is driving me nuts because the answer is probably staring me in the face. I'm trying to learn to make a simple service in Android using the example in http://marakana.com/forums/android/examples/60.html
But where I try to start my service
startService(new Intent(this, MyService.class));
I get "MyService cannot be resolved to a type" at build-time.
The example has this line in the Manifest just after the close of activity and before the close of application . . .
<service android:enabled="true" android:name=".MyService" />
... but I've also tried it without the "." and with a fully qualified package name, i.e., test.bg.MyService, with no improvement.
Any idea why it can't resolve it?
If you are getting "MyService cannot be resolved to a type" during the compile, or as an error from Eclipse, then there is no such class in your project.
It has nothing to do with your manifest -- problems stemming from that will not show up until runtime with the current crop of developer tools.
I'd suggest you read the documentation on Intents and Intent Filters especially the parts about Explicit and Implicit Intents.
What you are trying to do is use an Explicit Intent to start a Service using a class name which doesn't exist in the project that is attempting to start it (as CommonsWare points out).
As for your belief that...
a service is built as a separate project
...that may be possible but very often that isn't the case and even your link in your comment to CommonsWare actually demonstrates the use of a Local Service and to quote from the opening paragraph of that section...
One of the most common uses of a Service is as a secondary component running alongside other parts of an application, in the same process as the rest of the components. All components of an .apk run in the same process unless explicitly stated otherwise, so this is a typical situation.
So basically that's saying that a typical situation is that your Service will be a component of an application containing other components which will make use of that Service.
Sure, you can use a Service in another application but you need to register it in your manifest with an <intent-filter> entry and an action such as test.bg.ACTION_DO_SOMETHING and then have an external application start it using an Implicit Intent.
Using the example code you linked in your question isn't going to work.
Can someone explain me how to control one application from another application? I'm running a music player in an app1 using service class. And I want to stop that music player from another app.,i.e app2. But, I'm fallin short o the concept.
Depends what you need to do.
Opening another activity (or sending messages) is by using Intents:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
// ...
startActivity(intent);
Starting service is by using startService()
What you are trying to do can also be done using Intent broadcasts but only if your target app supports and listens to specific actions on the broadcast. You need to see if there is such an ACTION supported.
I'd like to continue this question a bit.
In my case, I'm developing the target app and I need to implement few simple procedure calls for the main app. Basically 'start', 'stop' and 'sendData'. As I wrote, I'm developing the target app so I can support whatever I want. Which would you say is the easiest way to handle.
The whole situation a bit more explained. Main app would like my app to start it's work, and if needed they'll request that I turn myself off and when the main app is closing it would request me to send my data forward.
I'm quite new to android development, so code snippets are preferable. Thank you.