主屏幕应用程序快捷方式不工作android。应用程序未安装 [英] home screen app shortcut is not working android. app isn't installed

查看:112
本文介绍了主屏幕应用程序快捷方式不工作android。应用程序未安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主屏幕上创建了应用程序快捷方式。但它不起作用。它始终

显示未安装Toast应用程序

。我尝试过两种不同的代码但结果总是一样的。



这是第一个代码



  private   void  addShortcut(){
// 在主屏幕上添加快捷方式
Intent shortcutIntent = new Intent(getApplicationContext(),MainActivity。 class );
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, AppName);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(
getApplicationContext(),R.drawable.ic_launcher));
addIntent.setAction( com.android.launcher.action.INSTALL_SHORTCUT);
getApplicationContext()。sendBroadcast(addIntent);
}





第二个代码



  public   static   void  addShortcut (上下文上下文)
{
Intent shortcut = new Intent( com.android.launcher.action.INSTALL_SHORTCUT);

ApplicationInfo appInfo = context.getApplicationInfo();

// 快捷方式名称
shortcut.putExtra(意图。 EXTRA_SHORTCUT_NAME, appInfo.name);
shortcut.putExtra( duplicate,false); // 只需创建一次

// 安装活动应该是快捷方式对象
ComponentName component = new ComponentName (appInfo.packageName, MainActivity.class);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(component));

// 设置快捷方式图标
ShortcutIconResource iconResource = Intent。 ShortcutIconResource.fromContext(context,appInfo.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);

context.sendBroadcast(快捷方式);
}





记录猫和清单:



< pre lang =java> 02 - 03 22 36 58 625 :E / memtrack( 1697 ):无法' t load memtrack module(没有这样的文件或目录)
02-03 22:36:58.625:E / android.os.Debug(1697):无法加载memtrack模块:-2
02-03 22 :37:02.515:E / memtrack(1708):无法
t加载memtrack模块(没有这样的文件或目录)
02 - < span class =code-digit> 03 22 37 02 515 :E / android.os.Debug( 1708 ):无法加载memtrack模块: - 2
02 - 03 < span class =code-digit> 22 : 37 03 255 :E / InputDispatcher( 388 ):channel ' b500ff48 com.example.test_shortcut / com.example.test_shortcut.MainActivity(server)'〜频道无法恢复,将被丢弃!
02 - 03 22 37 13 805 :E / WindowManager( 388 ):启动窗口AppWindowToken {b5537500 token = Token {b50334a8 ActivityRecord {b502b0e0 u0 com.example.test_shortcut / .MainActivity t7}}}超时



<?xml version = 1.0 encoding = utf-8?>
< manifest xmlns:android = http://schemas.android.com/apk/res/ android
package = com.example.test_shortcut
android:versionCode = 1
android:versionName = 1.0>

< uses-permission android:name = com.android.launcher.permission。 INSTALL_SHORTCUT />
< uses-permission android:name = com.android.launcher.permission.UNINSTALL_SHORTCUT />

< uses-sdk
android:minSdkVersion = 16
android:targetSdkVersion = 19 />

< application
android:allowBackup = true
android:icon = @ drawable / ic_launcher
android:label = @ string / app_name
android:theme = @ style / AppTheme>
< activity
android:name = com.example.test_shortcut.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>

< receiver android:name = com.example.test_shortcut.PackageReplacedReceiver>
< intent-filter>
< action android:name = android.intent.action.PACKAGE_REPLACED /> ;

< data
android:path = com.example.test_shortcut
android:scheme = com.example />
< / intent-filter>
< / receiver>
< / application>

< / manifest>





我已经在模拟器上尝试了我的app api 18和平板电脑android 4.2



任何帮助将不胜感激。谢谢

解决方案

嘿,我试过这段代码,这对我有用。

查看此链接,希望这对您有所帮助。

http://linkflows.blogspot.in/2014/09 /installing-uninstalling-home-screen.html [ ^ ]


I have created app shortcut on home screen. but Its not working. it always

shows the toast app isn't installed

. I have tried 2 different codes but the result is always same.

Here is the first code

private void addShortcut() {
        // Adding shortcut on Home screen
        Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
        shortcutIntent.setAction(Intent.ACTION_MAIN);
        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "AppName");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(
                        getApplicationContext(), R.drawable.ic_launcher));
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(addIntent);
    }



Second code

public static void addShortcut(Context context)
    {
        Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

        ApplicationInfo appInfo = context.getApplicationInfo();

        // Shortcut name
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "appInfo.name");
        shortcut.putExtra("duplicate", false); // Just create once

        // Setup activity shoud be shortcut object 
        ComponentName component = new ComponentName(appInfo.packageName, "MainActivity.class");
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(component));

        // Set shortcut icon
        ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(context, appInfo.icon);
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

        context.sendBroadcast(shortcut);
    }



Log cat and manifest:

02-03 22:36:58.625: E/memtrack(1697): Couldn't load memtrack module (No such file or directory)
    02-03 22:36:58.625: E/android.os.Debug(1697): failed to load memtrack module: -2
    02-03 22:37:02.515: E/memtrack(1708): Couldn't load memtrack module (No such file or directory)
    02-03 22:37:02.515: E/android.os.Debug(1708): failed to load memtrack module: -2
    02-03 22:37:03.255: E/InputDispatcher(388): channel 'b500ff48 com.example.test_shortcut/com.example.test_shortcut.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
    02-03 22:37:13.805: E/WindowManager(388): Starting window AppWindowToken{b5537500 token=Token{b50334a8 ActivityRecord{b502b0e0 u0 com.example.test_shortcut/.MainActivity t7}}} timed out



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test_shortcut"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test_shortcut.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>

        <receiver android:name="com.example.test_shortcut.PackageReplacedReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REPLACED" />

                <data
                    android:path="com.example.test_shortcut"
                    android:scheme="com.example" />
            </intent-filter>
        </receiver>
    </application>

</manifest>



I have tried my app at emulator with api 18 and at tablet with android 4.2

Any help will be appreciated. Thanks

解决方案

Hey, I tried this code and this works for me.
Check this link, i hope this will help you.
http://linkflows.blogspot.in/2014/09/installing-uninstalling-home-screen.html[^]


这篇关于主屏幕应用程序快捷方式不工作android。应用程序未安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