I have some strange problem. When I try to launch DevicePolicyManager activity from my main activity, it loads properly. However, when I make a notification, call QuestionActivity (if user clicks the notification), and then try to call DevicePolicyManager activity from QuestionActivity, I get (logcat):
INFO/ActivityManager(104): Starting activity: Intent {
act=android.app.action.ADD_DEVICE_ADMIN
cmp=com.android.settings/.DeviceAdminAdd
(has extras) }
WARN/InputManagerService(104): Window already focused, ignoring focus
gain of:
com.android.internal.view.IInputMethodClient$Stub$Proxy#4514a2d0
And nothing appears. This is strange for me, cause I'm able to launch different Android OS activity from QuestionActivity:
//This works
Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
startActivity(intent);
But I cannot launch the DevicePolicyManager with:
//This works from main activity, but not from QuestionActivity
MyDeviceAdmin admin = new MyDeviceAdmin(this);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
admin.getDeviceAdminComponent());
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
"Additional text explaining why this needs to be added.");
startActivityForResult(intent, 234234234);
I would be very grateful for any help, cause I'm completely stuck.
Related
Okay, I think I'm missing something here but can't seem to find a way around it :\
So this is my scenario, I have two apps, A and B. A Opens a B with the following intent:
PackageManager pm = getPackageManager();
Intent n = pm.getLaunchIntentForPackage(currAppInfo.getName());
n.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(n);
(currAppInfo is a custom object and getName returns the package name.)
Anyway, B is installing APKs. A receives the package installed broadcast and should be now moved back to front, how ever if I'm starting app A with an intent
Intent serviceIntent = new Intent();
serviceIntent.setClass(context, MainActivity.class);
serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceIntent);
Instead of seeing A's mainActivity screen all I see is B's main activity screen.
Why is that? Is it the way I open the apps with the intents or am I missing something more basic here?
This is how my app opens a page in default browser
Intent i = Intent.parseUri("http://www.google.com", Intent.URI_INTENT_SCHEME);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Once the browser activity is active, I can't navigate back to my app using back button. It goes the activity before my app. My app/activity is not destroyed though as I can still resume it from the app list. I suspect my activity is 'removed' from the back stack somehow. Please help me debug/fix this. Thanks.
try to use Intent.ACTION_VIEW
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(myUrl));
startActivity(intent);
I have an activity called FooActivity. It can be opened two ways. 1 - by MainActivity and 2 - by going to my app's URL
In the doInBackground(..) of AsyncTask in FooActivity I have the following code to finish this activity.
Intent returnIntent = new Intent(FooActivity.this.getApplicationContext(), MainActivity.class);
returnIntent.putExtra("result", "one");
AcceptActivity.this.setResult(FooActivity.this.RESULT_OK, returnIntent);
AcceptActivity.this.finish();
This works fine when my app had already been opened. Because when I finish FooActivity I would see MainActivity.
However, if my app was not already opened and the first time it opened was through a URL, then FooActivity just finishes and I see the phone's desktop.
Question
Is there a way to detect whether MainActivity has been opened already or not? If it is not opened then I'd change above code to open the MainActivity.
Just do that in your onPostExecute() of your FooActivity
launch home screen using startActivity(Intent) with an intent that has flag FLAG_ACTIVITY_CLEAR_TOP, and pass the result manually through the intent
I need to enable a device-admin for my app, it's working like this called from Activity A:
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdminComponentName);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Your boss told you to do this");
startActivityForResult(intent,1);
but i want that after my activity A calls the device-admin-activation prompt and the user says activate, immediately return to the caller-activation. Is there a way to do this?
Just try if it works..
In your DeviceAdminReceiver's onEnabled() method start the activity that you want to show after device admin activates.
my Main launcher activity (the one that has android.intent.action.MAIN as its action) is Login page.
After successful login I started HOME activity and finish() the LOGIN one to prevent users returning to that page by pressing BACK button.
When I press SIGN OUT button, I want the app to return to Login page. But I can't find a way to do it. Here's the sign out code:
//This method is in HOME activity
private void signOut(){
Intent i = new Intent("android.intent.action.MAIN");
startActivity(i);
finish();
}
That code will open dialog box listing all applications in my phone for me to choose. I tried putting the package name + class name (com.example.test.Login) as the Intent but keep getting this error:
android.content.ActivityNotFoundException: No Activity found to handle Intent
I know I can trick this problem by using Splash screen as Main activity. But If there is another better solution, I want to know it.
Thanks
Use
Intent i = new Intent(this, LoginPage.class);
startActivity (i);
finish();