2017-03-27 20 views
0

ブラウザを作成していて、サイトアイコン(apple-touch-icon)とタイトルがランチャーによって取り込まれて表示されるように、「ホーム画面にサイトを追加」ボタンを実装したい。Androidアイコンをホーム画面(ランチャー)に追加する

if (getIntent() != null){ 
     Intent intent = getIntent(); 

     //empty 
     String url1 = intent.getStringExtra("EXTRA_URL"); 
    } 

がどのように私は余分なparametr(URL)を渡す必要があり、:余分なデータがない

 Intent shortcutIntent = new Intent(); 
     shortcutIntent.setClassName(getPackageName(), "Browser"); 
     shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY); 
     shortcutIntent.putExtra("EXTRA_URL", webView.getUrl()); 

     Intent intent = new Intent(); 
     intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
     intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, webView.getTitle()); 
     intent.putExtra(Intent.EXTRA_ORIGINATING_URI, webView.getUrl()); 

     //TODO change to apple-touch icon 
     Bitmap btm = webView.getFaviconImage(); 
     intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, btm); 

     intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
     sendBroadcast(intent); 

しかし、残念ながら、のonCreateで意図がある -

私はそれを行うコードを発見しました私はそれを読むことができるようにランチャーに?

答えて

0

この

intent.putExtra(EXTRA_URL, Uri.parse(webView.getUrl())); 
+0

を動作しない、まだ到着するデータがないテント –

0

は、だから私は、次のコードを使用してこのタスクを解決するために管理してください:起動ツールに

送るショートカット:

 Intent shortcutIntent = new Intent(getApplicationContext(), BrowserActivity.class); 
     shortcutIntent.putExtra(BrowserUnit.EXTRA_URL, webView.getUrl()); 

     Intent intent = new Intent(); 
     intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
     intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, webView.getTitle()); 

     //TODO change to apple-touch icon 
     Bitmap btm = webView.getFaviconImage(); 
     intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, btm); 

     intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
     sendBroadcast(intent); 

は、適切なURLを盗ん:

 //in onCreate 
     if (getIntent() != null){ 
     //if we are launching from launcher shortcut 
     Bundle bundel = getIntent().getExtras(); 
     if (bundel != null) { 
      String url = bundel.getString(BrowserUnit.EXTRA_URL); 
      onSearchPressed(url); 
     } 
    } 
関連する問題