Read permission of installed Application in android phone? - java

I want to read permission of other applications installed in my android mobile using programming.
I think Android Cleaner read permission of other apps and display details like
I want get detail like this Image.
In this it's give details of Ad Network
How i get details like this app in my app?
If this app not Read Permission then How it's do it?

Well you can scrape the playstore app page for a given app and get the permissions it needs :)
Well that's just off the top of my head. On a serious note, you can do the following:
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List appsList = getPackageManager().queryIntentActivities(intent, 0);
for (Object app : appsList) {
ResolveInfo resolveInfo = (ResolveInfo) app;
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS);
} catch (NameNotFoundException ex) {
ex.printStackTrace();
}
String[] requestedPermissions = packageInfo.requestedPermissions;
}

Related

Some Android phones not opening “About device” page in Settings?

Some Android phones don't do anything when the the code below is ran. It's supposed to open the "About device" page in Settings.
For example, I know for a fact that it has no effect on the Huawei Y9 Prime 2019 running Android 10.
startActivity(new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS));
What's the best way to safeguard against this issue when it occurs? (In my app, I open this page to ask the user to perform a specific action there)
Use PackageManager.resolveActivity() to check whether such an Activity exists. If that returns null, there is no activity that matches the Intent and you have to guide your customers to the settings in another way:
Intent intent = new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, 0);
if (resolveInfo == null) {
// help customers by describing how to get to the device info settings
} else {
startActivity(intent);
}
If an activity is not found, the method startActivity will throw android.content.ActivityNotFoundException. You should catch this exception and notify the user:
try {
startActivity(new Intent(Settings.ACTION_DEVICE_INFO_SETTINGS));
} catch (ActivityNotFoundException e) {
// Notify the user, eg. using a popup so they can open settings manually
}

Application background service stopped when swiped up in China Phone

