Skip to content

Instantly share code, notes, and snippets.

@avipars
Last active April 30, 2020 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avipars/a7697bf12013cc50dbca6e218075e936 to your computer and use it in GitHub Desktop.
Save avipars/a7697bf12013cc50dbca6e218075e936 to your computer and use it in GitHub Desktop.
unitMeasure - Get Intents
<activity
android:name=".activities.Main"
android:configChanges="orientation"
android:label="@string/app_name"
android:resizeableActivity="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
void handleIntentFromOtherActivity() {
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
if(Helper.isNumeric(sharedText))
{
Toast.makeText(this, sharedText, Toast.LENGTH_SHORT).show();
}
}
}
@avipars
Copy link
Author

avipars commented Apr 30, 2020

I have a numeric method that ensures the String is a number.

It would be best to pass a Double when you open my app, but I can work around if you provide me with a long or a float

@avipars
Copy link
Author

avipars commented Apr 30, 2020

Note to self:

I'll need to add some sort of acknowledgement that data has passed through, then let the user pick a converter and pass the value through to the convert activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment