2017-01-10 3 views
0

私はさまざまなウェブサイトを表示するためにクロムカスタムタブを使用しています.iはカスタムタブのアクションバーに共有リンクボタンを追加しました。カスタムタブで余分なテキストデータを変更する実行時にアクションバーボタン

 builder.setActionButton(bitmap,shareLabel,createPendingShareIntent());  

と私のpendingintent機能

private PendingIntent createPendingShareIntent() { 
    Intent actionIntent = new Intent(Intent.ACTION_SEND); 
    actionIntent.setType("text/plain"); 
    actionIntent.putExtra(Intent.EXTRA_TEXT,getResources().getString(R.string.chromeextra)); 
    return PendingIntent.getActivity(
      getApplicationContext(), 0, actionIntent, 0); 
} 

今私は、ユーザーによって開かれているリンク上depanding共有リンクについてIntent.EXTRA_TEXTを変更したいです。

私はPendingIntent.FLAG_UPDATE_CURRENTについて知っていますが、このシナリオでの使用方法はわかりません。

答えて

0

私は長い間、解決策を見つけました。 私はこれを放送受信機を使って行っています。

最初のリンクを共有する

ShareBroadcastReceiver.javaその後、

public class ShareBroadcastReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    String url = intent.getDataString(); 
    if (url != null) { 
     Intent shareIntent = new Intent(Intent.ACTION_SEND); 
     shareIntent.setType("text/plain"); 
     shareIntent.putExtra(Intent.EXTRA_TEXT,context.getResources().getString(R.string.chromeextra)+ url); 

     Intent chooserIntent = Intent.createChooser(shareIntent, "Share url"); 
     chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

     context.startActivity(chooserIntent); 
    } 
} 

}

カスタムタブビルダークラスで

String shareLabel = getString(R.string.label_action_share); 
Bitmap icon = BitmapFactory.decodeResource(getResources(), 
     android.R.drawable.ic_menu_share); 

//Create a PendingIntent to your BroadCastReceiver implementation 
Intent actionIntent = new Intent(
     this.getApplicationContext(), ShareBroadcastReceiver.class); 
PendingIntent pendingIntent = 
     PendingIntent.getBroadcast(getApplicationContext(), 0, actionIntent, 0);    

//Set the pendingIntent as the action to be performed when the button is clicked.    
intentBuilder.setActionButton(icon, shareLabel, pendingIntent); 
をメニュー項目を設定したカスタムbroadcastrecieverクラスを作成します
関連する問題