[英]Android App to App Communication
我是android初學者。 請給我建議,我將遵循以下程序來開發該應用程序,例如:
例如:如何在App之間進行通信? 例如,例如,我想將圖像或任何其他數據發送到另一台設備或應用程序,請幫助我。
謝謝
switch (intent.getIntExtra(Constants.EXTENDED_DATA_STATUS,
Constants.STATE_ACTION_COMPLETE)) {
要么
在不使用推送通知的情況下,應用程序之間是否有可能進行應用程序通信? 我想將圖像從一個應用程序發送到另一個應用程序,一些建議和意見將不勝感激。
設備上的應用之間的通信與設備之間的通信有很大不同。
在設備內,您可以使用Intent在應用之間進行通信。
// send text
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
// send binary data
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
如果要在網絡上的設備之間共享,則可以使用某種TCP / IP或UDP協議,但是通常我發現藍牙是最簡單的解決方案。 這兩個應用程序都需要了解通信,但這很簡單。
這里有一篇很好的文章: http : //java.dzone.com/articles/bluetooth-data-transfer
本質上,要旨是您:
示例代碼如下所示:
import android.bluetooth.BluetoothAdapter;
// duration that the device is discoverable
private static final int DISCOVER_DURATION = 300;
// our request code (must be greater than zero)
private static final int REQUEST_BLU = 1;
//...
public void enableBlu(){
// enable device discovery - this will automatically enable Bluetooth
Intent discoveryIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoveryIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
DISCOVER_DURATION );
startActivityForResult(discoveryIntent, REQUEST_BLU);
}
然后接收:
// When startActivityForResult completes...
protected void onActivityResult (int requestCode,
int resultCode,
Intent data) {
if (resultCode == DISCOVER_DURATION
&& requestCode == REQUEST_BLU) {
// processing code goes here
}
else{ // cancelled or error
Toast.makeText(this, R.string.blu_cancelled,
Toast.LENGTH_SHORT).show();
}
}
如果需要,您也可以使用自己的藍牙意圖代替操作系統。 您可以從AOSP代碼中獲取藍牙意圖的來源。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.