I am trying to create a application for android in which I want to allow user to share text using my application.
The code that I have is as follow. Please help me find the error.
I don’t have logcat message because whenever I ran the sharer application in emulator and clicked on share button it directly opened the stock message application, despite my other application being installed in the emulator, so I had to test the application on my phone.
CODE OF APPLICATION I CREATED FOR SHARING
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(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
MAIN APPLICATION
MANIFEST DECLARATION
<activity
android:name="com.example.app.MainActivity"
android:label="@string/title_activity_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
CODE FROM MAINACTIVITY.JAVA
Intent myintent = getIntent();
String action = myintent.getAction();
String type = myintent.getType();
if(Intent.ACTION_SEND.equals(action) && type !=null) {
if("text/plain".equals(type)) {
handleSendText(myintent);
}
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
editText.setText(sharedText);
}
}
Please help me find the error why there no Intent Chooser pop up with my application and the stock message application.
Try to run it in emulator and use debugger to find where your app is crashed then write it here try use catching exceptions