I have been searching for answers regarding this problem with China phone (Oppo, Huawei, XiaoMi, Vivo, etc.) when app is swiped up (close), the background services stopped running.
Most of the solutions were:
Include START_STICKY and use AlarmManager to start service.
Programmatically direct user to auto-start manager to enable app by user.
Manually exclude my app from power saving mode or include my app as protected apps.
My question is how does apps like Whatsapp still receives message or notification even swiped up?
Furthermore, the solutions mentioned in 1. and 2. doesn't work if phone restarts, but how Whatsapp still can receive messages?
I have tested Samsung devices, they have no problem running background services even though the app is swiped up.
Has anyone face the same problem with China phone?
try {
Intent intent = new Intent();
String manufacturer = android.os.Build.MANUFACTURER;
if ("xiaomi".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
} else if ("oppo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
} else if ("vivo".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
} else if ("oneplus".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListAct‌​ivity"));
} else if ("Letv".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
} else if ("Honor".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
}
else if ("huawei".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
}
else if ("asus".equalsIgnoreCase(manufacturer)) {
intent.setComponent(new ComponentName("com.asus.mobilemanager","com.asus.mobilemanager.autostart.AutoStartActivity"));
}
else {
Log.e("other phone ", "===>");
}
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0) {
startActivity(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
I am still looking for the answer. I have contacted Google support team and they replied as follow:
Upon discussion with our engineers, this is really the expected behavior. For the reason that they use a stock ROM that disables the re-starting of background services for most apps. Users should manually enable the auto-starting of background services as they are disabled by default. This can not be programmatically enabled for all devices. So you'll have to prompt your users to perform the steps manually. Please check out this guide to learn more about this workaround.

How to programmatically grant the "draw over other apps" permission in android?

How can I programmatically grant the permission in Settings -> Apps -> Draw over other apps in Android? I want to use system alert window but unable to in Android Marshmallow without forcing the user to go through the Settings app and grant the permission first.
You can check and ask for overlay permission to draw over other apps using this
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 0);
}
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 0);
}
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Here's the code for automatic granting the SYSTEM_ALERT_WINDOW permission to the package. To run this code, your Android application must be system (signed by platform keys).
This method is based on the following Android source code files: AppOpsManager.java and DrawOverlayDetails.java, see the method DrawOverlayDetails.setCanDrawOverlay(boolean newState).
#TargetApi(Build.VERSION_CODES.KITKAT)
public static void autoSetOverlayPermission(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
int uid = 0;
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
uid = applicationInfo.uid;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return;
}
AppOpsManager appOpsManager = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
final int OP_SYSTEM_ALERT_WINDOW = 24;
try {
Class clazz = AppOpsManager.class;
Method method = clazz.getDeclaredMethod("setMode", int.class, int.class, String.class, int.class);
method.invoke(appOpsManager, OP_SYSTEM_ALERT_WINDOW, uid, packageName, AppOpsManager.MODE_ALLOWED);
Log.d(Const.LOG_TAG, "Overlay permission granted to " + packageName);
} catch (Exception e) {
Log.e(Const.LOG_TAG, Log.getStackTraceString(e));
}
}
}
The code has been tested in Headwind MDM project, it successfully grants "Draw over other apps" permission without any user consent to the Headwind Remote application (disclaimer: I'm the project owner of Headwind MDM and Headwind Remote), when Headwind MDM application is signed by platform keys. The code has been tested on Android 10 (LineageOS 17).
Check this question and the answer:
SYSTEM_ALERT_WINDOW - How to get this permission automatically on Android 6.0 and targetSdkVersion 23
"Every app that requests the SYSTEM_ALERT_WINDOW permission and that is installed through the Play Store (version 6.0.5 or higher is required), will have granted the permission automatically."

Share image in Facebook programmatically from Android app via Intent

I have this code working well on Android 4.0.4.
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
java.io.File media = new java.io.File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI and the caption to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
share.putExtra(Intent.EXTRA_TEXT, caption);
// Broadcast the Intent.
mActivity.startActivity(Intent.createChooser(share, "Share to"));
But on Android 4.4.2 it crashes the Facebook app. Facebook app opens, the image is not shown and the FB app is dead.
In log dump I've noticed this message:
E/JHEAD ( 5850): can't open '/data/data/cz.volten.brili.android.free/files/product_preview_shared.jpg'
V/ContextImpl( 5850): ----- packageName = com.facebook.katana is NOT LOCKED -----
Could the reason be some security restrictions, e.g. The FB app does not have rights to access the image in the application folder even though it is invoked from an intent?
If so, what would be a proper location for an image shared between the apps?
Shall I use something like this: how to share image to facebook via intent
Could the reason be some security restrictions, e.g. The FB app does not have rights to access the image in the application folder even though it is invoked from an intent?
Correct. That image is on internal storage for your app, which is private to your app.
If so, what would be a proper location for an image shared between the apps?
You can stick with internal storage, though you will need to use a FileProvider, perhaps with my LegacyCompatCursorWrapper, to serve the file. This sample app demonstrates this, albeit with a PDF rather than an image.
Or, put the file on external storage.
Shall I use something like this: how to share image to facebook via intent
You could, though that would seem to be overkill, compared to using FileProvider.
This is what I usually use
private void initShareIntent(String type) {
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(type) ||
info.activityInfo.name.toLowerCase().contains(type)) {
share.putExtra(Intent.EXTRA_TEXT, "Elevator Express");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath))); // Optional, just if you wanna share an image.
share.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found) {
Toast.makeText(getApplicationContext(), "Facebook does not exist", Toast.LENGTH_SHORT).show();
return;
}
startActivity(Intent.createChooser(share, "Select"));
}
}
and call it like this :
iniShareIntent("face");
This code works for me.....here "updateImage" is my image location.
if (isFacebookExist()) {
if (hashClick.isChecked()) {
SharePhoto sharePhoto = new SharePhoto.Builder()
.setBitmap(updateImage)
.build();
if (ShareDialog.canShow(SharePhotoContent.class)) {
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(sharePhoto)
.setShareHashtag(new ShareHashtag.Builder()
.setHashtag("#HashTag")
.build())
.build();
shareDialog.show(content);
}
} else {
SharePhoto sharePhoto = new SharePhoto.Builder()
.setBitmap(updateImage)
.build();
if (ShareDialog.canShow(SharePhotoContent.class)) {
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(sharePhoto)
.build();
shareDialog.show(content);
}
}
} else {
showToast(" Facebook is not install.");
}
private boolean isFacebookExist() {
PackageManager pm = getPackageManager();
try {
PackageInfo info = pm.getPackageInfo("com.facebook.katana", PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return true;
}

Start Android Market from App

I'm developing a lite version for an app on the Android. How can I start an Intent to open the Android Market, preferably with the full version of my app displayed? This is difficult to test on an emulator (which is the closest thing to a device I have), as there seems to be no legal way of installing the Market on it.
That query above works, but when I tried it, it looked like it was bringing up search results based on the name.
If you use something like
intent.setData(Uri.parse("market://details?id=com.wolinlabs.SuperScorepad"));
instead, it will go right to the Android Market page for your app.
I think that's more what you wanted (?)
Found answer in the end:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=pname:MyApp"));
startActivity(intent);
No way of testing on emulator, though.
Hi I was trying the achieve the same but with one small difference
I DIDN'T WANT TO OPEN IT EMBEDDED ON MY APP
public void start(JSONArray args, CallbackContext callback) {
Intent launchIntent;
String packageName;
String activity;
String uri;
ComponentName comp;
try {
packageName = args.getString(0); //com.android.vending
activity = args.getString(1); //com.google.android.finsky.activities.LaunchUrlHandlerActivity
uri = args.getString(2); //'market://details?id=com.triplingo.enterprise'
launchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
comp = new ComponentName(packageName, activity);
launchIntent.setComponent(comp);
launchIntent.setData(Uri.parse(uri));
this.cordova.getActivity().startActivity(launchIntent);
callback.success();
} catch (Exception e) {
callback.error(e.toString());
}
}
THE BIG DIFFERENCE HERE IS THAT YOU START A NEW APP NOT JUST SHOW GOOGLE PLAY IN YOUR
APP
This code is part of a Cordova plugin but is pretty obvious what you need to do to use it natively.
THE IMPORTANT LINES
launchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
comp = new ComponentName(packageName, activity);
launchIntent.setComponent(comp);
launchIntent.setData(Uri.parse(uri));
Regards

Categories

Resources