2013-12-12 1 views
0

안녕하세요 내가 개발하고 텍스트를 하나의 편집 텍스트 상자에서 Kik 같은 다른 응용 프로그램으로 보내야하는 응용 프로그램을 만들려고 이미 공유 메뉴를 만들었습니다. 단지 내 편집 텍스트 상자에서 텍스트를 보내도록해야합니다.편집 텍스트 상자에서 다른 앱으로 텍스트를 보내려면 어떻게해야합니까?

을 heres 내 주 메뉴 코드 (XML) :

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:id="@+id/menu_share" 
     android:title="Share" 
     android:orderInCategory="100" 
     android:showAsAction="ifRoom" 
     android:actionProviderClass= "android.widget.ShareActionProvider" /> 

</menu> 

그리고 heres는 내 자바 :

package com.example.Encryptor_Kik; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuInflater; 
import android.view.MenuItem; 
import android.widget.ShareActionProvider; 

/** 
* Created with IntelliJ IDEA. 
* Date: 12/12/13 
* Time: 3:15 PM 
* To change this template use File | Settings | File Templates. 
*/ 
public class Decryptor extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.decryption); 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater menuInflater = getMenuInflater(); 
    menuInflater.inflate(R.menu.menu2, menu); 
    MenuItem shareItem = menu.findItem(R.id.menu_share); 

    ShareActionProvider mShare = (ShareActionProvider)shareItem.getActionProvider(); 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setAction(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Hi"); 
    mShare.setShareIntent(shareIntent); 


    return super.onCreateOptionsMenu(menu); 
} 




} 

답변

0

문제는 코드가 onCreateOptionsMenu에 그것에게 당신의 EditText을 만들 때 점이다 는 비어 있으므로 text이 비어 있습니다. 텍스트 변경을 위해 리스너를 추가해야합니다. 여기에 전체 코드 -

public class Decryptor extends Activity { 
EditText e; 
private ShareActionProvider mShare; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.decryption); 
    e=(EditText)findViewById(R.id.YourID); 
    e.addTextChangedListener(commonTextWatcher); 


    TextWatcher commonTextWatcher 
    = new TextWatcher(){ 

    @Override 
    public void afterTextChanged(Editable s) { 
    String text=e.getText.toString(); 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setAction(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, text); 
    if (mShare != null) { 
    mShare.setShareIntent(shareIntent); 
    } 
    } 

    @Override 
    public void beforeTextChanged(CharSequence s, int start, int count, 
    int after) { 
    // TODO Auto-generated method stub 

    } 

    @Override 
    public void onTextChanged(CharSequence s, int start, int before, 
    int count) { 
    // TODO Auto-generated method stub 

    }}; 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater menuInflater = getMenuInflater(); 
    menuInflater.inflate(R.menu.menu2, menu); 
    MenuItem shareItem = menu.findItem(R.id.menu_share); 
    String text=e.getText.toString(); 
    mShare = (ShareActionProvider)shareItem.getActionProvider(); 
    Intent shareIntent = new Intent(Intent.ACTION_SEND); 
    shareIntent.setAction(Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(Intent.EXTRA_TEXT, text); 
    mShare.setShareIntent(shareIntent); 


    return super.onCreateOptionsMenu(menu); 
} 
} 
+0

당신이 오류가없는 말했듯이 내가했던이지만 없다 '공유'의 코드를 표시 @LochlanKennedy이 –

+0

에서 텍스트 않습니다. 내가 말한 것을 어떻게 구현 했니? – Naddy

+0

수정 사항을 확인하십시오. – Naddy

관련 문제