Last active
April 30, 2020 11:48
-
-
Save avipars/a7697bf12013cc50dbca6e218075e936 to your computer and use it in GitHub Desktop.
unitMeasure - Get Intents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
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
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