Looking for solution to integrate COSU mode in Android.I have already gone through below links,
https://developer.android.com/work/cosu.html
Has anyone implemented it successfully?
Take a look at this tutorial and that repository with example.
...
if (mDevicePolicyManager.isLockTaskPermitted(
getApplicationContext().getPackageName())) {
Intent lockIntent = new Intent(getApplicationContext(),
LockedActivity.class);
lockIntent.putExtra(EXTRA_FILEPATH, mCurrentPhotoPath);
startActivity(lockIntent);
finish();
} else {
Toast.makeText(getApplicationContext(),
R.string.not_lock_whitelisted,Toast.LENGTH_SHORT)
.show();
}
...
You might want to try Google's new Android Management API, it allows to manage COSU devices without having to build an on-device agent (a device policy controller).
I decided neither way was very good. I used device policy ownership to prevent installing any other apps, wrote a launcher app (so we were the homescreen), made it a system app and used the statusbar manager apis (which aren't well known) to remove the recents button and prevent the status bar from being opened so there was no way to launch any app but mine.
Related
I have a problem and a don't know how to solve it. I saw some tools for automation testing for android apps, like appium and others. They connect to the android device, emulator, from outside the device and open the application to be tested. I want to know how can i build a native android app that can to the same thing. Open another application and start executing different operations on the UI of that app. For a simple example, let's say i have a social app that i want to test. I want another that runs on the phone that opens my social app and starts running some operations like searching inside the app, clicking on different posts, liking post, s.o. Is there a way to do this? Are there any frameworks or methods for doing this?
Regards.
You have two kinds of automation frameworks for Android.
Instrumentation-based:
Robotium
Espresso
And black-box frameworks for functional testing:
Appium
Perfecto
ATMOSPHERE
The instrumentation frameworks work in the following way: As each android application runs in a sandbox and other applications can not change their behavior once they are installed, the instrumentation-based frameworks change the installation package of the application injecting hooks in the method definitions that allow them to interact with the application. This allows bypassing the sandbox in Android systems.
The other three all have UIAutomator Android service as basis for the interaction with the application. UIAutomator is part of hte Android SDK and allows emulation of real user interactions (e.g. click, scroll etc.), rahter than simulating them on lower, code level.
I believe that any of the five listed frameworks will allow you achieve what you want. I personally recommend black-box testing frameworks, as instrumentation can hide defects. My favorite framework is ATMOSPHERE - free to use, open sourced and although very recent a lot easier to use.
You would use an explicit intent to open a separate application.
public void openApplication(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i != null) {
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
} else {
Log.e(TAG, "Unable to start application");
return;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Package name not found");
return;
}
}
You would then call this method by providing the context and the package name of the application you want to open. For example, to open Instagram:
openApplication(this, "com.instagram.android");
My application performs data synchronization in background service which is critical task for application in order to work properly. now, application works fine & expected in some of devices having pure Android or near to pure Android ROM. e.g. Google Nexus, Android One & Motorola devices. but, some devices like Redmi having MIUI has inbuilt options for blocking application's background processes. which causes my application working not properly. So, I want to know "is there any way to find out my background processes are blocked? so that I can notify user to unblock it."
here's a somewhat related question
here's some screenshot related to this.
Any suggestions or help are welcome.
Thanks in advance
as i know, apps cannot get the info about whether or not in whitelist, but you can notify the user any more by :
Intent intent = new Intent(); intent.setAction("miui.intent.action.OP_AUTO_START"); intent.addCategory(Intent.CATEGORY_DEFAULT);
i want to know that is there any way i can prevent my android app from killing from task manager. Whether it's any third party app, clears from ram manager or user clicks force stop. i just don't want kill my app from background, It should be running.
How to disable the "Force Stop" button
Short answer: Use the Device Administration API.
How do I demonstrate that it works?
Yes, back to your job. Use the API link provided above and the Api Demos included in Google's sample collection to figure out how to integrate this into your app.
Build the demo and run it on your device.
Choose API Demos->App->Device Admin->General->Enable admin.
Choose Activate once the Device Administration API prompts you with its enabling screen.
Exit the app and attempt to manage the app via your device's settings menu (specifics for this step varies by device).
When viewing the Api Demo's "app info" screen, you should see both Force Stop and Uninstall are disabled.
How do I do this in my own app?
Review DeviceAdminSample.java in the Api Demos app for inspiration. You will need the following:
The following code is what brings up the activation screen:
// Launch the activity to have the user enable our admin.
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
mActivity.getString(R.string.add_admin_extra_app_text));
startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
However, there are a few other pieces you will need to get this to work:
A broadcast receiver that derives from DeviceAdminReceiver.
Entries in your manifest file that refer to the above broadcast receiver.
Permissions in your manifest for using the Device Administrator API.
An xml file stating what policies your app can access.
All of this can be found in the above links. Good luck with your client!
This might be a dirty way to do this. But it worked for me.
Just override onDestroy() method in service and start that service again.
#Override
public void onDestroy() {
Intent intent = new Intent(this,YourService.class);
startService(intent);
}
I am trying to open a different, already installed android application within another, on click of a button. The new application should be opened in a part of the screen within the calling application.
Currently, my code creates a new intent and runs the called application in that. the calling application disappears. Here's my code:
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.ritwik.camera");
startActivity(intent);
}
});
Ideally, it should open as a part of the same screen, without sidelining the parent(calling) application. How do I do that?
When you start an Intent to execute another application (i.e. because you are implementing a launcher or a main menu replacement) you are actually asking android to execute the application identified with a specific package (or the one satisfying some specific constraints, like the ability to handle images, videos, etc), without any clue or reference about the Activities it contains (nor the ability to get any...).
Therefore I don't think that what you are trying to achieve is possible with the current version of the OS (unless some vendor is providing extensions to do just that, see the comment by Pratik).
The new application should be opened in a part of the screen within the calling application.
This is not possible with conventional third-party application UIs.
AFAIK, the split-screen feature (Adaptive UI) is supported from Android 3.0 onwards.
That has nothing to do with embedding the UI of third-party apps into your own.
So I didn't get what you meant to say by "it's not possible with the current version of the OS"
It is not available on any stock version of Android released up through March 26, 2013 at 9:50am Eastern Time.
Certain device manufacturers, like Samsung, have extended Android with multi-window capabilities. However, the control over those windows lies with the user and the (modified) OS. Unless there is something in their S-Pen SDK for this, you have no way of starting another window.
Android also has RemoteViews, which is a means of passing a simplified UI between processes. Using this, it is possible for one app to embed RemoteViews published by another app. You see this with app widgets on the home screen, for example. However, both apps have to be written with this in mind, such as an app publishing an AppWidgetProvider to supply app widgets to home screens.
As far as I know, this is NOT possible. You can only launch the new activity, but you have no control of it.
EDIT: Some devices offer this possibility using Cornerstone or similar frameworks, but I haven't seen an option for developers to use this for their own apps.
As part of the free SmartWatch promotion I got a watch from Sony and have published an app for it. It is called SoundCheck and is found through the LiveWare Manager on the Google Play Market. A customer recently sent email for support. They installed Sound Check but did not see it on the watch since widgets are not enabled by default when they are installed. Is there any way to programmatically enable a widget when an app is installed? It might be nice for users if the widget was enabled by default rather than force them to navigate through the LiveWare manager to find the setting. This would be quite helpful for "widget-only" apps like Sound Check that do not have a control extension.
This week I created a pro version of my SmartWatch app to actually change the values displayed by the widget. Is it possible to open a control extension from a widget extension? Here is the use case. Short taps navigate through different screens of the widget. I want to use the long tap event type on the widget to open the 'editing' function in the control extension. Is this possible?
Thanks in advance for your help with these questions.
The question of how to enable a widget programmatically is still open. Here is code to open the control from a widget. This answer helped:
How should I do to start SmartWatch Extension from the program code?
if (type == Widget.Intents.EVENT_TYPE_SHORT_TAP) {
updateWidget();
} else {
//this code will launch the control and allow the user to change volume settings?
Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.mezcode.soundcheckpro");
intent.setPackage(mHostAppPackageName);
mContext.sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);
}