0

[Android] [APP] How to Add 3D Touch to Android app [Guide][Java]

In this tutorial, we are going to learn how to add an app shortcut to the Android app( like iPhone’s 3d touch).
Into your app from scratch using the android studio.

Requirements
-working Brain
-android studio /eclipse
-basic knowledge of android programming(not Required :-p ) 

let’s get started 

Step -1 
Add this in androidmanifest.xml

PHP Code:
<meta-data
                android:name=”android.app.shortcuts”
                android:resource=”@xml/shortcuts” />  

After this 

PHP Code:
<intent-filter>
                <action android:name=”android.intent.action.MAIN” />

                <category android:name=”android.intent.category.LAUNCHER” />
            </intent-filter>  

It should look like this after adding the code

PHP Code:
<activity
            android:name=”.MainActivity”
            android:theme=”@style/AppTheme.NoActionBar”>
            <intent-filter>
                <action android:name=”android.intent.action.MAIN” />
                <category android:name=”android.intent.category.LAUNCHER” />
            </intent-filter>
            <meta-data
                android:name=”android.app.shortcuts”
                android:resource=”@xml/shortcuts” />
        </activity>  


Now Create New XML file inside res/xml/ (if there is no folder names XML then create one )
Name the file as shortcuts.xml
and paste this inside

PHP Code:
<?xml version=”1.0″ encoding=”utf-8″?><shortcuts xmlns:android=”http://schemas.android.com/apk/res/android”>
<shortcut
    android:shortcutId=”myshortcut”
    android:enabled=”true”
    android:icon=”@drawable/shortcut”
    android:shortcutShortLabel=”@string/my_shortcut”
    android:shortcutLongLabel=”@string/ my_shortcut “
    android:shortcutDisabledMessage=”@string/ my_shortcut _disabled”>
    <intent
        android:action=”android.intent.action.VIEW”
        android:targetPackage=”YourPackageName”    for example com.pankaj.rai
        android:targetClass=”YourActivityName”/>       for example com.pankaj.rai.mainactivity
    <categories android:name=”android.shortcut.conversation”/>
    </shortcut>
</shortcuts>

Add this value to res/value/strings.xml

PHP Code:
<string name=”my_shortcut”>Your shortcut name</string>
<string name=”my_shortcut_disabled”>shortcut is disabled</string>  

Add icon in res/drawable
Name it to shortcut
And it should look like this

PHP Code:
Shortcut.png  

There you go, guys, now you have 1 shortcuts in your app.

Result




Ps: 3D touch/app shortcut will only work in Android 7.X.X or above 
if you have any doubt about this tutorial please let me know

Leave a Reply

Your email address will not be published. Required fields are marked *