How can I place app icon on launcher home screen?

前端 未结 6 1498
迷失自我
迷失自我 2020-12-02 17:47

As you know, when app is nomally installed, icon is created at launcher menu screen. What I want to do is create icon at user home screen during installation. (without press

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 18:17

    I had trouble with the above answers and that's because API 22 and maybe other APIs returns on getApplicationInfo().className in debug/emulation mode:
    "com.android.tools.fd.runtime.BootstrapApplication"

    Most important thing is that I needed to set the entire path to the class for the class name. (see the changes)

    For example, I had the following:
    packageName=com.example.user.myapp
    className=MainActivity

    In Kailash answer I needed to change this line:

    shortcutIntent.setClassName("packageName", "className");
    

    to

    shortcutIntent.setClassName("com.example.user.myapp", "com.example.user.myapp.MainActivity");
    



    In ChristopheCVBs answer I needed to change this line:

    ComponentName comp = new ComponentName(appInfo.packageName, appInfo.className);
    

    to

    ComponentName comp = new ComponentName(appInfo.packageName, appInfo.packageName+".MainActivity");
    

提交回复
热议问题