从另一个应用程序启动外部“隐形”应用程序

问题描述:

我创建了一些没有图标的小应用程序,并且这些应用程序无法在Android的应用程序菜单中直接启动。要小心谨慎,我删除了应用程序的意图过滤器部分:从另一个应用程序启动外部“隐形”应用程序

<intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 

现在,我要开始一个大的(我有一个列表视图列出所有的小应用程序),这些小应用程序。当用户点击其中一个应用程序时,我开始了相应应用程序的活动。但是当我用小应用程序的packageName做到这一点时,什么也没有发生。

我真的很想保持这种模块化,因为有很多小应用程序对用户是不可见的,只能从一个大应用程序启动它。

如果可能,我该怎么做。

感谢

public class MainActivity extends ListActivity { 

/** 
* This class describes an individual SoftFunction (the function title, and the activity class that 
* demonstrates this function). 
*/ 
private class SoftFunction { 
    private CharSequence title; 
    private String packageName; 

    public SoftFunction(int titleResId, int appPackageResId) { 
     this.title = getResources().getString(titleResId); 
     this.packageName = getResources().getString(appPackageResId); 
    } 

    @Override 
    public String toString() { 
     return title.toString(); 
    } 
} 
    /** 
    * The collection of all Soft Functions in the app. This gets instantiated in {@link 
    * #onCreate(android.os.Bundle)} because the {@link Sample} constructor needs access to {@link 
    * android.content.res.Resources}. 
    */ 
private static SoftFunction[] mSoftFunctions; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // Instantiate the list of samples. 
    mSoftFunctions = new SoftFunction[]{ 
      new SoftFunction(R.string.title_app_test1, R.string.app_test1_package_name), 
      new SoftFunction(R.string.title_app_test2, R.string.app_test2_package_name), 
      new SoftFunction(R.string.title_app_test3, R.string.app_test3_package_name), 
      new SoftFunction(R.string.title_app_test4, R.string.app_test4_package_name), 
    }; 

    setListAdapter(new ArrayAdapter<SoftFunction>(this, 
      android.R.layout.simple_list_item_1, 
      android.R.id.text1, 
      mSoftFunctions)); 
} 

    @Override 
    protected void onListItemClick(ListView listView, View view, int position, long id) { 
     // Launch the sample associated with this list position. 
     Intent i = getPackageManager().getLaunchIntentForPackage(mSoftFunctions[position].packageName); 

     if (i != null) 
     { 
      startActivity(i); 
     } 
    } 

} 
+0

我敢肯定,这是默认禁用的,因为这对于任何应用程序来说都是非常阴暗的行为。 – 2014-11-06 13:37:34

+0

对于没有可启动活动的应用程序,我看不到任何阴影。 – Okas 2014-11-06 15:34:44

你必须设置机器人:出口= “真” 为贵 “的小应用程序” 的活动。这是因为默认情况下没有意向过滤器的活动不会被导出。

像这样:

<activity 
    android:name=".YourActivity" 
... 
    android:exported="true" /> 

就可以启动使用包名称和活动名称外部应用这项活动。

Intent intent=new Intent(); 
intent.setComponent(new ComponentName("com.your.package.name", "com.your.package.name.YourActivity")); 
startActivity(intent); 
+0

它没有改变任何东西:/如果没有意图过滤器,仍然不能工作 – Eydolol 2014-11-07 08:46:35

+0

也许我们可以帮助你,如果你发布你的代码。 – Okas 2014-11-07 11:02:06

+0

我添加了启动所有应用程序的应用程序的代码。问题在于Intent始终为空:/ – Eydolol 2014-11-07 12:32:28