file selection

This commit is contained in:
Page Asgardius 2022-11-04 14:00:56 -07:00
parent f332c0d011
commit 95d03ce8ee
4 changed files with 65 additions and 2 deletions

View file

@ -16,6 +16,7 @@ import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; import androidx.core.app.NotificationManagerCompat;
import android.Manifest; import android.Manifest;
import android.app.Activity;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.ContentResolver; import android.content.ContentResolver;
@ -34,6 +35,7 @@ import android.os.SystemClock;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -53,6 +55,7 @@ public class MainScreen extends AppCompatActivity {
HttpsURLConnection myConnection; HttpsURLConnection myConnection;
String myData, usertype; String myData, usertype;
URL endpoint; URL endpoint;
Intent intent;
boolean success; boolean success;
BufferedReader br; BufferedReader br;
StringBuilder sb; StringBuilder sb;
@ -62,11 +65,12 @@ public class MainScreen extends AppCompatActivity {
TextView id ,email, nacionalidad, nacimiento; TextView id ,email, nacionalidad, nacimiento;
Button logout, notification, edit, delete, viewlocation; Button logout, notification, edit, delete, viewlocation;
LinearLayout adminactions; LinearLayout adminactions;
Uri crashsound; Uri crashsound, fileuri;
TextView textView; TextView textView;
TelephonyManager telephonyManager; TelephonyManager telephonyManager;
private Location lastLocation; private Location lastLocation;
private LocationManager locManager; private LocationManager locManager;
ImageView profile;
private final LocationListener locListener = new LocationListener() { private final LocationListener locListener = new LocationListener() {
public void onLocationChanged(Location loc) { public void onLocationChanged(Location loc) {
@ -87,6 +91,7 @@ public class MainScreen extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_screen); setContentView(R.layout.activity_main_screen);
textView = findViewById(R.id.location); textView = findViewById(R.id.location);
profile = (ImageView) findViewById(R.id.userPicture);
/*telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); /*telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
if (ActivityCompat.checkSelfPermission(this, READ_SMS) != PackageManager.PERMISSION_GRANTED && if (ActivityCompat.checkSelfPermission(this, READ_SMS) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED &&
@ -186,6 +191,13 @@ public class MainScreen extends AppCompatActivity {
} }
}); });
login.start(); login.start();
profile.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
performFileSearch("Select file to upload");
}
});
notification.setOnClickListener(new View.OnClickListener(){ notification.setOnClickListener(new View.OnClickListener(){
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -430,4 +442,43 @@ public class MainScreen extends AppCompatActivity {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(Intent.createChooser(intent, getString(R.string.view_location_via))); startActivity(Intent.createChooser(intent, getString(R.string.view_location_via)));
} }
private void performFileSearch(String messageTitle) {
//uri = Uri.parse("content://com.android.externalstorage.documents/document/home");
intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
//intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
//intent.putExtra("android.provider.extra.INITIAL_URI", uri);
intent.setType("*/*");
((Activity) this).startActivityForResult(intent, 100);
}
@Override
public void onActivityResult(int requestCode, int resultCode, final Intent resultData) {
// The ACTION_OPEN_DOCUMENT intent was sent with the request code OPEN_DIRECTORY_REQUEST_CODE.
// If the request code seen here doesn't match, it's the response to some other intent,
// and the below code shouldn't run at all.
super.onActivityResult(requestCode, resultCode, resultData);
if (requestCode == 100) {
if (resultCode == Activity.RESULT_OK) {
// The document selected by the user won't be returned in the intent.
// Instead, a URI to that document will be contained in the return intent
// provided to this method as a parameter. Pull that uri using "resultData.getData()"
if (resultData != null && resultData.getData() != null) {
fileuri = resultData.getData();
System.out.println(fileuri.toString());
Toast.makeText(getApplicationContext(),fileuri.toString(), Toast.LENGTH_SHORT).show();
//System.out.println("File selected successfully");
//System.out.println("content://com.android.externalstorage.documents"+file.getPath());
} else {
Toast.makeText(MainScreen.this, getResources().getString(R.string.file_path_fail), Toast.LENGTH_SHORT).show();
finish();
}
} else {
//System.out.println("User cancelled file browsing {}");
finish();
}
}
}
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout 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" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -18,6 +19,16 @@
tools:ignore="MissingConstraints" tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp"> tools:layout_editor_absoluteX="20dp">
<ImageView
android:id="@+id/userPicture"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#000000"
app:srcCompat="@drawable/user"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="82dp" />
<Button <Button
android:id="@+id/notification" android:id="@+id/notification"
android:layout_width="0dp" android:layout_width="0dp"

View file

@ -25,7 +25,8 @@
<string name="openstreetmap" translatable="false">OpenStreetMap</string> <string name="openstreetmap" translatable="false">OpenStreetMap</string>
<string name="geouri" translatable="false">GeoURI</string> <string name="geouri" translatable="false">GeoURI</string>
<string name="decimal">Decimal</string> <string name="decimal">Decimal</string>
<string name="file_path_fail">No se encuentra el uri del archivo</string>
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="link_type">Link type</string> <string name="link_type">Link type</string>
</resources> </resources>