I am programming a tiny app which opens the camera as it is opened via assist-request.
In the onCreate method, it simply opens the camera via intent.
But if the app is opened "the regular way" I'd like to display a little instruction instead of the camera.
Is there an easy solution for checking if the app was started by an assist-request?
extract from my Manifest:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
If you want to determine which sort of Intent was used to start MainActivity, use getIntent().getAction() and compare it to the possible values (e.g., Intent.ACTION_MAIN).
Related
<activity
android:name=".activitys.SplashScreen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
When app is sterted, trying to share the text and app is launching but if open pervious app by android navigation button i see 2 my app exemplars. How to check if app is launched and reopen not open second at one time
Simple answer: you need to add
android:launchMode="singleInstance"
within your activity bracket (below android:name=".activitys.SplashScreen", for example)
Better answer: Go through this article to understand the different types of launch modes: https://medium.com/#iammert/android-launchmode-visualized-8843fc833dbe
Best answer: Read through the doc on tasks: https://developer.android.com/guide/components/activities/tasks-and-back-stack
I have an html page with two links as follow:
Test 1
Test 2
I open it with android Internet app. In my "Hello word" manifest application i declare:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="testapp">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myApp" />
</intent-filter>
</activity>
I can open my application with both links.The first time i click on both links my app starts and passes through onCreate (my app was not in background before click). The second time (app now is in recent tasks), the first link clicked before in chronologically order pass through onResume only but the second pass on onCreate. This will be the behaviour if i try open links n times until i kill application from recent. Any ideas?Thanks!
An Android activity, by default can be instantiated multiple times. You should use android:launchMode="singleTask" to override this behavior. There are some other flags that might interest you if you - here is the link to documentation.
I have a main-activity which shows some data in a list and a nfc-asynctask which reads some data from a card. I want to achieve the following behavior:
If the app is closed and a card is put near the mobile phone, the main-activity and simultaneously the nfc-asynctask should be started. The results of the asynctask should be presented in a dialog.
If the app is opened and a card is put near, the nfc-asynctask should be restarted and only a dialog with the results should be opened.
My current approach always starts the main-activity. This means that sometimes, there are multiple instances of my main-activity and when the user hits the back-button, instead of switching to the home-menu, another activity instance is put on.
Manifest
<activity
...
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="#xml/filter_nfc"/>
</activity>
Have a look at Android's foreground dispatch facility. If you register your app for foreground dispatch, your activity receives an onNewIntent() event instead of getting started a second time.
Also, I suggest putting the TECH_DISCOVERED intent in a separate intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/filter_nfc" />
in my first activity I have two intent filters.
The first one is for regular access from the launcher. The second one is used when a user tries to unzip a file.
android:name=".MyApplication">
<activity
android:name=".SplashActivity"
android:label="#string/app_name"
android:icon="#drawable/ico"
android:theme="#style/Theme.Sherlock.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.ALTERNATIVE"/>
<data android:mimeType="application/zip"/>
</intent-filter>
</activity>
The problem is that in the launcher I get two icons instead of one .
How can I get only one icon and mantain the ability to run the activity with the second intent filter. I have tried removing (or changing to a different category)
<category android:name="android.intent.category.ALTERNATIVE"/>
Thanks
EDIT:
The problems seems somehow related with Android Studio (v 0.1.6 and 0.1.7) as
with Eclipse only one icon shows up.
in my app, there is two activity and i want to make activity1 to the starting activity after installation.
But now the RUN button (is showed right after packgae installing) is disabled.
below is the manifest file. thanks.
<activity ...1>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity ...2>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</activity>
android) can i set a default activity that runs right after installing
No activity "runs right after installing". The user has to launch it from the launcher.
below is the manifest file
No, it is not. That is not even valid XML.
Also, note that your third <intent-filter> is invalid. Not only are you missing any category (you need at least DEFAULT for activities), but ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED are not activity actions.
I am going to take a guess that you really mean to ask: "I have two activities, both described as ACTION_MAIN/CATEGORY_LAUNCHER, and now the Run button does not work -- what can I do?" The answer would be "either remove the ACTION_MAIN/CATEGORY_LAUNCHER <intent-filter> from one of them, or mark one of the two as disabled (android:enabled="false") and enable it later on using PackageManager."
I think the problem is the second:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You shouldn't have 2 activities flagged as the MAIN and LAUNCHER activity.
Try removing it within activity2.
Check out: http://developer.android.com/reference/android/content/Intent.html the intentfilter s are discussed.