我有一個應用程序A和一個應用程序B,我試圖從應用程序A打開一個應用程序B的活動,這不是主要活動。爲什麼我無法使用軟件包名稱訪問我的活動?
我知道這個問題已經有很多答案,但我無法設法做出任何這些工作,這就是爲什麼我要求幫助。
首先這裏是應用B(即必須打開的)的「簡化」清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rlaville.gestionsav" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".Vues.CreationSav"
android:windowSoftInputMode="stateHidden"
android:noHistory="true">
</activity>
<activity android:name=".Vues.GestionSav" android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Vues.StatSav" android:noHistory="true">
</activity>
<activity android:name=".Vues.ModifierSav" android:noHistory="true" android:windowSoftInputMode="stateHidden" android:exported="true" >
<action android:name="com.example.rlaville.gestionsav.MODIFY_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</activity>
<provider
android:name=".Donnees.SavDataProvider"
android:authorities="com.example.rlaville.gestionsav.Donnees.SavDataProvider"
android:exported="true"
></provider>
</application>
</manifest>
我想開是ModifierSav的活動,所以我也把一個意圖過濾器內正如它在每個教程中所說的那樣。
然後我試着在其他應用這些方法:
直接調用的意圖過濾器名稱:
Intent i = new Intent("com.example.rlaville.gestionsav.MODIFY_ACTIVITY");
i.putExtra("CurrentSavID", itemId);
startActivity(i);
或使用packageManager:
public boolean openSavApp(Context ctx, String packageName, long itemId){
PackageManager manager = ctx.getPackageManager();
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.putExtra("CurrentSavID", itemId);
ctx.startActivity(i);
return true;
}
,我試着這樣的電話
openSavApp(getActivity(), "com.example.rlaville.gestionsav.MODIFY_ACTIVITY", itemId);
我在做什麼錯?我應該怎麼做才能從另一個應用程序中打開這個特定的活動?
哇我總是犯最愚蠢的錯誤...非常感謝您的幫助 – RiddlerNewComer
但是,當我打電話給openSavApp(getActivity(),「com.example.rlaville.gestionsav.MODIFY_ACTIVITY」,itemId);我的意圖仍然是空的,即使有意圖過濾器 – RiddlerNewComer
@RiddlerNewComer你想通過調用'openSavApp(getActivity(),「com.example.rlaville.gestionsav.MODIFY_ACTIVITY」,itemId);'方法?你想重新啓動應用程序? –