我正在尝试构建一个android应用程序。有一个选项“共享”可以在“ WhatsApp”中共享当前产品详细信息。此应用没有网站。在那种情况下,我应该共享哪个链接,以便当有人单击时在我的应用中打开特定产品详细信息活动。
请参阅修改后的代码
<activity
android:name="com.bodaty.samyata.samyata4.profiles.Profile"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.bodaty.samyata.samyata4.customer_service.Contacts"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.bodaty.samyata.samyata4.barcode.Barcode"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.bodaty.samyata.samyata4.login_pages.EmailVerification"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
android:name="com.bodaty.samyata.samyata4.product_search.Details"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<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:host="www.samyata.com"
android:scheme="samyata"/>
</intent-filter>
</activity>
<activity
android:name="com.bodaty.samyata.samyata4.product_search.VoiceRecognitionActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
<activity
java代码:
//.....for network.....//
NetworkReceiver networkReceiver;
LinearLayout linearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
setTitle("Product_Details");
if(getSupportActionBar() != null){
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Intent i1 = getIntent();
Uri data = i1.getData();
if(data != null){
Log.e("data", String.valueOf(data));
}else{
Log.e("data123", String.valueOf(data));
}
mAuth = FirebaseAuth.getInstance();
user_id = mAuth.getUid();
listView = findViewById(R.id.list);
ratingBar1 = findViewById(R.id.ratingBar1);
img = findViewById(R.id.img);
ls_data=new ArrayList<>();
// for network...//
linearLayout = findViewById(R.id.linearlayout);
networkReceiver = new NetworkReceiver();
Logcat
Increasing code cache capacity to 1024KB
08-01 07:25:33.316 25408-25413/com.bodaty.samyata.samyata4 I/zygote: Do full code cache collection, code=497KB, data=314KB
08-01 07:25:33.319 25408-25413/com.bodaty.samyata.samyata4 I/zygote: After code cache collection, code=484KB, data=261KB
08-01 07:25:34.420 25408-25408/com.bodaty.samyata.samyata4 I/AssistStructure: Flattened final assist data: 9352 bytes, containing 1 windows, 44 views
08-01 07:25:34.559 25408-25413/com.bodaty.samyata.samyata4 I/zygote: Do partial code cache collection, code=490KB, data=277KB
08-01 07:25:34.565 25408-25413/com.bodaty.samyata.samyata4 I/zygote: After code cache collection, code=490KB, data=277KB
Increasing code cache capacity to 2MB
08-01 07:25:42.710 25408-25408/com.bodaty.samyata.samyata4 E/data123: null
答案 0 :(得分:0)
在没有网站的情况下,这取决于您的应用已预先安装在用户设备上的前提。
假设您的应用程序名称为MyApp,而您选择与应用程序关联的域是www.myapp.com
现在,每当用户单击链接“ https://www.myapp.com/productA”时,都应在DetailActivity.class中打开productA的详细信息页面。
要实现此目的,您必须在清单中针对DetailActivity.class声明添加一个意图过滤器:
<activity
android:name=".DetailActivity"
android:theme="@style/AppTheme">
<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:host="www.myapp.com"
android:scheme="https" />
</intent-filter>
</activity>
在您的活动中,您可以按以下方式获取进入该屏幕的网址:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Intent intent = getIntent();
Uri data = intent.getData(); // data= https://www.myapp.com/productA
String productId = data.getLastPathSegment() // "productA"
}
现在使用此数据,您可以显示productA的详细信息。
您可以使用以下任意过滤器定义目标网址:
<data android:scheme="string"
android:host="string"
android:port="string"
android:path="string"
android:pathPattern="string"
android:pathPrefix="string"
android:mimeType="string" />
有关更多信息,请参阅https://developer.android.com/guide/topics/manifest/data-element
注意:当用户单击链接时,将显示一个对话框,供您在浏览器和您的应用之间进行选择。假设他选择了您的应用。