Is it possible to uninstall one android application from other application? - android

Suppose there are two different Android apps: A and B.
App A is a system admin. Is there any way for it to uninstall app B or make it non-functional?

Yes, it is possible, you need to use Intent.ACTION_DELETE have a look at following code,
Uri packageUri = Uri.parse("package:com.mypackgage");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,packageUri);
startActivity(uninstallIntent);
when you run the above code, it will ask for uninstall application as follows, image

try below code for uninstall apk...
Uri packageURI = Uri.parse("package:com.example.uninstall"); // replace with your package name
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(uninstallIntent);

By using the below code snippet you can uninstall an installed application on your ANDROID phone.It redirected you to the uninstall confirmation...
Create an intent object with an action and data as the package name
and start with the ACTION_DELETE.
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.pack.Applicationname"));
startActivity(intent);

Related

How run a native android Activity using titanium module?

I need to call a custom activity that is written in android in titanium studio.
How should I run this code in accelerator?
The module code is this :
ChoosePDFActivity cpa = new ChoosePDFActivity();
Intent intent = new Intent();
intent.setClassName("com.pdfreader.my", "com.artifex.mupdf.MuPDFActivity");
Activity activity = TiApplication.getAppRootOrCurrentActivity();
activity.startActivity(cpa.showPDF());
Tiapp setting is :
<modules>
<module platform="android">com.pdfreader.my</module>
</modules>
and titanium code is :
var sample_module = require('com.pdfreader.my');
sample_module.example()
Nothing happen whenever i run my code? if i return a string i can show it in my titanium but i cannot run activity, can anyone help me?
thanks
I solved my problem by changing my Java code:
final File file = new File(path);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent();
intent.setClassName("com.artifex.mupdf", "com.artifex.mupdf.MuPDFActivity");
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
Activity activity = TiApplication.getAppRootOrCurrentActivity();
activity.startActivity(intent);
require() is used to include CommonJS modules inside, it doesn't create Intent.
If you want to create Intent inside your titanium application follow documentation about Android platform

Get all services with PackageInfo

I have a problem with an app of mine. I use this code to uninstall a package, fired from a Service:
Uri packageUri = Uri.parse("package:"+packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(uninstallIntent);
The problem is, I've heard from someone who is using this app that there is no uninstall dialog opening on a Sony Xperia Z. It works on my Samsung phones, one with Touchwiz and one with Cyanogenmod and also on my Nexus 7.
I tried to change the intent to:
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
This also works on my devices but not his. Anyone who has an idea why?
Try this:
Intent deleteIntent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("com.the.package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(deleteIntent);
hope it helps

How do I open android built in downloads app?

So I'm downloading stuff and it gets put into the built in downloads app since thats how the download manager works. I just want to the user to click a button which opens the built in downloads app.
Heres my try:
btnDownloads.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
PackageManager pakMan=MainActivity.context.getPackageManager();
Log.d("bebr", "Making pak");
if(pakMan!=null){
Intent downloadsIntent=new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("com.android.downloads","com.android.downlods.Downloads"));
ResolveInfo resolved=pakMan.resolveActivity(downloadsIntent, PackageManager.MATCH_DEFAULT_ONLY);
Log.d("bebr","Resolving");
if(resolved!=null){
Log.d("bebr", "Starting");
startActivity(downloadsIntent);
}
}
}
});
Ok finally managed to get the solution:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
Use the DownloadManager.ACTION_VIEW_DOWNLOADS constant:
startActivity(new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS));
You'd have to know the package name to launch the Downloads application. I am not certain that it is the same on every device either (though it may be). You can find it by watching the Logcat and launching it you should see some line in the log that has the package name in it.
However you can skip the downloads app completely and launch the package installer directly (which is what will happen when the user selects your apk in the downloads app)
just fill in the path to the file in the following snippet:
File appFile = new File("/path/to/your/file.apk");
Uri packageURI = Uri.parse("file:/"+ appFile.getAbsolutePath());
Intent installIntent = new Intent(Intent.ACTION_VIEW);
installIntent.setDataAndType(Uri.fromFile(appFile),"application/vnd.android.package-archive");
startActivity(installIntent);

