always start app from root activity - java

I have an activity for handling deeplink which is a browsable activity
suppose user clicks a link on another app and my browsable activity handles that intent
and start the app, then user minimise the app after use by pressing back button
if user reopen my app from running apps my browsable activity gets started instead of launcher activity
so my question is how can i start my app from launcher activity instead of browsable if user launches my app from running apps
Quora uses the same procedure, you can test by clicking a link of Quora on any other app
manifest of browsable activity
<activity android:name="com.example.android.deeplink"
>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:host="com.example"
android:scheme="test" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
class code for handling intent data
Uri link = getIntent().getData();

how can i start my app from launcher activity instead of browsable if user launches my app from running apps
There is more then one approach to achieve this goal,
I believe that the best and simplest way would be to add to your "browsable activity" an Activity flag:
android:excludeFromRecents="true"
settings this flag - will make sure that this activity will simply won't be shown in the recent tasks in the first place.
more info in the documentation - http://developer.android.com/guide/topics/manifest/activity-element.html#exclude

Related

The activity is not responding

I have been working on developing an application which needed login and signup screen. My register activity is not working properly.
The application is unable to take user from the start screen to the register activity, first the error arose of absence of intent filter then I included the intent filter in the manifest file but it seems like my app is ignoring the register activity.
I am attaching both manifest file and the activity code please have a look.
As images are suggesting there are two LAUNCHER Activities in your AndroidMenifest.xml file, so you will have to make one of them as DEFAULT category.
Put this line to your intent-filter of one Activity
<category android:name="android.intent.category.DEFAULT" />
instead of
<category android:name="android.intent.category.LAUNCHER" />
Simply define registeractivity like login activity , remove the intentfilter & it will work perfectly fine.

How to Hide/ Remove/ Avoid System App (non UI) getting listed/shown in Android app drawer?

I'm working on a system app which not contain any user interface(service only). I start my service on boot. And I'm killing the launcher activity immediately by calling the finish() method.
Also I'm using the following code to remove the icon from launcher/app drawer.
PackageManager packageManager = getPackageManager();
ComponentName componentName = new ComponentName(this.getApplicationContext(), MainActivity.class);
packageManager.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
No issue with the implementation all work fine. But I couldn't reinstall apk on the device which already have this app installed unless uninstall the app and install it freshly.
My question is there are lot of apps in the Android devices which is not listed in the app drawer especially system apps & some downloaded apps too.(example few Keyboard apps downloaded from playstore).
I wonder is this only way to achieve this? Or is there are any other ways to declare the app as non UI app (to avoid getting listed/shown in app drawer) some where in AndroidMainfest?
Try this way. Completely remove this line. Because this is not the best idea to hide your app icon from the app drawer. It may cause some problems during the app updating process as you mentioned.
PackageManager packageManager = getPackageManager();
ComponentName componentName = new ComponentName(this.getApplicationContext(), MainActivity.class);
packageManager.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Also, remove the following "category.LAUNCHER" line from you main activity intent filter tag(on Mainifest.xml)
<category android:name="android.intent.category.LAUNCHER" />
Make sure you have ".action.MAIN" inside your main activity tag
For an example, you can simply replace this code with your current tag of your main activity. manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.INFO" /> <!-- optional-->
</intent-filter>
After this, your app won't be listed in the App drawer since your app doesn't contain launchable activity. In this way, you can also avoid reinstalling/updating issue that you have mentioned.
In the android manifest for the relevant activity remove the Launcher intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

How to open installed android application via browser in android?

I want to make my app to get opened when user enters particular url in the browser like chrome or internet.For this i have referred and googled about this topic what i noticed is similar and i have used in my manifest file but still doesnt work.
i have referred below links for my issue
Launching custom Android application from Android browser / Chrome
Launch custom android application from android browser
How to open android application when an URL is clicked in the browser
Intercepting links from the browser to open my Android app
All this have same answer but when i use this it has no effect,when i type url www.myurl.co.gdf or http://www.myurl.co.gdf it doesnt prompt the user it opens in browser itself instead of opening myapp or showing choose dialog box
the code i have used in manifest file is as follows
<application
android:icon="#drawable/logo"
android:label="#string/app" >
<activity
android:name="com.app.secondActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/service"
android:screenOrientation="portrait"
android:theme="#style/aa_theme" >
<intent-filter android:label="#string/app" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:host="www.myurl.co.gdf"
android:pathPrefix="/"
android:scheme="http" >
</data>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.VIEW" />
</intent-filter>
</activity>
<activity
android:name="com.app.firstActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/activity_title"
android:screenOrientation="portrait"
android:theme="#style/aa_theme" />
</application>
If this works fine for others why not for me?
Note:i have changed to above code only in manifest and i have not changed or added any thing extra in .java files or anyother files.
For this to work should i make any device setting changes or should i add Uri intentUri = getIntent().getData(); in .java file (should use then why?)or should i type differently in browser or have i used intentfilter in wrong activity or is there anything i am missing?
one more thing i am using some cordova plugins to this app, i dont think this has to do with opening an app.
I am very new to android please give me some ideas regarding this..
The issue isn't with your code- it is with your testing strategy.
Typing a URL in a browser does not typically start an Intent, and thus Android doesn't check to see if any other apps can handle the URL. When a user types a link into Chrome, for example, Chrome assumes that the user wants to continue using Chrome and will handle browsing to the URL itself.
Instead, you need to create an intent containing your URL to test if Android will handle deep links to your application correctly.
The easiest way to do so is via the following ADB command:
adb shell am start
-W -a android.intent.action.VIEW
-d http://www.myurl.co.gdf/

Launch browsable intent in correct app

my problem is the following:
My app has an activity that has this declared in the manifest:
<category android:name="android.intent.category.BROWSABLE" />
i am using this to launch my app when i click on a link received by sms. The problem is that the app starts running in the messages context and when i press the back button it launches the app in the default context.
What i want is, when i click the link, it opens the app in its own context.
How do I solve this?
Managed to get it working by using this on the manifest:
android:launchMode="singleTask"

Launch an app from a link issue in Android

Suppose I have an app with the following intent filter in an activity in the AndroidManifest.xml file:
<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:host="blabla.com"
android:pathPrefix="/element/"
android:scheme="http" />
</intent-filter>
Of course it will cause my app to be launched from the browser, for example. However, when the user clicks on the link, it is asked to select the application for opening that link. If he/she selects a browser instead of my app and, in addition, he/she checks the "don't ask me again" check box, my app will never be launched!
Is there any way to avoid that?
Is there another kind of URI I can use to uniquely open my app? I have been looking for answers in StackOverflow but I have not found any good example of a non browsable URI for launching my app from a link.
Thank you so much,
Use an with a element. For example, to handle all links to twitter.com, you'd put this inside your in your AndroidManifest.xml:
<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application.
Of course, if you want to provide tight integration between your website and your app, you can define your own scheme:
<intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, in your web app you can put links like:
<a href="my.special.scheme://other/parameters/here">
And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check.
Use a custom scheme instead of http. Maybe, x-myapp
<data
android:host="blabla.com"
android:pathPrefix="/element/"
android:scheme="x-myapp" />
Have your blabla.com web server respond to http links (http://blabla.com/element/foo) with a redirect to x-myapp://blabla.com/element/foo for mobile android devices.....or put a link on the page that will have the x-myapp:// link for the user to tap
Now since your app is the only one responding to x-myapp://blabla.com/element/ links, you have avoided step 1.

Categories