Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add share target in share sheet to open URLs from other apps #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
<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>
</application>

</manifest>
</manifest>
17 changes: 15 additions & 2 deletions app/src/main/java/io/liriliri/eruda/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var btnGoForward: ImageView
private lateinit var favicon: ImageView
private lateinit var manager: InputMethodManager
private var initialURL = "https://github.com/liriliri/eruda"
private val TAG = "Eruda.MainActivity"
var mFilePathCallback: ValueCallback<Array<Uri>>? = null
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -48,10 +49,22 @@ class MainActivity : AppCompatActivity() {

manager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager

onNewIntent(getIntent())

initView()
initWebView()
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (Intent.ACTION_SEND.equals(intent.getAction())
|| Intent.ACTION_SENDTO.equals(intent.getAction())) {
if (intent != null) {
intent.getStringExtra(Intent.EXTRA_TEXT)!!.also { this.initialURL = it }
}
}
}

private fun initView() {
webView = findViewById(R.id.webView)
progressBar = findViewById(R.id.progressBar)
Expand Down Expand Up @@ -298,7 +311,7 @@ class MainActivity : AppCompatActivity() {
}
}

webView.loadUrl("https://github.com/liriliri/eruda")
webView.loadUrl(initialURL)
}

override fun dispatchTouchEvent(event: MotionEvent): Boolean {
Expand Down Expand Up @@ -333,4 +346,4 @@ fun mayBeUrl(text: String): Boolean {
val domains = arrayOf(".com", ".io", ".me", ".org", ".net", ".tv", ".cn")

return domains.any { text.contains(it) }
}
}