Advertisement
BankUpload Join!

Tuesday, February 17, 2015

INTEGRATING APPLICATION DELPHI XE7TWITTER WITH TWITTER

delphi twiter


INTEGRATING APPLICATION DELPHI XE7 ANDROID WITH TWITTER


Both desktop and mobile, in development on several occasions the need to have our application interact with other applications of the target platform in our development.


Straight to the point

Let's cut to Delphi and start a Multi-Device application (File-> New-> Other-> Multi-Device Projects-> Blank Application).
Let's take a recapitulated in should be configured as the Project Manager:

For teaching purposes we will use only 1 TImage and 5 TButtonswe'll set its properties as follows:
  • Button1
    • Align -> Botton
    • Text -> Profile
    • Heigth -> 36
  • Button2
    • Align -> Botton
    • Text -> Time Line
    • Heigth -> 36
  • Button3
    • Align -> Botton
    • Text -> Categories
    • Heigth -> 36
  • Button4
    • Align -> Botton
    • Text -> DM
    • Heigth -> 36
  • Button5
    • Align -> Botton
    • Text -> Send Tweet
    • Heigth -> 36
  • Image1
    • MultiResBitmap -> [An image of your choice]
    • Align -> Client
At the end of these our application settings will look similar to this:
Once you set the application interface, it is understood the operation thereof for the button clicks will run their described in the texts of the same operations. Anyway, here's the code.

Encoding functions

Before we start the codes can not forget to include the Unitsresponsible for integrating Delphi Android, in the implementationsection we will declare the uses:
  uses
   FMX.Helpers.Android, Androidapi.Jni.GraphicsContentViewText,
   Androidapi.Jni.Net, Androidapi.Jni.JavaTypes, idUri, Androidapi.Jni,
   Androidapi.JNIBridge, Androidapi.Helpers; 
To win time already go straight to each of the codes of buttons:
  procedure TForm1.Button1Click (Sender: TObject);
 var
   IntentPerfil: JIntent;
 begin
 // Profile - Running
   IntentPerfil: = TJIntent.JavaClass.init (TJIntent.JavaClass.ACTION_VIEW);
   IntentPerfil.setClassName (StringToJString ('com.twitter.android'),
     StringToJString ('com.twitter.android.ProfileActivity'));  // Profile
   IntentPerfil.putExtra (StringToJString ('screen_name'), StringToJString ('@ landersongomes'));
   SharedActivity.startActivity (IntentPerfil);
 end; 
For the Time Line button are:
  procedure TForm1.Button2Click (Sender: TObject);
 var
   IntentTimeLine: JIntent;
 begin
 // Show Time Line
   IntentTimeLine: = TJIntent.JavaClass.init (TJIntent.JavaClass.ACTION_VIEW);
   IntentTimeLine.setClassName (StringToJString ('com.twitter.android'),
     StringToJString ('com.twitter.android.TimelineActivity'));  // Show the TimeLine
   SharedActivity.startActivity (IntentTimeLine);
 end; 
As for the categories the code will be:
  procedure TForm1.Button3Click (Sender: TObject);
 var
   IntentCateg: JIntent;
 begin
 // Accounts Categories
   IntentCateg: = TJIntent.JavaClass.init (TJIntent.JavaClass.ACTION_VIEW);
   IntentCateg.setClassName (StringToJString ('com.twitter.android'),
     StringToJString ('com.twitter.android.CategoriesActivity'));
   SharedActivity.startActivity (IntentCateg);
 end; 
The Direct Messaging, or DM have implemented their view through the code:
  procedure TForm1.Button4Click (Sender: TObject);
 var
   IntentDM: JIntent;
 begin
 // See Received Messages
   IntentDM: = TJIntent.JavaClass.init (TJIntent.JavaClass.ACTION_VIEW);
   IntentDM.setClassName (StringToJString ('com.twitter.android'),
     StringToJString ('com.twitter.android.MessagesActivity'));  // Show DM received
   SharedActivity.startActivity (IntentDM);
 end; 
Finally, the code to send one Twett:
  procedure TForm1.Button5Click (Sender: TObject);
 var
   IntentTweet: JIntent;
 begin
 // Send tweet
   IntentTweet: = TJIntent.JavaClass.init (TJIntent.JavaClass.ACTION_SEND);
   IntentTweet.setClassName (StringToJString ('com.twitter.android'),
         StringToJString ('com.twitter.android.composer.ComposerActivity'));  // Send Tweet
   IntentTweet.putExtra (TJIntent.JavaClass.EXTRA_TEXT,
                 StringToJString ('Sending tweet developed by #Android applications' +
                  'WithEmbarcaderoTech #Delphi XE7.  Check out the blog http://goo.gl/tRWiqS ').);
   SharedActivity.startActivity (IntentTweet);
 end; 

All ready, just run and see the results!
Note: Inserting the EXTRA_TEXT line for the intent of DM you can also make sending them again but it still fails and establish the recipient of the same but through the user manual selection.

No comments:

Post a Comment