Android app icon shorcut not launching activity - android

I'm trying to implement app icon shortcut on Android. I followed the documentation but I'm having problem launching the app from the shortcut. Every time I click the app icon shortcut, nothing happens.
Here's the code on my AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.package.myapp">
<application
android:name=".MyApp"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar"
android:usesCleartextTraffic="${usesCleartextTraffic}"
tools:ignore="ExportedService,GoogleAppIndexingWarning,UnusedAttribute">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
</activity>
...
</application>
</manifest>
Here's the shortcuts.xml file:
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedAttribute">
<shortcut
android:enabled="true"
android:icon="#drawable/ic_send"
android:shortcutId="send_funds"
android:shortcutLongLabel="#string/LBL_SEND_FUNDS"
android:shortcutShortLabel="#string/BTN_SEND">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.package.myapp.MainActivity"
android:targetPackage="com.package.myapp" />
</shortcut>
</shortcuts>

So the issue was on the buildType. When running on buildTypes other than the release build, I'm having the issue because the package name is different from what was indicated on the android:targetPackage of shortcut's intent. So what I did was, I created multiple shortcuts.xml with different targetPackage in the respective build folder:
app/src/debug/res/xml/shortcuts.xml
app/src/dev/res/xml/shortcuts.xml
app/src/staging/res/xml/shortcuts.xml
And set the android:targetPackage respectively:
android:targetPackage="com.package.myapp.debug"
android:targetPackage="com.package.myapp.dev"
android:targetPackage="com.package.myapp.staging"
Thanks to this SO question which is almost similar to my issue. And to Rakesh's answer.

Related

Application's name disappear Android

I made an Android application, but when I look at it in my device, the appName just disappeared whereas I added it in the manifest and strings.xml. My application is the one at the bottom left
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.package.package"
android:versionCode="3"
android:versionName="2">
<application
android:allowBackup="true"
android:icon="#drawable/countdown_icono"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
// Activities
</application>
strings.xml
<resources>
<string name="app_name">I can\'t wait!</string>
</resources>
If someone could helps :)
SOLUTION :
<activity
android:name=".MainActivity"
android:label="APP NAME" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You probably need to add
android:label="#string/app_name"
inside your Activity tag in the AndroidManifest.xml.
<activity android:name=".theJavaClassActivity"
android:label="yourString">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Android Launcher shows the title of the activity that has the Intent-filter of android.intent.action.MAIN. In this way it is able to show more than one activity icons and titles if your application requires so.

I want to launch my app from google now....can anyone help me with the code

I have been trying to launch the main activity of my app by voice searching it using google now...Can anyone help me with the code
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="My Voice Activated App" >
</searchable>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.authorwjf.myvoiceactivatedapp" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.authorwjf.myvoiceactivatedapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="#xml/searchable"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I wrote this code to search my app using command -"Okay Google..... Open My Voice Activated App" but this is not working
Say your app name stored in #string/app_name . Your app will reflect in search result (phone)

Two manifest tags get created when I add an activity

With everything checked, when I create a new activity two manifest tags are created automatically and it shows an error. Should I uncheck something when creating a new activity before clicking finish in the preview section? My manifest code is below:
<<<<<<< Original
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iamtheonewhoknocks.toolkit"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.iamtheonewhoknocks.toolkit.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.iamtheonewhoknocks.toolkit.FlashlightActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_flashlight"
android:parentActivityName="com.iamtheonewhoknocks.toolkit.MainActivity"
android:theme="#style/FullscreenTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.iamtheonewhoknocks.toolkit.MainActivity" />
</activity>
</application>
</manifest>
=======
<manifest xmlns:android="http://schemas.android.com/apk/res/android" >
<application>
<activity android:name=".FlashlightActivity"
android:label="#string/title_activity_flashlight"
>
</activity>
</application>
</manifest>
>>>>>>> Added
Those <<<<<<< Original and other tags were created automatically. Why is it doing this?
<intent-filter>
<action android:name="android.intent.FlashLight." />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
I don't know what IDE you are using ~ I am going to assume the Eclipse IDE Android bundle. When you create a new activity in the android manifest you need an intent filter within the activity xml files. So when you call a new activity in the src java files. You should have something like the code above in yours, but the 'FlashLight' at the end of android:name can be anything you want as long as you remember it and it makes sense. This is what seems to be missing from your code.
A quick work around would be to delete everything but:
<activity
android:name="com.iamtheonewhoknocks.toolkit.FlashlightActivity"
android:label="#string/title_activity_flashlight"
</activity>
and then add in that snippet of code at the top.
<activity
android:name="com.iamtheonewhoknocks.toolkit.FlashlightActivity"
android:label="#string/title_activity_flashlight"
<intent-filter>
<action android:name="android.intent.FlashLight." />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Hope this helps

Test project icon not visible in android

I am unit testing an android applications using Robitium. When I install the test project in to android emulator, I can't find the icon of the test project, but I can run it.
The manifest file of the test project is like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smartek.screens.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.smartek.screens" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
What should I do to make the test project icon visible?
The test project will not contain the launcher entry in manifest file, so you cannot see the icon on launcher.
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
We can do this and its same as the normal android application .
Add the following lines to the android manifest file
<activity android:name=".Testing class name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

INSTALL_FAILED_ALREADY_EXISTS with two different package names

I have two manifests that I swap round when building different releases of my app. The manifests have different package names yet I can only build one on the device at a time. I really need both to be built. The project has no src files and uses an activity from a library.
Manifest one:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.pkgone" android:versionCode="01" android:versionName="0.1">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name="com.test.Splashscreen" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Manifest Two:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.pkgtwo" android:versionCode="01" android:versionName="0.1">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<activity android:label="#string/app_name" android:name="com.test.Splashscreen" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I've sorted it out! The issue was that the R.java file in the gen folder wasn't being cleaned so I just ran
ant clean
before
ant release
and it works great! Thanks to #enrmarc and #Roman Nurik for their help :)
I solved it. I had the same problem.
You need to change the "applicationId" in your build.gradle(Module:app) file
be aware that there will be two build.gradle files. Open the one with (Module:app)
then clean your project.

Categories

Resources