1

Anybody knows how to open and send a data to another application?

I have a String that I want to send it and I used an ACTION.MAIN and putExtra for send the string:

 String smth = "Test";

 Intent intents = new Intent(Intent.ACTION_MAIN);
 intents.setComponent(new ComponentName("com.package.address","com.package.address.HelloGlassActivity"));
 intents.putExtra("STRING", smth);
 mContext.startActivity(intents);

I declared the intent in Android manifest another project (Application):

 <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
 </intent-filter>

After I declare the intent in Android Manifest, I call the intent in one of my activity:

  Intent intent = getIntent();
  String tester = intent.getStringExtra("STRING");

Unfortunately when I run the first app, I couldn't open the second application. Anybody knows what I have missed?

eng
  • 83
  • 1
  • 9

4 Answers4

0

Just send that intent to application, using startActivity(Intent intent) method. Also you can add specific types to an intent so you could define which activities could catch it.

bgplaya
  • 1,105
  • 15
  • 27
0

I think you have declared your second activity in manifestfile.

Sandeep Kumar
  • 350
  • 4
  • 18
0

Intent divided into two classes,one is explicit intent,like what you do,you set the specific component,but it only works when the component in the same application.second is implicit intent,do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it.which means just build the intent with action,and the activity will catch it depends on action you declare in your intent filter.you mixed two type of intent.

ben
  • 71
  • 2
  • Hi @ben: So I don't have to specify the spesific component? How can I get the intent then? – eng Sep 15 '14 at 06:31
  • by defining the action string in the intent-filter.like`new Intent("my action string")... ` – ben Sep 15 '14 at 07:23
0

use Content Provider. Then to access a file in application A from application B, you can declare a ContentProvider in application A and override the public ParcelFileDescriptor openFile(Uri uri, String mode) method. Then application B can access a file located in data directory of application A through an appropriate uri using the getContentResolver().openInputStream(...) method.

For more information see:

http://www.grokkingandroid.com/handling-binary-data-with-contentproviders/

https://stackoverflow.com/a/4336013/148272

Community
  • 1
  • 1
Rustam
  • 6,485
  • 1
  • 25
  • 25