I have already checked the solutions mentioned here, but my app doesn't have most of those settings, including the manifest one. The ones I could try changing, I did. Still no luck.
Below is my code, and this is part of one of my tabs in TabHost. I am able to choose an image from gallery, but any statement after that isn't getting executed. No sysout statements are printed.
All my variables, except for the Button, are static. Could that be a problem?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
int permission = ActivityCompat.checkSelfPermission(messageActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
messageActivity.this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
101
);
}
databaseRef = FirebaseDatabase.getInstance().getReference();
imgStorageRef = FirebaseStorage.getInstance().getReference();
imgRef = databaseRef.child("images");
user = MainActivity.sendUser();
et = findViewById(R.id.msg);
et.setText("");
send = findViewById(R.id.sendBtn);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, PICK_IMAGE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
System.out.println("Entered onActivityResult");
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == PICK_IMAGE){
imageUri = data.getData();
try {
bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
bmp=bmp.copy(Bitmap.Config.ARGB_8888 , true);
encode();
System.out.println("Encoded");
upload();
System.out.println("Uploaded");
/*Code continues...*/
} catch (IOException e) {
e.printStackTrace();
}
}
}
This is the manifest file :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".messageActivity"/>
<activity android:name=".chatActivity" />
<activity android:name=".usersActivity" />
<activity android:name=".afterRegister" />
<activity android:name=".activityTwo" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
What's surprising is that, this exact same code works for me in all apps. But most of them are just 2 actvities long. Over here I've included it within a TabHost's activity, but based on my internet search, that shouldn't be a problem.