Reputation: 71
I am doing one application for that I need to call " com.android.settings.DeviceAdminAdd" from my application. how to call this class in my app. My code is like this but it is not working
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings.DeviceAdminAdd");
startActivity(intent);
thx in advance
Upvotes: 1
Views: 2059
Reputation: 67296
Instead of using setClassName
use setComponent
, as below
Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
intentDeviceTest.setComponent(new ComponentName("com.intent.service",
"com.intent.service.InentServiceDemoActivity"));
startActivity(intentDeviceTest);
Upvotes: 1
Reputation: 24181
i've tried this code now and it works , it opens the AddAccount Activity
:
Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
startActivity(intent);
Regards , Houcine
Upvotes: 1
Reputation: 13541
All the answer are correct. You should however NEVER target an application by package name UNLESS it is your application. This will cause problems with future releases if you follow this pattern.
Upvotes: 0
Reputation: 48871
Try...
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
startActivity(intent);
From the docs...
DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN
Upvotes: 1
Reputation: 35
you can read this code
public class CurrentActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent=new Intent(this,TargetActivityName.class);
this.startActivity(intent);
}
}
Upvotes: 0
Reputation: 29199
Set DeviceAdminAdd activity property exported=true in manifest file. and call as follows:
Intent intent = new Intent(com.android.settings.this, com.android.settings.DeviceAdminAdd.class);
startActivity(intent);
Upvotes: 1
Reputation: 59338
Try this instead(note the 1st line is different):
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.DeviceAdminAdd");
startActivity(intent);
If it doesn't work for some reason another (better) option is to use the PackageManager to get an Intent for the package:
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.android.settings");
startActivity(intent);
Upvotes: 0
Reputation: 29670
Please try this,
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity( LaunchIntent );
Upvotes: 0