我制作了一个简单的应用程序,该应用程序的活动可以在单击图像时播放视频(效果很好),但是后来我尝试将其与Amazon Login SDK合并,此后它就无法播放视频。它没有显示任何错误。
包com.amazon.identity.auth.device.lwaapp;
import android.content.Intent;导入android.os.Bundle;进口 android.support.v7.app.AppCompatActivity;导入android.view.View; 导入android.widget.ImageView;
公共类MainActivity扩展了AppCompatActivity实现 View.OnClickListener {
@Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imageView1 = (ImageView) findViewById( R.id.imageView1 ); imageView1.setOnClickListener( this ); ImageView imageView2 = (ImageView) findViewById( R.id.imageView2 ); imageView2.setOnClickListener( this ); ImageView imageView3 = (ImageView) findViewById( R.id.imageView3 ); imageView3.setOnClickListener( this ); ImageView imageView4 = (ImageView) findViewById( R.id.imageView4 ); imageView4.setOnClickListener( this ); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.imageView1: openActivity1(); Intent intent = new Intent( this, Activity1.class ); startActivity( intent ); break; case R.id.imageView2: openActivity2(); Intent intent1 = new Intent( this, Activity2.class ); startActivity( intent1 ); break; case R.id.imageView3: openActivity3(); Intent intent2 = new Intent( this, Activity3.class ); startActivity( intent2 ); break; case R.id.imageView4: openActivity4(); Intent intent3 = new Intent( this, Activity4.class ); startActivity( intent3 ); break; default: openActivity1(); } } private void openActivity1() { } private void openActivity2() { } private void openActivity3() { } private void openActivity4() { } }
/ *用于亚马逊登录活动的Java文件,我什至尝试在此处调用AppcompatActivity,但随后我的应用程序停止工作* /
包com.amazon.identity.auth.device.lwaapp;
import android.app.Activity;导入android.content.Intent;进口 android.os.Bundle;导入android.support.v7.app.AppCompatActivity; 导入android.util.Log;导入android.view.Gravity;进口 android.view.View;导入android.widget.Button;进口 android.widget.ImageView;导入android.widget.ProgressBar;进口 android.widget.TextView;导入android.widget.Toast;
导入com.amazon.identity.auth.device.AuthError;进口 com.amazon.identity.auth.device.api.Listener;进口 com.amazon.identity.auth.device.api.authorization.AuthCancellation; 进口 com.amazon.identity.auth.device.api.authorization.AuthorizationManager; 进口 com.amazon.identity.auth.device.api.authorization.AuthorizeListener; 进口 com.amazon.identity.auth.device.api.authorization.AuthorizeRequest; 进口 com.amazon.identity.auth.device.api.authorization.AuthorizeResult; 导入com.amazon.identity.auth.device.api.authorization.ProfileScope; 导入com.amazon.identity.auth.device.api.authorization.Scope;进口 com.amazon.identity.auth.device.api.authorization.User;进口 com.amazon.identity.auth.device.api.workflow.RequestContext;
公共类LoginWithAmazonActivity扩展了活动{
private static final String TAG = LoginWithAmazonActivity.class.getName(); private TextView mProfileText; private Button mLogoutButton; private ProgressBar mLogInProgress; private RequestContext requestContext; private boolean mIsLoggedIn; private View mLoginButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestContext = RequestContext.create(this); requestContext.registerListener(new AuthorizeListener() { @Override public void onSuccess(AuthorizeResult authorizeResult) { runOnUiThread(new Runnable() { @Override public void run() { // At this point we know the authorization completed, so remove the ability to return to the app to sign-in again setLoggingInState(true); } }); fetchUserProfile(); } @Override public void onError(AuthError authError) { Log.e(TAG, "AuthError during authorization", authError); runOnUiThread(new Runnable() { @Override public void run() { showAuthToast("Error during authorization. Please try again."); resetProfileView(); setLoggingInState(false); } }); } @Override public void onCancel(AuthCancellation authCancellation) { Log.e(TAG, "User cancelled authorization"); runOnUiThread(new Runnable() { @Override public void run() { showAuthToast("Authorization cancelled"); resetProfileView(); } }); } }); setContentView(R.layout.activity_main); initializeUI(); } @Override protected void onResume() { super.onResume(); requestContext.onResume(); } @Override protected void onStart() { super.onStart(); Scope[] scopes = {ProfileScope.profile(), ProfileScope.postalCode()}; AuthorizationManager.getToken(this, scopes, new Listener<AuthorizeResult, AuthError>() { @Override public void onSuccess(AuthorizeResult result) { if (result.getAccessToken() != null) { /* The user is signed in */ fetchUserProfile(); } else { } } @Override public void onError(AuthError ae) { /* The user is not signed in */ } }); } private void fetchUserProfile() { User.fetch(this, new Listener<User, AuthError>() { @Override public void onSuccess(User user) { final String name = user.getUserName(); final String email = user.getUserEmail(); final String account = user.getUserId(); final String zipCode = user.getUserPostalCode(); runOnUiThread(new Runnable() { @Override public void run() { updateProfileData(name, email, account, zipCode); } }); } @Override public void onError(AuthError ae) { runOnUiThread(new Runnable() { @Override public void run() { setLoggedOutState(); String errorMessage = "Error retrieving profile information.\nPlease log in again"; Toast errorToast = Toast.makeText(getApplicationContext(), errorMessage,
Toast.LENGTH_LONG); errorToast.setGravity(Gravity.CENTER,0,0); errorToast.show(); } }); } }); }
private void updateProfileData(String name, String email, String account, String zipCode) { StringBuilder profileBuilder = new StringBuilder(); profileBuilder.append(String.format("Welcome, %s!\n", name)); profileBuilder.append(String.format("Your email is %s\n", email)); profileBuilder.append(String.format("Your zipCode is %s\n", zipCode)); final String profile = profileBuilder.toString(); Log.d(TAG, "Profile Response: " + profile); runOnUiThread(new Runnable() { @Override public void run() { updateProfileView(profile); setLoggedInState(); } }); } private void initializeUI() { mLoginButton = findViewById(R.id.login_with_amazon); mLoginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AuthorizationManager.authorize( new AuthorizeRequest.Builder(requestContext) .addScopes(ProfileScope.profile(), ProfileScope.postalCode()) .build() ); } }); // Find the button with the logout ID and set up a click handler View logoutButton = findViewById(R.id.logout); logoutButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AuthorizationManager.signOut(getApplicationContext(), new
Listener(){ @Override 公共无效onSuccess(无效响应){ runOnUiThread(new Runnable(){ @Override 公共无效run(){ setLoggedOutState(); } }); }
@Override public void onError(AuthError authError) { Log.e(TAG, "Error clearing authorization state.", authError); } }); } }); String logoutText = getString(R.string.logout); mProfileText = (TextView) findViewById(R.id.profile_info); mLogoutButton = (Button) logoutButton; mLogoutButton.setText(logoutText); mLogInProgress = (ProgressBar) findViewById(R.id.log_in_progress); } private void updateProfileView(String profileInfo) { Log.d(TAG, "Updating profile view"); mProfileText.setText(profileInfo); } private void resetProfileView() { setLoggingInState(false); mProfileText.setText(getString(R.string.default_message)); } private void setLoggedInState() { mLoginButton.setVisibility(Button.GONE); setLoggedInButtonsVisibility(Button.VISIBLE); mIsLoggedIn = true; setLoggingInState(false); } private void setLoggedOutState() { mLoginButton.setVisibility(Button.VISIBLE); setLoggedInButtonsVisibility(Button.GONE); mIsLoggedIn = false; resetProfileView(); } private void setLoggedInButtonsVisibility(int visibility) { mLogoutButton.setVisibility(visibility); } private void setLoggingInState(final boolean loggingIn) { if (loggingIn) { mLoginButton.setVisibility(Button.GONE); setLoggedInButtonsVisibility(Button.GONE); mLogInProgress.setVisibility(ProgressBar.VISIBLE); mProfileText.setVisibility(TextView.GONE); } else { if (mIsLoggedIn) { setLoggedInButtonsVisibility(Button.VISIBLE); } else { mLoginButton.setVisibility(Button.VISIBLE); } mLogInProgress.setVisibility(ProgressBar.GONE); mProfileText.setVisibility(TextView.VISIBLE); } } private void showAuthToast(String authToastMessage) { Toast authToast = Toast.makeText(getApplicationContext(), authToastMessage, Toast.LENGTH_LONG); authToast.setGravity(Gravity.CENTER, 0, 0); authToast.show(); } }
<ImageView android:id="@+id/imageView1" android:layout_width="150dp" android:layout_height="150dp" android:src="@drawable/aggressive_momemnts" android:clickable="true" android:focusable="true" android:contentDescription="@string/todo" /> <ImageView android:id="@+id/imageView2" android:layout_width="150dp" android:layout_height="150dp" android:layout_marginStart="30dp" android:clickable="true" android:focusable="true" android:visibility="gone" android:src="@drawable/best_moments" android:layout_marginLeft="30dp" android:contentDescription="@string/todo" /> <ImageView android:id="@+id/imageView3" android:layout_width="150dp" android:layout_height="150dp" android:layout_marginStart="30dp" android:layout_marginEnd="99dp" android:clickable="true" android:focusable="true" android:src="@drawable/best_player" android:layout_marginLeft="30dp" android:layout_marginRight="99dp" android:contentDescription="@string/todo" /> <ImageView android:id="@+id/imageView4" android:layout_width="150dp" android:layout_height="150dp" android:layout_marginStart="30dp" android:clickable="true" android:focusable="true" android:src="@drawable/coach" android:layout_marginLeft="30dp" android:contentDescription="@string/todo" /> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fragment"/> <ProgressBar android:id="@+id/log_in_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/Widget.ProgressBar.Inverse"/> </LinearLayout> <TextView android:id="@+id/profile_info" android:layout_width="310dp" android:layout_height="wrap_content" android:text="@string/default_message" android:textSize="15sp" android:gravity="center" android:layout_gravity="center"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="10dp" android:id="@+id/login_with_amazon" android:src="@color/login_button_image_state" android:background="@android:color/transparent" android:padding="0dp" android:contentDescription="@string/login_button_content_description"
/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:id="@+id/logout" android:text="@string/logout" android:visibility="gone" android:clickable="true" android:textColor="@color/logout_text_color_state" android:paddingBottom="10dp" android:layout_alignParentEnd="true" android:layout_marginEnd="10dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:id="@+id/return_to_app" android:text="@string/return_to_app" android:visibility="gone" android:clickable="true" android:textColor="@color/logout_text_color_state" android:paddingBottom="10dp" android:layout_alignParentEnd="true" android:layout_marginEnd="10dp" /> </RelativeLayout>
其中一项活动是我为所有视频单独制作的
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Activity1"> <VideoView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/v1" /> </RelativeLayout>
包com.amazon.identity.auth.device.lwaapp;
import android.app.Activity;导入android.net.Uri;进口 android.support.v7.app.AppCompatActivity;导入android.os.Bundle; 导入android.widget.VideoView;
公共类Activity1扩展了AppCompatActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_1); VideoView v1 = (VideoView) findViewById( R.id.v1 ); v1.setVideoURI( Uri.parse( "https//.mp4" ) ); v1.start(); v1.requestFocus(); v1.setKeepScreenOn( true ); } }