Get system default package name - android

How can I know which is the package name of default system app if user has one defined? By example get the package name of system default music app to stop it

solved:
String mKillAppName = null;
headsetPlugIntent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
Intent.CATEGORY_APP_MUSIC);
ResolveInfo da = mContext.getPackageManager()
.resolveActivity(headsetPlugIntent,PackageManager.MATCH_DEFAULT_ONLY);
mKillAppName = da.activityInfo.packageName;

Related

How does "parallel apps" feature work on OnePlus 3 devices, and how can we use Intents properly with them?

Background
Apps use Intents to open other apps, sometimes with specialized Intents.
One example is this Intent, to choose a contact from WhatsApp:
val WHATSAPP_PACKAGE_NAME = "com.whatsapp"
val whatsAppPickIntent = Intent(Intent.ACTION_PICK).setPackage(WHATSAPP_PACKAGE_NAME)
This works fine in general. Same goes for when you wish to launch the app:
val launchIntent=packageManager.getLaunchIntentForPackage(WHATSAPP_PACKAGE_NAME)
The problem
Recently I was informed of a relatively new feature, allowing the user to have multiple instances of the same app. It might be available on other devices, but on OnePlus devices it's called "parallel apps". Here's an example of 2 instances of WhatsApp, each is assigned to a different phone number :
Thing is, this can break how Intents work with a single instance of the app. Now the Intent doesn't know for which app to go to. The launcher show 2 icons now for WhatsApp:
If you choose to launch WhatsApp via the normal launcher icon (the left one), it shows this dialog:
Works fine, but if you choose to use the picker intent, you still get this dialog, but when you choose an item, from the dialog, it doesn't let you really do anything with it (opens and closes the app), while showing a toast "The file format is not supported".
What I've tried
Since I don't have the device, I tried to read about it over the Internet, but I only found user-related information, such as these:
https://www.androidpolice.com/2017/08/04/new-oneplus-33t-open-beta-adds-parallel-app-support-run-multiple-instances-app/
https://www.techrepublic.com/article/how-to-run-cloned-versions-of-apps-with-oneplus-parallel-apps/
I've decided to try to investigate it further, by sending an APK to the person who told me about it, trying to see if the next code will work any different:
val whatsAppPickIntent = Intent(Intent.ACTION_PICK).setPackage(WHATSAPP_PACKAGE_NAME)
val queryIntentActivities: List<ResolveInfo> = packageManager.queryIntentActivities(whatsAppPickIntent, 0)
button2.setOnClickListener {
intent = Intent(Intent.ACTION_PICK)
val resolveInfo = queryIntentActivities[0]
toast("number of possible choices:" + queryIntentActivities.size)
intent.component = ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name)
startActivity(intent)
}
The toast that will be shown tells that I have only one thing that can handle the intent, and indeed when I use it, I get the same dialog for choosing which instance of it to use. And like in the original Intent, it fails with the same toast.
EDIT: Later I tried the next thing: I asked to show what are the ResolveInfo properties, before and after enabling the feature, by using this code:
val launchIntent = packageManager.getLaunchIntentForPackage(WHATSAPP_PACKAGE_NAME)
val whatsAppPickIntent = Intent(Intent.ACTION_PICK).setPackage(WHATSAPP_PACKAGE_NAME)
var queryIntentActivities: List<ResolveInfo> = packageManager.queryIntentActivities(whatsAppPickIntent, 0)
var sb = StringBuilder()
queryIntentActivities[0].dump(object : Printer {
override fun println(x: String?) {
if (x != null)
sb.append(x)
}
}, "")
val pickResult = "pick result:packageName:\"" + queryIntentActivities[0].activityInfo.packageName + "\" name:\"" + queryIntentActivities[0].activityInfo.name + "\"\n\n" + "extended:" + sb.toString()
sb = StringBuilder()
queryIntentActivities = packageManager.queryIntentActivities(launchIntent, 0)
queryIntentActivities[0].dump(object : Printer {
override fun println(x: String?) {
if (x != null)
sb.append(x)
}
}, "")
val launchResult = "launch result:packageName:\"" + queryIntentActivities[0].activityInfo.packageName + "\" name:\"" + queryIntentActivities[0].activityInfo.name + "\"\n\n" + "extended:" + sb.toString()
val body = pickResult + "\n\n" + launchResult
val emailIntent = Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "", null))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "whatsApp investigation")
emailIntent.putExtra(Intent.EXTRA_TEXT, body)
startActivity(Intent.createChooser(emailIntent, "Send email..."))
The result is that both are the same, as if everything is fine. Here's the result when it's turned on/off (exact same thing) :
pick result:packageName:"com.whatsapp" name:"com.whatsapp.ContactPicker"
extended:priority=0 preferredOrder=0 match=0x108000 specificIndex=-1 isDefault=falseActivityInfo: name=com.whatsapp.ContactPicker packageName=com.whatsapp enabled=true exported=true directBootAware=false taskAffinity=com.whatsapp targetActivity=null persistableMode=PERSIST_ROOT_ONLY launchMode=0 flags=0x3 theme=0x7f110173 screenOrientation=-1 configChanges=0xfb3 softInputMode=0x0 lockTaskLaunchMode=LOCK_TASK_LAUNCH_MODE_DEFAULT resizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION ApplicationInfo: name=com.whatsapp.AppShell packageName=com.whatsapp labelRes=0x7f100473 nonLocalizedLabel=null icon=0x7f080c15 banner=0x0 className=com.whatsapp.AppShell processName=com.whatsapp taskAffinity=com.whatsapp uid=10099 flags=0x3 privateFlags=0x1010 theme=0x7f110164 requiresSmallestWidthDp=0 compatibleWidthLimitDp=0 largestWidthLimitDp=0 sourceDir=/data/app/com.whatsapp-NaKTLVhiNTh4zEGhFdkxrg==/base.apk seinfo=default:targetSdkVersion=26 seinfoUser=:complete dataDir=/data/user/0/com.whatsapp deviceProtectedDataDir=/data/user_de/0/com.whatsapp credentialProtectedDataDir=/data/user/0/com.whatsapp enabled=true minSdkVersion=15 targetSdkVersion=26 versionCode=452238 targetSandboxVersion=1 supportsRtl=true fullBackupContent=true category=4
launch result:packageName:"com.whatsapp" name:"com.whatsapp.Main"
extended:priority=0 preferredOrder=0 match=0x0 specificIndex=-1 isDefault=falseActivityInfo: name=com.whatsapp.Main packageName=com.whatsapp labelRes=0x7f10044c nonLocalizedLabel=null icon=0x0 banner=0x0 enabled=true exported=true directBootAware=false taskAffinity=com.whatsapp targetActivity=null persistableMode=PERSIST_ROOT_ONLY launchMode=0 flags=0x3 theme=0x0 screenOrientation=-1 configChanges=0xfb3 softInputMode=0x0 lockTaskLaunchMode=LOCK_TASK_LAUNCH_MODE_DEFAULT resizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION ApplicationInfo: name=com.whatsapp.AppShell packageName=com.whatsapp labelRes=0x7f100473 nonLocalizedLabel=null icon=0x7f080c15 banner=0x0 className=com.whatsapp.AppShell processName=com.whatsapp taskAffinity=com.whatsapp uid=10099 flags=0x3 privateFlags=0x1010 theme=0x7f110164 requiresSmallestWidthDp=0 compatibleWidthLimitDp=0 largestWidthLimitDp=0 sourceDir=/data/app/com.whatsapp-NaKTLVhiNTh4zEGhFdkxrg==/base.apk seinfo=default:targetSdkVersion=26 seinfoUser=:complete dataDir=/data/user/0/com.whatsapp deviceProtectedDataDir=/data/user_de/0/com.whatsapp credentialProtectedDataDir=/data/user/0/com.whatsapp enabled=true minSdkVersion=15 targetSdkVersion=26 versionCode=452238 targetSandboxVersion=1 supportsRtl=true fullBackupContent=true category=4
So I wanted to check on something else: Try to put a widget-shortcut of WhatsApp (called "whatsApp chat"), that requires you to choose a contact, when this feature is turned on.
Turns out, it can't handle it well. It asks which app to create the widget to: the original or the clone. If you choose the original, all is fine. If you choose the clone, it adds the widget all fine and well, but when clicking on it, it goes to the main window of the app instead of going to the person.
The questions
How can I differentiate between the main instance and the "cloned" one? I mean, how can an Intent be directed to a single instance (the main one) of the targeted app? I ask this about both of the Intents I've presented (launch and picker).
How does this feature even work? Where does the private data of each instance gets saved now? Does each of them have a process, with a different name?
Do other devices of other OEMs have this feature? Does it work there the same way as here ?
Why do we see the toast message, if the user chose the app to target to? Is it maybe a buggy feature, that will work only for launch-intents?
Is there at least a way to know that a given app (given a package name of it) has this feature enabled for it?

