I have found this post how to make an application to start after Android OS boot is completed. I have done it good - I am catching the broadcast android.intent.action.BOOT_COMPLETED, but unfortunately my app crashes and I cannot observe it with logcat because I have to reboot the device in order to see if my feature is working.
Does anybody know how can I catch an exception so I can see why my app is crashing OR does anybody know what could be the problem (if you have experienced the same problem)?
I have solved the problem... The initial intent was:
Intent i = new Intent();
i.setClassName("com.example.app", "MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
I made a toast with exception in it and made printscreen on emulator.
The exception said this:
android.content.ActivityNotFoundException: Unable to find explicit activity class{com.example.app/com.example.app.MainActivity}; have you declared this activity in your AndroidManifest.xml?
After checking, my activity was in the file. So I googled this
and made correction in my intent to:
Intent i = new Intent();
i.setClassName(context.getPackageName(), "com.example.app.sunshine.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
and context.startActivity(i); started the app after reboot.
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)
I was starting activity from services till android P, but from android10 google has kept one restriction that activity cannot be started from background.
https://developer.android.com/guide/components/activities/background-starts
// below code stopped working
Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
what should i do for android10 ?
You can use a notification using setFullScreenIntent, it's the best you can do or you can ask for SYSTEM_ALERT_WINDOW permission but it doesn't work with android go devices.
Is it possible to run android application from android application? For example, i have a button in application 1 and when i press that button i want application 2 to start. I'm developing application in react-native.
I tried with Linking component but I'm getting this error "No Activity found to handle Intent". So i tried to edit AndroidManifest.xml, also without much success.
Thanks in advance.
Yes through Intent we call Activity of another application like below Intent by passing Application Package name and its class name with full package name .
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.example", "com.example.MyExampleActivity"));
startActivity(intent);
Allowing Other Apps to Start Your Activity
I've got some strange problem with bringing the application to foreground. As it's said in Android documentation using startActivity(myIntent) should bring application from background and it worked until upgrade Android on HTC Desire HD to version 2.3.5. At this version this method doesn't work at all. Application is running in the background even if I add singleInstance flag
Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT.
This is the code snippet where I create the intent and launch activity
Intent intent = new Intent();
intent.setClassName(self.ctx, "com.app.WakeUp");
ctx.startActivity(intent);
The ctx variable is a context passed to the object from Activity instance and com.app.WakeUp is a name of Activity to start.
Some ideas what is going on?
I almost forgot about this question.
The cause of the problem with waking up intent probably is a bug in HTC Desire HD with Android version 2.3.5 (unfortunatelly have no build number). Simple workaround (but not so simple to discover) is for example remote service which can bring the intent to the front.
In this app I'm developing I need to load/call another app that is already installed on the phone. It's an application for my own personal use only, so no need to check if the other app is installed - I know it is.
I've googled this problem for hours, but I can't find anything that works. Mostly because the guidelines for finding package name and class name are really bad.
Via cmd and adb I was able to find that the info regarding the application I'd like to call is:
package:/data/app/com.soundcloud.android-1.apk=com.soundcloud.android
(that's exactly what it said in the cmd window.)
I tried something like this:
Intent i = new Intent();
i.setClassName("/data/app/com.soundcloud.android-1.apk", "com.soundcloud.android");
startActivity(i);
But my app just crashes instead. I used the above code because someone said that this could call an app:
Intent i = new Intent();
i.setClassName("<package_name>","<Class Name(with package name)>");
startActivity(i);
Does anyone know what to really write?
P.S.: my own app does not need any information about what's happening in the called app.
Use the PackageManager to get an Intent for the package:
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.example.package");
startActivity(intent);
The documentation is
here.
I think in your example, com.soundcloud.android is in fact the package name, so that should be the first argument. For the second one, you still need to figure out the class to use.
If you don't have the code, you can check how to find out the class from the apk with this.