How to programmatically open another app in kiosk mode? - java

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

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
}

How can i check that app is installed with my link or not or cancelled?

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.

Android 4.4 set default sms application without user confirmation

Is it possible to change default sms application on Android 4.4 without user knowledge? I'm trying to do it on a ROOTED Galaxy S5 using reflection and invoking system methods, so here is what I done so far:
Created small app that implements all things needed for app to be a SMS manager (as per http://android-developers.blogspot.in/2013/10/getting-your-sms-apps-ready-for-kitkat.html) and I can make it default sms app but Android asks me to confirm that in dialog. Now I'm exploring android source code and I found something in this class:
https://github.com/android/platform_packages_apps_settings/blob/2abbacb7d46657e5863eb2ef0035521ffc41a0a8/src/com/android/settings/SmsDefaultDialog.java
So I'm trying to invoke internal method:
SmsApplication.setDefaultApplication(mNewSmsApplicationData.mPackageName, this);
via reflection and here is how I done it so far:
Class[] params = new Class[2];
params[0]=String.class;
params[1]=Context.class;
Class cls = null;
try {
cls = Class.forName("com.android.internal.telephony.SmsApplication");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Method method = null;
try {
method = cls.getDeclaredMethod("getSmsApplicationData", params);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
try {
Object[] params2 = new Object[2];
params2[0]=getPackageName();
params2[1]=getApplicationContext();
Log.d("Current package", getPackageName());
method.invoke(null, params2);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
And I made this app system app and put it into folder /system/priv-app, rebooted phone and started it successfully with adb, but when I click on the button that executes code above, nothing happens. No errors, no log output, but default app is still Messaging (com.android.mms).
Is there any way to do this?
This information contained in file /data/system/users/0/settings_secure.xml. For example, default application for SMS stored by key sms_default_application.
<setting id="85" name="sms_default_application" value="com.google.android.talk" package="com.android.settings" />
More info you can find in this class: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/provider/Settings.java#6067
Accordingly, if you have ROOT permissions, you can edit this file.

Launching an Android application from within app

To launch an Android application I use below code which works for fine for every application
installed on phone except for the "Phone" application itself. When I attempt to launch "Phone" the
app is not launced and no error message or displayed or exception thrown.
This is the code I'm using to launch the application :
launchApp(context, packageManager,
"com.android.phone");
/*
* Launch an application
*
* #param c Context of application
*
* #param pm the related package manager of the context
*
* #param pkgName Name of the package to run
*/
public static boolean launchApp(Context c, PackageManager pm, String pkgName) {
// query the intent for lauching
Intent intent = pm.getLaunchIntentForPackage(pkgName);
// if intent is available
if (intent != null) {
try {
// launch application
c.startActivity(intent);
// if succeed
return true;
// if fail
} catch (ActivityNotFoundException ex) {
// quick message notification
Toast toast = Toast.makeText(c, "Application Not Found",
Toast.LENGTH_LONG);
// display message
toast.show();
}
}
// by default, fail to launch
return false;
}
Is this the correct method to use for launching an Android application and/or is the "Phone"
app a special case which does not allow other applications to launch/use it ?
Try with this code:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);

Eclipse Android Runtime Errors

Currently working on a Android application for delivery drivers. Its been working fine for months but now it suddenly force quits when 'submit' button is pressed.
Whilst debugging its given me all sorts of run time errors relating to the android library.
When I go to the exact location each one says Source not found. Everything is there as it should be and I've reinstalled the SDK and been through every file location.
Please Help
Edit:
if(isOnline())
{
PODCache.clearedfordeliveryjobs.add(etDespatch.getText().toString());
new runner().execute(al_kvp);
}
PODCache is another class this is the bit the above is referring too.
public void onStart(Intent intent, int startid) {
// Run this
Toast.makeText(getApplicationContext(), "PODCache Started", 10).show();
RUNNING = true;
try {
clearedfordeliveryjobs = (ArrayList<String>) LocalPersistence
.readObjectFromFile(this, UNBLOCKEDLIST);
} catch (Exception e) {
clearedfordeliveryjobs = new ArrayList<String>();
}
What is keypod.keyfort.net.PickUpActivity? Have you tried finding that class? That does not look like a standard Android to me.

Categories

Resources