2012-11-29 16 views
5

Pracuję nad aplikacją, która powinna zwrócić tekst do aplikacji, która rozpoczęła intencję.Rozpocznij aktywność dla wyniku z IME

Ale aplikacja, która zaczyna intencję, to IME/miękka klawiatura. Funkcja StartActivityForResult jest niedostępna, ponieważ edytor IME jest usługą.

Jak mogę to osiągnąć?

Co mam tak daleko:

Klawiatura:

final Intent intent = new Intent("com.example.helloworld.GETTEXT"); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
intent.putExtra("keyboard", true); 
startActivity(intent); 

Inne App:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Bundle extras = getIntent().getExtras(); 
    if (extras == null){     
     return; 
    } else { 
     finish(); 
    } 
} 

@Override 
public void finish() { 
    Intent data = new Intent(); 
    data.putExtra("test", "PASSED"); 
    setResult(RESULT_OK, data); 
    super.finish(); 
} 
+0

nie możesz użyć do tego odbiornika? –

Odpowiedz

0

Można użyć ResultReceiver za to myśleć.

ResultReceiver lReceiver = new KeyboardResultReceiver(aListener); 
final Intent intent = new Intent("com.example.helloworld.GETTEXT"); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
intent.putExtra(EXTRA_RESULT_RECIEVER, lReceiver); 
intent.putExtra("keyboard", true); 
startActivity(intent); 

private static final class KeyboardResultReceiver extends ResultReceiver { 

    public FileUploadResultReceiver() { 
    } 

    @Override 
    protected void onReceiveResult(int aResultCode, Bundle aResultData) { 
      //Do your thing here you can also use the bundle for your data transmission 
    } 
} 
1

Można użyć ResultReceiver. Spójrz na this example, to całkiem jasne, wyjaśnia, jak to działa.

Powiązane problemy