Call twicca for tweet from your app/plug-in

twicca can hook WebIntent of Twitter. By using this feature, you can provide Tweet function without cumbersome authentication.

Snippet

This is a snippet to call twicca tweets view with your text from your app/plug-in. If it have not installed twicca, it open Twitter.com in browser. User can tweet your text on Twitter.com.

public static void tweet( Context context, String tweet ){
	Uri.Builder builder = Uri.parse( "https://twitter.com/intent/tweet" ).buildUpon();
	builder.appendQueryParameter( "text", tweet ); // WebIntent parameter.
	// Add WebIntent parameter here if you need.
	
	Uri web_intent_uri = builder.build();
	
	try{
		// Try to open tweet via twicca.
		Intent intent = new Intent( Intent.ACTION_VIEW, web_intent_uri );
		intent.addCategory( Intent.CATEGORY_DEFAULT );
		intent.setPackage( "jp.r246.twicca" );
		context.startActivity( intent );
		return;
	}
	catch( ActivityNotFoundException e ){
		// twicca is not intalled. 

		// If you need, you can customize here for your own authentication. 

		// Open Twitter's WebIntents in browser. 
		Intent intent = new Intent( Intent.ACTION_VIEW, web_intent_uri );
		intent.addCategory( Intent.CATEGORY_DEFAULT );
		context.startActivity( intent );
		return;
	}
}