同じアプリケーション内のアクティビティ間ではなく、Androidの1つのアプリケーションアクティビティから他のアプリケーションアクティビティに文字列データを送信する必要があります。どうやってするか?他のアプリケーションが宣言する必要のあるインテントフィルターは何ですか?例を挙げて詳しく説明してみてください。
3 に答える
私があなたの答えから理解できる限り、あなたは意図を探しています:
アプリAのマニフェスト-アクティビティアルファで、カテゴリDEFAULTおよびアクション=を使用してインテントフィルターを宣言します com.your_app_package_name.your_app_name.ActivtiyAlpha
アプリBのアクティビティベータでは、Aを起動してデータを渡すためのコードを配置します。
Intent i = new Intent("com.your_app_package_name.your_app_name.ActivtiyAlpha");
i.putExtra("KEY_DATA_EXTRA_FROM_ACTV_B", myString);
// add extras to any other data you want to send to b
次に、アプリA-アクティビティアルファに戻り、コードを入力します。
Bundle b = getIntent().getExtras();
if(b!=null){
String myString = b.getString("KEY_DATA_EXTRA_FROM_ACTV_B");
// and any other data that the other app sent
}
少量のデータのみに関心がある場合、Androidはアプリケーション間で設定を共有するためのSharedPreferencesクラスを提供します。特に、OnSharedPreferenceChangeListenerを各アプリケーションに追加して、他のアプリケーションが値を変更したときに通知を受け取ることができます。
最も重要なことは、両方のアプリケーションが実行されていることを確認できないことです。
詳細については、 http://developer.android.com/guide/topics/data/data-storage.htmlをご覧ください。
アプリAからアプリBにGPS座標を渡すブロドキャストを使用して2つのアプリを通信します
これはAPPB(データを送信する人)にあります
Intent sendGPSPams = new Intent();
sendGPSPams.setAction(ACTION_GET_GPS_PARAMS);
sendGPSPams.putExtra("Latitude",latitude);
sendGPSPams.putExtra("Longitude",longitude);
sendGPSPams.putExtra("Velocity",velocity);
sendGPSPams.putExtra("DOP",PDOP);
sendGPSPams.putExtra("Date",time);
sendGPSPams.putExtra("Bearing", bearing);
sendBroadcast(sendGPSPams);
これは、gpsパラメータまたはアプリBから送信されたデータを受信するアプリAにあります
private BroadcastReceiver myBrodcast = new BroadcastReceiver() {
double latitude;
double longitude;
double velocity;
double DOP;
String date;
double bearing;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_GET_GPS_PARAMS)) {
latitude = intent.getDoubleExtra("Latitude", 0);
longitude = intent.getDoubleExtra("Longitude", 0);
velocity = intent.getDoubleExtra("Velocity", 0);
DOP = intent.getDoubleExtra("DOP", 0);
date = intent.getStringExtra("Date");
bearing = intent.getDoubleExtra("Bearing", 0);
String text = "Latitude:\t" + latitude +"\nLongitude\t"+ longitude +
"\nVelocity\t" +velocity +"\nDOP\t" + DOP +"\n Date \t" + date +"\nBearing\t" + bearing;
tv_text.setText(text);
}
}
};
罪状認否はこのビデオを見てください。