我将应用插入到共享列表中,如下所示:
<activity
android:name="xxxx.MainActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|uiMode|orientation|screenSize|smallestScreenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan">
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
然后像下面这样从Intent
获取值:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (getIntent().getExtras() != null) {
Intent intents = getIntent();
String action = intents.getAction();
String type = intents.getType();
if (action != null && type != null) {
String receivedUri = intents.getParcelableExtra(Intent.EXTRA_STREAM).toString();
}
}
}
问题
但是当我的应用程序最近时,我没有从intent
获得任何价值。我该怎么办?
答案 0 :(得分:2)
最近一次看到您的活动时,GetIntent()。getExtras()将为空。要获取新的Intent,您必须覆盖活动的'getNewIntent'方法
@Override
protected void onNewIntent(Intent intents)
{
super.onNewIntent(intents);
if (intents != null) {
String action = intents.getAction();
String type = intents.getType();
if (action != null && type != null) {
String receivedUri = intents.getParcelableExtra(Intent.EXTRA_STREAM).toString();
}
}
}