Android 如何与我的应用程序共享链接?
如何打开由其他应用程序共享的网络视图中的链接Android 如何与我的应用程序共享链接?,android,android-intent,Android,Android Intent,如何打开由其他应用程序共享的网络视图中的链接 <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
我已经试过了,但它没有列出我的应用程序-
TextView uri = (TextView) findViewById(R.id.urlField);
//if (Intent.ACTION_MAIN.equals(getIntent().getAction())) {
String intentUri = (new Intent("com.example.browsableintent.MY_ACTION"))
.toUri(Intent.URI_INTENT_SCHEME).toString();
uri.setText(intentUri);
Log.w("URLHandler", intentUri);
//} else {
Uri data = getIntent().getData();
if (data == null) {
uri.setText(" ");
} else {
uri.setText(getIntent().getData().toString());
}
//}
// Load URL from Browsable intent filter if there is a valid URL pasted
if (uri.length() > 0)
webView.loadUrl(url);
else
// dont load
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
显示
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
要允许其他应用程序启动您的活动,您需要在清单文件中为相应的
添加
元素
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
如何打开由其他应用程序共享的网络视图中的链接?我希望我的应用程序在此列表中
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
我已经试过了,但它没有列出我的应用程序-
TextView uri = (TextView) findViewById(R.id.urlField);
//if (Intent.ACTION_MAIN.equals(getIntent().getAction())) {
String intentUri = (new Intent("com.example.browsableintent.MY_ACTION"))
.toUri(Intent.URI_INTENT_SCHEME).toString();
uri.setText(intentUri);
Log.w("URLHandler", intentUri);
//} else {
Uri data = getIntent().getData();
if (data == null) {
uri.setText(" ");
} else {
uri.setText(getIntent().getData().toString());
}
//}
// Load URL from Browsable intent filter if there is a valid URL pasted
if (uri.length() > 0)
webView.loadUrl(url);
else
// dont load
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
取自Chromium AndroidManifest.xml:
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.j2ko.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<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.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
</application>
</manifest>
Android将在“选择应用程序”对话框中列出您
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
客户端应用程序的完整示例:
在AndroidManifest.xml中:
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.j2ko.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:launchMode="singleTask">
<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.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
</application>
</manifest>
我强烈建议你阅读文档,它非常简单,如果你想了解更多关于android的信息,你至少应该能够理解其中的内容。我已经编辑了答案,以便更彻底地解释它,我希望它能有所帮助@你说的是哪个url?如果你想向打开你的活动的应用程序返回一些结果,请使用setResult查看我已更新了答案。有关打开你的活动的应用程序的所有数据都在此处传递//获取启动此活动的意图intent=getIntent();Uri data=intent.getData();您是否记录了l ink链接中的内容?是的,将其放入setContentVIew(R.layout.main)后面的onCreate中你能得到链接吗?我不知道如何检查。你能编辑你的问题并复制粘贴整个活动和AndroidManifest文件吗?@gaurav4sarma我看不出我的答案和其他答案之间有任何关系。colechole下面的答案能解决您的问题吗?对不起,我的问题是,当我的webview收到这个URL/数据/链接时,我实际上如何在其中加载它?在遵循gaurav的清单部分之后,我的应用程序将被列在“开放”应用程序中。但是,我想加载这个URL,你能修复我的java部分吗?(请参阅相关代码)@colechole然后,当您从intent提取url时,请执行以下webview.loadUrl(url)
。我需要有关崩溃的更多信息-请在崩溃后记录日志。