简体   繁体   English

从另一个应用程序启动测试项目

[英]launching a test project from another application

I have created a test project for one of android app. 我已经为一个Android应用程序创建了一个测试项目。 This test project also creates an excel file with some content. 该测试项目还会创建一个包含某些内容的excel文件。 Now, every time i have to run the app, I have to connect my device and run it through eclipse. 现在,每次我必须运行该应用程序时,都必须连接我的设备并通过Eclipse运行它。 However, I need to generate the excel whenever I want (on the go). 但是,我需要随时随地生成Excel。

But my test app doesn't show up in the launcher(obviously). 但是我的测试应用程序没有显示在启动器中(显然)。 I can only see the test project installed at, Settings-->Apps-->All . 我只能在“设置”->“应用程序”->“所有”中看到安装的测试项目。 And hence I cannot even tap and launch. 因此,我什至无法点击并启动。 (First problem) (第一个问题)

My Approach : I thought of creating a separate android app with one or two buttons and invoking the test app with onClickListner event. 我的方法 :我想用一个或两个按钮创建一个单独的android应用程序,并使用onClickListner事件调用测试应用程序。 But again, the new app is unable to find the test class. 但是同样,新应用无法找到测试类。

This is my code : 这是我的代码:

private OnClickListener launchListener = new OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setComponent(new ComponentName("com.org.search.test","com.org.search.test.MyTestClassName"));
            startActivity(intent);
        } 
    };

And below is the exception log: 下面是异常日志:

03-10 17:05:44.185: E/AndroidRuntime(22195): FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class      {com.org.search.test/com.org.search.test.MyTestClassName}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3390)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivity(Activity.java:3587)
at android.app.Activity.startActivity(Activity.java:3555)
at com.expedia.pb.activity.ScrapeActivity$2.onClick(ScrapeActivity.java:49)

Adding Android Manifest file : 添加Android Manifest file

   <?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.pb.activity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/PB_APP"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.pb.activity.ScrapeActivity"
            android:label="@string/PB_APP" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity  
            android:name="com.org.search.test.MyTestClassName">
        </activity>
    </application>

</manifest>

Can someone please help me out to solve this problem? 有人可以帮我解决这个问题吗?

It shows that you forget to declare com.org.search.test.MyTestClassName in your manifest file. 它表明您忘记在清单文件中声明com.org.search.test.MyTestClassName

Make sure you have regiestered your MyTestClassName activity in your manifest file as below: 确保您已在清单文件中重新注册MyTestClassName活动,如下所示:

     <activity
        android:name=".MyTestClassName"
        android:label="@string/basic_map" />

Add category as launcher in your test activity. 在测试活动中将类别添加为启动器。 launch icon will be displayed in your homescreen. 启动图标将显示在您的主屏幕中。

<activity
        android:name="com.pb.activity.ScrapeActivity"
        android:label="@string/PB_APP" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity  
        android:name="com.org.search.test.MyTestClassName">
 <category android:name="android.intent.category.LAUNCHER" />
    </activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM