asma
asma

Reputation: 71

how to call one application from another in android

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

Answers (8)

Lalit Poptani
Lalit Poptani

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

Houcine
Houcine

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

jtt
jtt

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

Squonk
Squonk

Reputation: 48871

Try...

Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
startActivity(intent);

From the docs...

DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN

Upvotes: 1

Pradeep Sharma
Pradeep Sharma

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

jeet
jeet

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

Caner
Caner

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

Lucifer
Lucifer

Reputation: 29670

Please try this,

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity( LaunchIntent );

Upvotes: 0

Related Questions