2016-10-08 6 views
-4

私のアプリのショートカット/ランチャーアイコンを360セキュリティのようにホームスクリーン上に作成し、ユーザーが入力せずにアイコンをクリックしたときにアクティビティをリリースしたいアプリ内で私のアプリケーションのショートカットを360セキュリティのようなホームスクリーンに追加するには

+1

これはあなたの最初の質問です。私はあなたに少しフィードバックを提供したいと思います。まず、他の人があなたの質問に投票した理由を確かめることはできませんが、通常は質問サイトの範囲を満たしている必要があります。これはおそらくそうではないでしょうし、解決策を探して、あなたがすでに試したことを言ってください。また、あなたの質問をより詳しく説明したいと思うかもしれません。あなたが働いているものを誰かが見ることが困難なことがよくあります。あなたのQを編集して、あなたが使っているバージョンを言うことは良いことです。お役に立てれば。 –

答えて

1
private void addShortcut() { 

    //Adding shortcut for MainActivity 
    //on Home screen 
    Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); 
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    shortcutIntent.putExtra(Constants.DEVICE_NO, mDevice.getFDeviceNo()); 
    shortcutIntent.setAction(Intent.ACTION_MAIN); 
    Intent addIntent = new Intent(); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mDevice.getFName()); 
    int defaultImageRes = Utils.getDeviceImage(mDevice.getFViewType()); 
    int color = Color.RED; 
    Bitmap defaultBitmap = overlay(BitmapFactory.decodeResource(getResources(), defaultImageRes), color); 
    if (mDevice.isCustomImage() && !mDevice.getFImage().isEmpty()) { 
     File file = MyApplication.getImageLoader(this).getDiskCache().get(ImageUtils.getImageUrl(mDevice.getFImageName())); 
     } 
     Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); 
     if (bitmap != null) { 
      Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 128, 128, true); 
      addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap); 
     } else { 
      addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, defaultBitmap); 
     } 
    } else { 
     addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, defaultBitmap); 
    } 

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    getApplicationContext().sendBroadcast(addIntent); 
    Toast.makeText(this, R.string.added_to_home_screen, Toast.LENGTH_SHORT).show(); 
} 
関連する問題