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
}
Related
I want to to list some play store app links in my app. and i want that user click on the link and go to the play store and download the app. Now i want to track that if user clicked on the link and has he downloaded or not the app or not cancelled the download. so how can i implement this kind if feature in android studio.
using package manager you can check whether app installed or not
if(appInstalledOrNot(com.demo.package)){
Toast.makeText(this,"App Installed",Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this,"App NOt Installed",Toast.LENGTH_LONG).show();
}
private boolean appInstalledOrNot(String packageName) {
PackageManager pm = this.getPackageManager();
try {
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
} catch (Exception e) {
Log.e("::MG::",""+e);
return false;
}
}
you can call this function onResume so when user come back to application from play-store you check application status is installed or not.
I want to create an app,that's use to only allow access specific apps in a device.So I tried to pinned the device.Now I want to open another application that is in my specific apps list.
I can't open another app while pinned.
This is the code I used to pinned
startLockTask();
and this is the code to I tried to open another appilication in kiosk mode
ComponentName deviceAdmin = new ComponentName(KioskActivity.this, MyAdmin.class);
if (myDevicePolicyManager.isDeviceOwnerApp(getPackageName()))
{
myDevicePolicyManager.setLockTaskPackages(deviceAdmin, new String[]{getPackageName(), "com.example.pan.pocmdmhelper"});
try
{
PackageManager pm = KioskActivity.this.getPackageManager();
Intent it = pm.getLaunchIntentForPackage("com.example.pan.pocmdmhelper");
it.addCategory(Intent.CATEGORY_LAUNCHER);
if (null != it) {
KioskActivity.this.startActivity(it);
Toast.makeText(KioskActivity.this, "Started activity for this package", Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
Toast.makeText(KioskActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
finish();
}
}
At the moment I tried to open single app by using it's package name.It's open if I unpinned only
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.ChainLaunchAppListActivity"));
} 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.
i try to show user location in my android app , but it dosnt work! package manager is always null.
private void openPrefredLocationInMap (){
String location =
PreferenceManager.getDefaultSharedPreferences(this)
.getString(getString(R.string.pref_location_key)
, getString(R.string.pref_defult));
Uri geoLocation = Uri.parse("geo:0,0?").buildUpon()
.appendQueryParameter("q", location).build();
Intent intent= new Intent(Intent.ACTION_VIEW,geoLocation);
if (intent.resolveActivity(getPackageManager()) != null)
startActivity(intent);
else
Log.d("package","couldnt call"+location);
}
Your device does not have an application that could handle such intent. Install an application that can handle that intent or make one yourself. To be more specific, you might not have a map application that would be able to display geoLocation intent.
Try installing Google Maps for example.
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;
}