How to send file to google cloud printing app via intent in android 5?

I'm trying to tell the google cloud printing app to print a document, be it a .png file or an pdf. After checking if the app is installed via
public static boolean isCloudPrintInstalled(Context ctx){
String packageName = "com.google.android.apps.cloudprint";
android.content.pm.PackageManager mPm = ctx.getPackageManager();
try{
PackageInfo info = mPm.getPackageInfo(packageName, 0);
boolean installed = (info != null);
return installed;
}catch(NameNotFoundException e){
return false;
}
}
i send the user to the PrintingDialogActivity if it is missing, as described here: https://developers.google.com/cloud-print/docs/android
But i would like to use the app, if it is installed. If i send the following intent:
File theFile = new File(filePath); //file is NOT missing
Intent printIntent = new Intent(Intent.ACTION_SEND);
printIntent.setType(Helper.getMimeType(filePath));
printIntent.putExtra(Intent.EXTRA_TITLE, titleOfFile);
printIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(theFile));
ctx.startActivity(printIntent);
The getMimeType method is this:
public static String getMimeType(String url) {
String method = "Helper.getMimeType";
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
//Fix for Bug: https://code.google.com/p/android/issues/detail?id=5510
if(extension == null || extension.equals("")){
extension = url.substring(url.lastIndexOf('.'));
}
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
//should i consider just not using the MimeTypeMap? -.-
if(type == null || type.equals("")){
if(extension.toLowerCase(Locale.getDefault()).equals(".txt") == true){
type = "text/plain";
}else{
Log.e(method, "Unknown extension");
}
}
return type;
}
it returns "application/pdf" for pdf files.
On my android 4.0.3 device i get the action chooser and can choose the google cloud print app, which then allows to do stuff like saving the file to google drive. It works.
But if i start this intent on my Android 5.1.1 device (Nexus 5), the action chooser also opens, but it doesn't have the google cloud printing app or anything else printing related in it. Cloud print is preinstalled and currently on version 1.17b. I didn't kill it's process with some form of energy saving app. The device is not routed. What am i missing?
I also tried entering "text/html" by hand as the mime type, because that was the solution to another stackoverflow thread - but it doesn't solve mine.
Setting the mimetype to */* also doesn't make the actionchooser offer me the printer
After a lot of googling and testing it is rather unclear to me, if printing via intent is still possible on android 5 with google cloud print. BUT what does work is to create a custom PrintDocumentAdapter, as described in this post: https://stackoverflow.com/a/20719729/1171328

Hide App icon from its package Name

I am new to android. I want to hide other app icons from their package names. I get apps package name using this code
final PackageManager pm = getPackageManager();
List<ApplicationInfo> PackList = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (int i = 0; i < PackList.size(); i++) {
ApplicationInfo PackInfo = PackList.get(i);
// if (((PackInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) !=
// true) {
appsList.add(new AppPojo(PackInfo
.loadLabel(getPackageManager()).toString(),
PackInfo.packageName.toString(), "0"));
// }
}
Give package name of a particular app, is it possible to hide its icon??
Give package name of a particular app, is it possible to hide its icon?
No. You are welcome to write your own home screen which filters out apps, but you cannot force other home screens, or anything else, from showing whatever they want.

Set Bluetooth device name in Android Source Code?

Android device name == "BlueZ"?
My question is very similar to this one, I need to know how to change BlueZ to display the actual device name, i.e. reading it from the build.prop, as opposed to displaying "BlueZ"
I found the main.conf in external/bluetooth/bluez/src/main.conf (Might be slightly off) and it contains a line regarding the device name, with the variable set to "BlueZ". I tried changing it to both %d and %h, neither of which made any change. I'm going to try setting it to the device name manually, but I'd prefer that this fix be usable across several devices.
Any ideas?
# Default adaper name
# %h - substituted for hostname
# %d - substituted for adapter id
Name = "Bluez"
I've tried substituting the above two variables, but neither seem to have any effect.
What about from an outside app?
You could just make an Android build and, at the last state, run an app to change the Android device name?
You can use IBluetooth.aidl -> setName to change the Bluetooth name.
Tutorials can be found here, which further references this.
In short, in src you make a package android.bluetooth, Inside it you copy paste IBluetooth.aidl and IBluetoothCallback.aidl (you can find them in the previous link).
In your code, import the package:
import android.bluetooth.IBluetooth;
Then implement this method to get the Bluetooth object:
#SuppressWarnings("rawtypes")
private IBluetooth getIBluetooth() {
IBluetooth ibt = null;
try {
Class c2 = Class.forName("android.os.ServiceManager");
Method m2 = c2.getDeclaredMethod("getService", String.class);
IBinder b = (IBinder) m2.invoke(null, "bluetooth");
Class c3 = Class.forName("android.bluetooth.IBluetooth");
Class[] s2 = c3.getDeclaredClasses();
Class c = s2[0];
Method m = c.getDeclaredMethod("asInterface", IBinder.class);
m.setAccessible(true);
ibt = (IBluetooth) m.invoke(null, b);
} catch (Exception e) {
Log.e("flowlab", "Erroraco!!! " + e.getMessage());
}
return ibt;
}
Then instance this object:
IBluetooth ib =getIBluetooth();
and probably use
ib.setName("something");

Android get install location with packagename

Hi i used the following code from this tutorial to list all of the installed applications in an app i'm working on.
http://impressive-artworx.de/2011/list-all-installed-apps-in-style/
I changed the onClick to my own dialog and what i now need to do is be able to get the location of the app. That is if it's in /system/app or /data/app i'd like to be able to toast the entire path to the pressed app but can't figure out how to do this. I can get the packagename by doing app.getPackageName() in the onClick but how can i get the apks path with this? Thank you for any suggestions or help it is much appreciated!
After a bit more googling i got what i was looking for
PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.sourceDir;
worked very well found it here
Get Application Directory
thanks for the help it helped with my googling as to what to look for
Take a look at this . In particular the snippet with publicSourceDir .
List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
// skip system apps if they shall not be included
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
continue;
}
App app = new App();
app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
app.setPackageName(p.packageName);
app.setVersionName(p.versionName);
app.setVersionCode(p.versionCode);
CharSequence description = p.applicationInfo.loadDescription(packageManager);
app.setDescription(description != null ? description.toString() : "");
apps.add(app);
}
u can use this code to get the information of installed Applications.

Categories

Resources