mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-19 20:02:16 +02:00
share text to open (as url)
This commit is contained in:
parent
8be086d086
commit
c1a64b84ce
@ -27,6 +27,11 @@
|
||||
<data android:scheme="http" />
|
||||
<data android:scheme="https" />
|
||||
</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>
|
||||
<activity android:name=".activities.MainActivity">
|
||||
<intent-filter>
|
||||
|
@ -33,8 +33,7 @@ public class AboutActivity extends Activity {
|
||||
share.setType("text/plain");
|
||||
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
|
||||
// Add data to the intent, the receiving app will decide
|
||||
// what to do with it.
|
||||
// Add data to the intent, the receiving app will decide what to do with it.
|
||||
share.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
|
||||
share.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + getPackageName());
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.trianguloy.urlchecker.dialogs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@ -147,22 +148,39 @@ public class MainDialog extends Activity {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the url that this activity was opened with (intent uri)
|
||||
* @return the url that this activity was opened with (intent uri or sent text)
|
||||
*/
|
||||
private String getOpenUrl() {
|
||||
// get the intent
|
||||
Intent intent = getIntent();
|
||||
if (intent == null) return invalid();
|
||||
|
||||
// get data
|
||||
Uri uri = this.getIntent().getData();
|
||||
|
||||
if (uri == null) {
|
||||
// check in case someone opens this without url
|
||||
Toast.makeText(this, "No url", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return null;
|
||||
// check the action
|
||||
String action = getIntent().getAction();
|
||||
if (Intent.ACTION_SEND.equals(action)) {
|
||||
// sent text
|
||||
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
if (sharedText == null) return invalid();
|
||||
return sharedText.trim();
|
||||
} else if (Intent.ACTION_VIEW.equals(action)) {
|
||||
// view url
|
||||
Uri uri = intent.getData();
|
||||
if (uri == null) return invalid();
|
||||
return uri.toString();
|
||||
} else {
|
||||
// other
|
||||
return invalid();
|
||||
}
|
||||
}
|
||||
|
||||
// return
|
||||
return uri.toString();
|
||||
/**
|
||||
* @return null, finishes the activity and shows a toast
|
||||
*/
|
||||
private String invalid() {
|
||||
// for an invalid parameter
|
||||
Toast.makeText(this, R.string.toast_invalid, Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
return null;
|
||||
}
|
||||
|
||||
// ------------------- url -------------------
|
||||
|
@ -45,7 +45,7 @@ public class UrlUtilities {
|
||||
|
||||
// check if none
|
||||
if (intents.isEmpty()) {
|
||||
Toast.makeText(cntx, R.string.toast_cantOpen, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(cntx, R.string.toast_noBrowser, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@
|
||||
<!-- generic -->
|
||||
<string name="toast_error">Can\'t open activity</string>
|
||||
<string name="toast_noBrowser">Can\'t open the browser</string>
|
||||
<string name="toast_cantOpen">No other apps can open this url</string>
|
||||
<string name="title_choose">Choose app</string>
|
||||
<string name="toast_invalid">Invalid</string>
|
||||
<string name="dd">%s:</string>
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user