Я абсолютно потрясен тем, что это произошло впервые. На самом деле, когда я устанавливаю apk из Android Studio, он запускается, но когда я генерирую подписанный apk и устанавливаю на том же мобильном устройстве, приложение вылетает, я вообще не могу понять. Это мой код.
public class Refer_And_Earn extends YouTubeBaseActivity {
private static final int RECOVERY_REQUEST = 1;
LinearLayout facebookShare, whatsappShare, instaShare, moreShare;
ImageView backArrow;
YouTubePlayerView youTubePlayerView;
YouTubePlayer.OnInitializedListener mOnInitialized;
ImageView showImageThumbnail;
TextView myTeamMemberET;
String VLink;
String msg, userId;
private static final String FACEBOOK_CHANNEL = "Facebook";
private static final String WHATSAPP_CHANNEL = "Whatsapp";
private static final String INSTAGRAM_CHANNEL = "Instagram";
private static final String FACEBOOK_PACKAGE_NAME = "com.facebook.katana";
private static final String WHATSAPP_PACKAGE_NAME = "com.whatsapp";
private static final String INSTAGRAM_PACKAGE_NAME = "com.instagram.android";
Uri imageUri;
SeekBar seekBar;
Bitmap bitmap;
Uri uri;
int maxcount = 100;
int setProgress = 0;
@Override
protected void onCreate(Bundle onSaveInstanceState) {
super.onCreate(onSaveInstanceState);
setContentView(R.layout.activity_refer__and__earn);
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this);
userId = sharedPreferences.getString("username", null);
try {
VLink = "1vwgrBjCXMY";
register();
getCountMyTeamMember();
backArrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
whatsappShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linkGeneratorToShare(WHATSAPP_CHANNEL, WHATSAPP_PACKAGE_NAME, imageUri);
}
});
facebookShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linkGeneratorToShare(FACEBOOK_CHANNEL, FACEBOOK_PACKAGE_NAME, imageUri);
}
});
instaShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linkGeneratorToShare(INSTAGRAM_CHANNEL, INSTAGRAM_PACKAGE_NAME, imageUri);
}
});
moreShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linkGeneratorToShare("without", "without", imageUri);
}
});
showImageThumbnail.setVisibility(View.VISIBLE);
youTubePlayerView.setVisibility(View.GONE);
showImageThumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showImageThumbnail.setVisibility(View.GONE);
youTubePlayerView.setVisibility(View.VISIBLE);
youTubePlayerView.initialize(getString(R.string.youyube_api_key), mOnInitialized);
}
});
try {
mOnInitialized = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo(VLink);
YouTubePlayer.PlayerStyle style = YouTubePlayer.PlayerStyle.DEFAULT;
youTubePlayer.setPlayerStyle(style);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
if (youTubeInitializationResult.isUserRecoverableError()) {
youTubeInitializationResult.getErrorDialog(Refer_And_Earn.this, RECOVERY_REQUEST).show();
} else {
String error = youTubeInitializationResult.toString();
}
}
};
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void getCountMyTeamMember() {
Call<MyCountModel> call = RetrofitClient.getInstance().getApi().myteamMember(userId);
call.enqueue(new Callback<MyCountModel>() {
@Override
public void onResponse(Call<MyCountModel> call, Response<MyCountModel> response) {
if (response.body() != null){
String statusCode = response.body().getStatuscode();
if (statusCode.equalsIgnoreCase("TXN")){
String msg = response.body().getMessage();
Data data = response.body().getData();
String totalMember = data.getTotalMember();
setMascotMoving(totalMember);
}else {
Toast.makeText(Refer_And_Earn.this, "No any one in your team", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(Refer_And_Earn.this, "No any one in your team", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<MyCountModel> call, Throwable t) {
Toast.makeText(Refer_And_Earn.this, "Due to Internet Error", Toast.LENGTH_SHORT).show();
}
});
}
private void setMascotMoving(String totalMember) {
try {
if (totalMember.equalsIgnoreCase("null")){
myTeamMemberET.setText("0");
}else {
myTeamMemberET.setText(totalMember);
}
int mascotCount = Integer.parseInt(totalMember);
if (mascotCount <= 100){
setProgress = (mascotCount * maxcount)/maxcount;
}else if (mascotCount >= 100){
setProgress = 100;
}
seekBar.setMax(0);
seekBar.setMax(maxcount);
seekBar.setProgress(setProgress);
seekBar.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return true;
}
});
}catch (Exception e){
e.printStackTrace();
}
}
private void linkGeneratorToShare(final String channel, final String pack, final Uri videoUri) {
try {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.refer_image);
saveBitMap(bitmap);
final ProgressDialog pDialog = new ProgressDialog(Refer_And_Earn.this);
pDialog.setTitle("Loading....");
pDialog.setMessage("Please wait while create your referral link to share");
pDialog.setCancelable(false);
pDialog.show();
Call<ReferResponse> call = RetrofitClient.getInstance().getApi().getReferLink(userId);
call.enqueue(new Callback<ReferResponse>() {
@Override
public void onResponse(Call<ReferResponse> call, Response<ReferResponse> response) {
String statuscode = response.body().getStatuscode();
if (statuscode.equals("TXN")) {
pDialog.dismiss();
String urlLink = response.body().getData();
if (channel.equalsIgnoreCase(WHATSAPP_CHANNEL)) {
String referUrl = urlLink.replaceAll(" ", "%20");
shareToApp(Refer_And_Earn.this, channel, pack, referUrl, videoUri);
} else if (channel.equalsIgnoreCase(INSTAGRAM_CHANNEL)) {
String referUrl = urlLink.replaceAll(" ", "%20");
shareToApp(Refer_And_Earn.this, channel, pack, referUrl, videoUri);
} else if (channel.equalsIgnoreCase(FACEBOOK_CHANNEL)) {
String referUrl = urlLink.replaceAll(" ", "%20");
shareToApp(Refer_And_Earn.this, channel, pack, referUrl, videoUri);
} else {
String referUrl = urlLink.replaceAll(" ", "%20");
openMoreOption(referUrl);
}
} else if (statuscode.equals("ERR")) {
pDialog.dismiss();
String mesg = response.body().getMessage();
AlertDialog.Builder alert = new AlertDialog.Builder(Refer_And_Earn.this);
alert.setTitle("Alert..!!!!");
alert.setMessage("Didn't create your referral link" + mesg);
alert.setCancelable(false);
alert.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
} else {
pDialog.dismiss();
String mesg = response.body().getMessage();
AlertDialog.Builder alert = new AlertDialog.Builder(Refer_And_Earn.this);
alert.setTitle("Alert..!!!!");
alert.setMessage("Didn't create your referral link" + mesg);
alert.setCancelable(false);
alert.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
@Override
public void onFailure(Call<ReferResponse> call, Throwable t) {
pDialog.dismiss();
}
});
}catch (Exception e){
e.printStackTrace();
}
}
private void saveBitMap(Bitmap finalBitmap) {
try {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Refer");
myDir.mkdirs();
String timeStamp = new SimpleDateFormat("yyyy").format(new Date());
String fname = "Refer_" + timeStamp + ".jpg";
File file = new File(myDir, fname);
uri = Uri.fromFile(file);
if (file.exists()) file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}catch (Exception e){
e.printStackTrace();
}
}
private void register() {
facebookShare = findViewById(R.id.facebookShare);
whatsappShare = findViewById(R.id.whatsappShare);
instaShare = findViewById(R.id.instaShare);
moreShare = findViewById(R.id.moreShare);
backArrow = findViewById(R.id.backArrow);
youTubePlayerView = findViewById(R.id.youtubePlay);
showImageThumbnail = findViewById(R.id.showImageThumbnail);
seekBar = findViewById(R.id.seekBar);
myTeamMemberET = findViewById(R.id.myTeamMemberET);
}
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(Refer_And_Earn.this, maindrawer.class);
startActivity(intent);
finish();
}
private void openMoreOption(String url) {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap, "Title", null);
Uri imageUri = Uri.parse(path);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setType("image/*");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
share.putExtra(android.content.Intent.EXTRA_STREAM, imageUri);
share.putExtra(Intent.EXTRA_TEXT, "I have found this application, a great medium to earn money. Download India's biggest B2B platform and work with 100+ Brands with link\n\n" + url);
startActivity(Intent.createChooser(share, "Share link!"));
} catch (Exception e) {
e.printStackTrace();
}
}
private void shareToApp(Context context, String channel, String packageName, String link, Uri videoUri) {
try {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (channel.equalsIgnoreCase(WHATSAPP_CHANNEL)) {
if (intent != null) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
Uri imageUri = Uri.parse(path);
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
waIntent.setType("image/*");
waIntent.setPackage(packageName);
waIntent.putExtra(Intent.EXTRA_TEXT, "I have found this application, a great medium to earn money. Download India's biggest B2B platform and work with 100+ Brands.\nclick here & install REDMIL:\n" + link);
waIntent.putExtra(android.content.Intent.EXTRA_STREAM, imageUri);
startActivity(waIntent);
} else {
Toast.makeText(context, "App " + packageName + " doesn't exist.", Toast.LENGTH_SHORT).show();
}
} else if (channel.equalsIgnoreCase(INSTAGRAM_CHANNEL) || channel.equalsIgnoreCase(FACEBOOK_CHANNEL)) {
if (intent != null) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
Uri imageUri = Uri.parse(path);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "I have found this application, a great medium to earn money. Download India's biggest B2B platform and work with 100+ Brands.\nclick here & install REDMIL:\n" + link);
if (channel.equalsIgnoreCase(INSTAGRAM_CHANNEL)) {
shareIntent.setPackage(INSTAGRAM_PACKAGE_NAME);
} else {
shareIntent.setPackage(FACEBOOK_PACKAGE_NAME);
}
startActivity(shareIntent);
} else {
Toast.makeText(context, "App " + packageName + " doesn't exist.", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
На самом деле я создаю приложение, в котором реферальная ссылка генерируется из API, которым я хочу поделиться через Whatsapp, Facebook, Instagram и Share Intent. Эти коды работают отлично, просто мой вопрос в том, что когда я создаю подписанный APK и устанавливаю его, приложение вылетает. Пожалуйста, помогите мне. Заранее спасибо