当我想用真实设备测试我的应用程序时,应用程序无法启动

时间:2016-10-03 11:43:09

标签: java android testing android-emulator

我一直在尝试测试我的应用程序,我正在实施G +登录,当我在Android Studio的模拟器中运行应用程序运行但是说我需要更新Google Play服务。

我一直在努力做到这一点所以我认为我只会在真实设备上测试它,但是当我这样做时,应用程序无法启动/运行。当我转到设备上的设置和应用程序时,我可以看到应用程序已安装,但它不会显示在应用程序抽屉中或其他任何位置。

我在左下角的“运行”标签下得到此异常:

java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.madchallenge2016edwindaniel.upbirdwatchers/.LoginActivity } from null (pid=20620, uid=2000) not exported from uid 10154
    at android.os.Parcel.readException(Parcel.java:1425)
    at android.os.Parcel.readException(Parcel.java:1379)
    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1948)
    at com.android.commands.am.Am.runStart(Am.java:463)
    at com.android.commands.am.Am.run(Am.java:108)
    at com.android.commands.am.Am.main(Am.java:81)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:276)
    at dalvik.system.NativeStart.main(Native Method)

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBar" />
<intent-filter >
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <activity android:name=".RegisterActivity" />
    <activity android:name=".LoginActivity" />
</application>

以下是我的发布活动的代码:

package com.madchallenge2016edwindaniel.upbirdwatchers;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import android.view.View;
import com.google.android.gms.common.ConnectionResult;

public class LoginActivity extends AppCompatActivity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener{

    private GoogleApiClient mGoogleApiClient;
    private SignInButton mSignInButton;
    private static final int RC_SIGN_IN = 9001;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);



        //Background
        getWindow().setBackgroundDrawableResource(R.drawable.login_background);

        // Configure sign-in to request the user's ID, email address, and basic
        // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
        GoogleSignInOptions gso = new     GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    SignInButton mSignInButton = (SignInButton)findViewById(R.id.sign_in_button);
    mSignInButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.sign_in_button:
                    signIn();
                    break;
                // ...
            }
        }
    });
}

//Start sign in
private void signIn() {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }


}

private void handleSignInResult(GoogleSignInResult result) {

    if (result.isSuccess()) {



    } else {
        // Signed out, show unauthenticated UI.
        // updateUI(false);
    }
}

@Override
public void onConnected(Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}

public void setmSignInButton(SignInButton mSignInButton) {
    this.mSignInButton = mSignInButton;
}
}

根据我得到的答案编辑我的清单文件后,我的应用程序现在运行。 这是我更新的清单文件的样子:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".LoginActivity"
        android:exported="true">
        <intent-filter >
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
     </activity>
    <activity android:name=".RegisterActivity" />
    <activity android:name=".MainActivity"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBar"/>
</application>

1 个答案:

答案 0 :(得分:0)

你错过了android清单中的Intent过滤器

请用以下代码替换您的清单......

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    <activity android:name=".RegisterActivity" />
    <activity android:name=".LoginActivity" />
</application>

意图过滤器显示何时启动此活动。通常,您将拥有一个带有intent过滤器的活动,以表明它是启动应用程序时的第一个活动。