0

I called my custom app from browser by "customapp://myactivity"

It works good, but when I launch my app. It works like two different app.

I think the browser launched just "myactivity" instead of "customapp".

I think if I start "customapp" on "myactivity", then I can do what I want, but I think it is ridiculous.

Is there a cool way to solve this problem?

  • More explaination is on below

ex) If I launch "customapp" and start "myactivity" and call my custom app from web browser by "customapp://myactivity" and press home button long, there is "customapp" in applications eventhough I'm in "myactivity". If I launch other application and press home button long, there are two "myactivity". One from "customapp" and one from web browser.

The applicaion icon and name is webbrowser, but there is "myactivity".

Sorry for poor english.

Mid
  • 1
  • 1
  • 3

2 Answers2

0

I just solved my problem.

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

    if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
        Intent intent = getPackageManager().getLaunchIntentForPackage("com.company.app");
        intent.setData(getIntent().getData());
        intent.putExtras(getIntent().getExtras());
        startActivity(intent);
        finish();
        return;
    }

    // do something
}
Mid
  • 1
  • 1
  • 3
-1

Please DO NOT use your own custom scheme like that!!! URI schemes are a network global namespace. Do you own the "anton:" scheme world-wide? No? Then DON'T use it.

One option is to have a web site, and have an intent-filter for a particular URI on that web site. For example, this is what Market does to intercept URIs on its web site:

<intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="http" android:host="market.android.com"
                android:path="/search" />
        </intent-filter>

Alternatively, there is the "intent:" scheme. This allows you to describe nearly any Intent as a URI, which the browser will try to launch when clicked. To build such a scheme, the best way is to just write the code to construct the Intent you want launched, and then print the result of intent.toUri(Intent.URI_INTENT_SCHEME).

You can use an action with this intent for to find any activity supporting that action. The browser will automatically add the BROWSABLE category to the intent before launching it, for security reasons; it also will strip any explicit component you have supplied for the same reason.

The best way to use this, if you want to ensure it launches only your app, is with your own scoped action and using Intent.setPackage() to say the Intent will only match your app package.

Trade-offs between the two:

  • http URIs require you have a domain you own. The user will always get the option to show the URI in the browser. It has very nice fall-back properties where if your app is not installed, they will simply land on your web site.

  • intent URIs require that your app already be installed and only on Android phones. The allow nearly any intent (but always have the BROWSABLE category included and not supporting explicit components). They allow you to direct the launch to only your app without the user having the option of instead going to the browser or any other app.

Ravi_Parmar
  • 12,319
  • 3
  • 25
  • 36
  • Thank you. So, you are saying start activity with Intent.setPackage() in myActivity? The flow will be Web browser -> myActivity in Web browser -> myActivity in customApp. is it correct?? – Mid Oct 11 '13 at 05:55
  • Is it ok to use package name for scheme? like com.company.packagename://myActivity. I have company.com domain. – Mid Oct 11 '13 at 06:25
  • minus one for copying the answer from @hackbod (http://stackoverflow.com/a/3472228/472262) and not even adjusting the 'Do you own the "anton:" scheme world-wide' to the question – Makibo Oct 16 '13 at 04:14