Call third party app Activity from own App
Asked Answered
P

1

0

I have successfully called third party apps from my app

Apps like: Google Drive and Google Photos

Code:

btnL1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
     openApp(KioskActivity.this, "com.google.android.apps.docs");
   }
});

btnL2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
     openApp(KioskActivity.this, "com.google.android.apps.photos");
    }
});


public static boolean openApp(Context context, String packageName) {
        PackageManager manager = context.getPackageManager();
        try {
            Intent i = manager.getLaunchIntentForPackage(packageName);
            if (i == null) {
                return false;
                //throw new PackageManager.NameNotFoundException();
            }
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            context.startActivity(i);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

UPDATE # 1 Here is the Code I have followed to call third party app Activity from own App

On button click calling Activity of third party app (Like: Last FM)

final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");                
intentDeviceTest.setComponent(new ComponentName("fm.last.android","fm.last.android.LastFm"));
startActivity(intentDeviceTest);

But always getting android.content.ActivityNotFoundException: Unable to find explicit activity class {fm.last.android/fm.last.android.LastFm}; have you declared this activity in your AndroidManifest.xml? And If I use try-catch blog or if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } to avoid ANF exception then its not showing exception, but still unable to call an activity

I already installed Last FM app on my device, so what could be the reason ?

UPDATE # 2 : I have created Hello World app and successfully called that one

Screenshots

Screenshot 1 (just enabled Kiosk Mode)

enter image description here

Screenshot 2 (just called Hello World app and pressed back to exit Hello World)

enter image description here

Question: Why it showing Navigation Bar and Bottom Bar (I mean Back, Home and Recents keys)

Here is my updated code:

  public class KioskActivity extends Activity {        

    final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().getDecorView().setSystemUiVisibility(flags);

        getActionBar().hide();

        setContentView(wenchao.kiosk.R.layout.activity_lock_activity);

        DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

        ComponentName mDPM = new ComponentName(this, MyAdmin.class);

        if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) {

            String[] packages = {this.getPackageName()};
            startLockTask();
        } else {
            Toast.makeText(getApplicationContext(),"Not owner", Toast.LENGTH_LONG).show();
        }

        setVolumMax();

        Button lock_btn = (Button)findViewById(wenchao.kiosk.R.id.lock_button);
        Button unlock_btn = (Button)findViewById(wenchao.kiosk.R.id.unlock_button);
        Button appButton = (Button) findViewById(R.id.appButton);

        lock_btn.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                startLockTask();
                return false;
            }
        });

        unlock_btn.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                stopLockTask();
                return false;
            }
        });

        appButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intentDeviceTest = new Intent("android.intent.action.MAIN");
                intentDeviceTest.setComponent(new ComponentName("com.example.hello1","com.example.hello1.MainActivity"));
                startActivity(intentDeviceTest);
            }
        });
    }
Pollywog answered 16/3, 2016 at 4:34 Comment(6)
Kiosk word itself describes that the device runs only single app. It prevents others and to uninstall itself..Sweep
@ShreeKrishna first of all nice name, secondly I have just installed that apk, but my device is not in kiosk mode, so how could I uninstall that apk...Pollywog
@Pollywog if not in kiosk mode then you can easily uninstall itMeimeibers
I have tried many times, but not able to uninstall that apk, always getting dialog in which showing cancel as enabled and ok as disabled @MeimeibersPollywog
Go to setting->app->kiosk app->force stopMeimeibers
@Meimeibers leave that, may I know why I am not able to call third party apps, when I am using app in Kiosk mode !Pollywog
E
0

Kiosk mode is officially called task locking. The name contains a clue. You can only launch third party activities if their launch mode allows them to be launched into the same task. If they don't, your options are:

  • disable task locking before launching the third-party activity
  • petition the maintainer of the third-party activity to change its launch mode
  • find an alternative third-party activity
Eno answered 16/3, 2016 at 6:38 Comment(2)
I got your point, I can call App activity to run that within my app, so I followed this : stackoverflow.com/a/3518476 SO Post to call third party app activity, but getting : android.content.ActivityNotFoundException: Unable to find explicit activity class {fm.last.android/fm.last.android.LastFm}; have you declared this activity in your AndroidManifest.xml?Pollywog
I was the original poster of the answer you linked to. Do you have LastFM installed? Maybe the package name of the app has changed? Did you check the manifest or the LastFm app version, to make sure you are calling the right activity? If it's still the app that they have on Github, it should still be valid though. github.com/lastfm/lastfm-android/blob/master/app/…Fouquet

© 2022 - 2024 — McMap. All rights reserved.