3

메뉴 항목을 추가해야하는 CustomTabs 라이브러리를 사용하고 싶습니다. 라이브러리는 메뉴 항목에 대한 조치로 사용될 PendingIntent 인스턴스 만 승인합니다. 나는 그냥 한 번과 항상 버튼 하지 않고 목록이 사용자에게 모든 시간을 제안되어 있는지 확인하려면 다음 코드를 사용하려면 :선택기에서 의도를 PendingIntent로 사용하는 방법

Intent shareIntent = Intent.createChooser(intent, "Choose the application to share."); 

그러나 문제는 지금 그 나는이 선택기를 사용하는 경우 PendingIntent로 선택기의 의도를 사용하는 방법이

PendingIntent pendingIntent = PendingIntent.getActivity(context, 
      requestCode, 
      shareIntent, 
      PendingIntent.FLAG_UPDATE_CURRENT); 

있습니까 : 의도, 크롬에 대한 CustomTabs은 사용자의 선택을 해고하지 않는 PendingIntent를 만드는 방법? 당신은 방송 receiever를 사용하여이를 달성 할 수

startActivity(Intent.createChooser(i, getString())); 

답변

3

: 라이브러리가 그 일을하는 하나이며, 그것은 단지 PendingIntents을 허용하기 때문에

나는, 텐트를 시작하려면 다음 라인을 사용할 수 없습니다.

먼저 공유하는 선택기를 만들 수있는 사용자 정의 broadcastreciever 클래스를 만들

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); 
+1

명시 적 브로드 캐스트 ... 암시 적 브로드 캐스트가 올바르게 작동하지 않습니다. – starkej2

+1

또한 AndroidManifest.xml에서 브로드 캐스트 수신기를 선언해야합니다. 다른 방법으로는 작동하지 않습니다. – Markonionini