How to launch the stock installer app in android

I used to have this problem but I found a solution, so just decided to post it here just in case someone else needs it.
How to launch the native installer app to install an apk?
Many posts have the solution as below:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(path), "application/vnd.android.package-archive");
context.startActivity(intent);
This is fine except a tiny but crutial detail:
the "path" string must start with file:// otherwise you'll get an exception such as
Unable to find an activity to handle the intent .....
So make sure the path starts with file://
Cheers.
Actually, instead of using the parse(...) method, you can simply use the fromFile(...) method of the Uri class (the Uri will automatically have the form "file://").
Thus:
final File file = new File(path);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
context.startActivity(intent);

launch facebook app from other app

How can I launch a facebook app from my app in android?
Looking at the latest Facebook apk (1.6), it looks like both "facebook://" and "fb://" are registered protocols.
facebook://
facebook:/chat
facebook:/events
facebook:/friends
facebook:/inbox
facebook:/info
facebook:/newsfeed
facebook:/places
facebook:/requests
facebook:/wall
fb://
fb://root
fb://feed
fb://feed/{userID}
fb://profile
fb://profile/{userID}
fb://page/{id}
fb://group/{id}
fb://place/fw?pid={id}
fb://profile/{#user_id}/wall
fb://profile/{#user_id}/info
fb://profile/{#user_id}/photos
fb://profile/{#user_id}/mutualfriends
fb://profile/{#user_id}/friends
fb://profile/{#user_id}/fans
fb://search
fb://friends
fb://pages
fb://messaging
fb://messaging/{#user_id}
fb://online
fb://requests
fb://events
fb://places
fb://birthdays
fb://notes
fb://places
fb://groups
fb://notifications
fb://albums
fb://album/{%s}?owner={#%s}
fb://video/?href={href}
fb://post/{postid}?owner={uid}¹
Sorry if I missed some... only played with a handful of them in the emulator to see if they actually work - a bunch of them will cause the Facebook application to crash.
¹ where postid is in the uid_postid format, e.g 11204705797_10100412949637447
To just start the default Launcher Activity:
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
I did some research, because I wanted to find this out :). I found some ways how to start different activities easily. But I can not guarantee that this will work after upgrades of facebook. I tested it with my current facebook app and it works. At least I tested it with "adb shell" using "am start .....".
Basic is:
String uri = "facebook://facebook.com/inbox";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
the facebook.com part is not checked. you can even type: "facebook://gugus.com/inbox" having the same effect.
How to do this in adb.
1. Start adb shell through console: "adb shell"
2. run: "am start -a android.intent.action.VIEW -d facebook://facebook.com/inbox"
this will start the inbox activity.
Here some Uris with examples. I think they speak for themselves what they do.
facebook://facebook.com/inbox
facebook://facebook.com/info?user=544410940 (id of the user. "patrick.boos" won't work)
facebook://facebook.com/wall
facebook://facebook.com/wall?user=544410940 (will only show the info if you have added it as friend. otherwise redirects to another activity)
facebook://facebook.com/notifications
facebook://facebook.com/photos
facebook://facebook.com/album
facebook://facebook.com/photo
facebook://facebook.com/newsfeed
there might be additianl parameters you can give to certain of those uris, but I have no time to go through all the code of those activities.
How did I do this? check out apktool.
If any one want to directly open a photo
public Intent getOpenFacebookIntent(String pId) {
try {
activity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("facebook:/photos?album=0&photo=" + pId + "&user=" + ownerId));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"));
}
}
startActivity(getOpenFacebookIntent(pid));
where ownerId is the Facebook id of the user who uploaded this picture and pid is PhotoId
Enjoy :))
Launching of another application from your application in android, can be done only if Intent action you fire matches with intent filter of other application you want to launch.
As #patrick demonstrated, download facebook.apk to emulator and try to run that through adb shell command. It works fine..
Pass Intent filter and data as an Uri
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/groups/14531755***6215/")));
This directly opens facebook group having the id: 14531755***6215 inside fb app

Categories

Resources