How to programatically restart another android app? - android

Firstly, I understand that commonly this is not something that you typically want to do. However, the app I'm developing adds functionality to another app, but requires that the other app be restarted for it to work.
Is it possible to restart another app (i.e. -> user clicks a confirm button, other app is closed and reopened)? How would I accomplish this?
If it's not possible normally, would it be possible if the app has SU? How would it be accomplished then?

I found a way that no need root permission.
ComponentName componentName = getPackageManager().getLaunchIntentForPackage("com.xxx.yyy.zzz").getComponent();
Intent intent = IntentCompat.makeRestartActivityTask(componentName);
startActivity(intent);

There are some ways to interact with other apps through Android. Usually, intents are used for this.
You can go through this tutorial that shows what are the possible things you can do with other apps using your activity.
Especially, see the Lesson: Sending the User to Another App

I was able to uncover an answer... hopefully this will be helpful to those of you looking for the same.
Using RootTools, this is very easily done.
RootTools.killProcess(package);
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(package);
startActivity(LaunchIntent);

Related

How to configure the android intent actions in android manifest

I have a webview in my app, on trying to do actions like making a call (Tapping call button from results displayed in webview), sending mails and other actions, my webview doesn't perform those actions
I Found a solution to add the intent actions in my web view activity as
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent)
Instead of doing so is there any way to add in the android manifest file
or Is there any way to turn on all of the intent actions for the webview so that
there wont be further issues in handling the actions
Can someone help me on this pls
Your answer seems to me a bit strange, I think you are a bit confuse about the difference between Intent and manifest permission. The first one are the system used by android to let app communicate with each other, the second one allow you to use some feature of the device like wifi and direct phone call that need the explicit agreement of the user to be used (the prompt that popup when you make the first install of an app).
With this clarification it is clear that if you want to do something that require another app you will have to make an Intent. This Intent, if well formed, will be elaborated by the os that will take care of sending it to the correct application able to accomplish the Intentrequirement.
So the answer to your question, as far as i know, is no, you have to use intent if you have the need of calling external app. It's also a good practice to set in the manifest only the permission really needed by the app, this way the user know what the app really can do and and what it can't do.
Hope i understand your question and answer it.

Android intent opposite of setComponent

I know I can force an intent to use a specific application/activity by using intent.setComponent(). But is there a way to say that it should not use a specific app/activity?
Why I need this:
My application will be able to respond to several urls (like http://www.companyname.com/something/12345). If my app launches cause of an Intent to this url, I'll check if I have the needed data to handle this. (In my example, something with id 12345). If I'm not able to do something useful with the intent, I create a new Intent with the same data, so the user can try to view the content in its browser.
This is the moment my problem occurs. When I start my newly created intent, my app appears again in the list of apps that can handle this. But I already know that my app can't do anything with this intent. The user already knows that my app can't handle the intent, but still it'd be nice if my app just didn't appear in this list.
Thanks in advance.
A possible solution that works is when creating the new intent, instead of intent.setData(uri) I do intent.setDataAndType(uri, "text/html").
This causes that my app disappears from the list. At the moment it's a solution that works :) But still I'd like to know if there are better ways to achieve this result.
You may use Intent-Filters for your app and set up the URI with wildcards as you need, see here for more information. With some additional info via an action or category, you may ensure, that your app it the only one (not) matching against the intent.

How to let user know he/she needs to install another app that my app depends on

I am developing an application which has defined some intent filters (in the form of action strings, e.g. com.example.project.UPLOAD) for other applications to use. Consider a device that didn't have my application but with applications that use my intent filters, the Intent created will fail the action test as described in the documentation. Is there any way to prevent this happening or give a better user experience? Here are some of the approaches I can think of but don't know if there are feasible:
While installing an application that depends on another applications to handle some of the intents, suggest user to install the application that can handle the intent
Dynamically determine if the intent can be handled. If not, launch the market showing the application that can handle the intent
What is the best approach to handle this? Please provide some implementation references if possible.
Aside from mentioning it in the Marketplace, I'm not sure how you'd go about presenting messages during the application installation, as (to my knowledge) there is no supported way to execute code upon installation.
If other applications use your filters, then it's up to them to make sure your package is installed. You can't really give them anything without being installed.
They can test to see if a package is installed using the PackageManager, and adjust their logic to notify the user when they need to install your package. Example:
private boolean isInstalled(){
ComponentName comp = new ComponentName("com.yourpackagestuff", "com.yourpackagestuff.TestClass");
Intent intentName = new Intent().setComponent(comp);
List <ResolveInfo> list = ctx.getPackageManager().queryIntentActivities(intentName, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
That's how I'd go about it, at least.
You can try calling the Intent and catch the ActivityNotFoundException if it is thrown. If it does get thrown, you know it doesn't exist so you can implement your backup code.
This solution is quicker Android check for dependent application during installation?
getPackageManager().getApplicationInfo("com.myproject", 0 );
No exception means its ok

android can intent executes another apps code

I'm in the middle of an app where a function is implemented in its code. I have an intent too. Can this function be executed by this intent on its space. I mean like it iss intents code.
Sorry, I am not certain but think this is not possible. It would go against all security policies android cares about.

In Android, can you delete an application from another application?

If I have two applications loaded on an Android device, are there calls I can make in one that will delete the other one? I am looking for something to delete apps in a fashion similar to how I can launch an app from another.
I thought this may be possible through the Intent/Activity interactions but it doesn't seem possible. This seems like something that may not be allowed for obvious reasons but wanted to check anyways.
Follow up question, can an application remove itself?
You cannot complete the removal without user approval, but you can use an intent to bring up a screen where they can confirm the removal:
<manifest ...>
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
...
</manifest>
Uri packageURI = Uri.parse("package:"+"some.package.to.remove");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
There are apps like quick uninstaller that speed up the delete process, you'll probably need to find an Intent that deletes the app, because the user still needs to have the final say over this.

Categories

Resources