Skip to content

Commit

Permalink
update android app fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jatin-Mehra119 committed Nov 17, 2024
1 parent 921400e commit 9635abd
Show file tree
Hide file tree
Showing 41 changed files with 290 additions and 107 deletions.
11 changes: 0 additions & 11 deletions Android App/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Android App/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Android App/.idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions Android App/.idea/vcs.xml

This file was deleted.

6 changes: 3 additions & 3 deletions Android App/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ android {
compileSdk 34

defaultConfig {
applicationId "com.jatinmehra.pdfinsightpro"
applicationId 'com.jatinmehra.pdfinsightpro'
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
versionCode 3
versionName '1.2.0'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Binary file removed Android App/app/release/PDF-Insight-PRO.apk
Binary file not shown.
Binary file added Android App/app/release/app-release.apk
Binary file not shown.
Binary file modified Android App/app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified Android App/app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
4 changes: 2 additions & 2 deletions Android App/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"versionCode": 3,
"versionName": "1.2.0",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.jatinmehra.pdfinsightpro", appContext.getPackageName());
assertEquals("com.jatinmehra.pdf_insight_pro", appContext.getPackageName());
}
}
24 changes: 11 additions & 13 deletions Android App/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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

<!-- Storage Permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/ic_launcher_background"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PDFInsightPro"
android:theme="@style/Theme.PDFInsightPRO"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true">
android:exported="false" />
<activity
android:name=".SplashActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Binary file modified Android App/app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.jatinmehra.pdfinsightpro;

import android.annotation.SuppressLint;
import android.Manifest;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
Expand All @@ -16,73 +27,134 @@

public class MainActivity extends AppCompatActivity {

private WebView myweb;
private static final int FILE_CHOOSER_REQUEST_CODE = 1;

String websiteURL = "https://jatinmehra-pdf-insight-pro.hf.space";
private WebView webview;
private ValueCallback<Uri[]> filePathCallback;

// File chooser launcher
private final ActivityResultLauncher<Intent> fileChooserLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(), result -> {
if (filePathCallback != null) {
Uri[] resultUris = null;
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
resultUris = new Uri[]{result.getData().getData()};
}
filePathCallback.onReceiveValue(resultUris);
filePathCallback = null;
private final ActivityResultLauncher<Intent> fileChooserLauncher =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (filePathCallback == null) return;

Uri[] results = null;
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
results = new Uri[]{result.getData().getData()};
}
}
);
filePathCallback.onReceiveValue(results);
filePathCallback = null;
});

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize WebView
myweb = findViewById(R.id.myweb);
myweb.getSettings().setJavaScriptEnabled(true);

// Set WebViewClient to handle all URL navigation
myweb.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Handle mailto links
if (url.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse(url)); // Open the default email app
startActivity(intent);
return true;
}
return super.shouldOverrideUrlLoading(view, url);
if (!CheckNetwork.isInternetAvailable(this)) {
setContentView(R.layout.activity_main);

new AlertDialog.Builder(this)
.setTitle("No internet connection available")
.setMessage("Please Check your Mobile data or Wi-Fi network.")
.setPositiveButton("Ok", (dialog, which) -> finish())
.show();
} else {
webview = findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setDomStorageEnabled(true);
webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
webview.loadUrl(websiteURL);
webview.setWebViewClient(new WebViewClientDemo());
webview.setWebChromeClient(new WebChromeClientDemo());
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
Log.d("permission", "permission denied to WRITE_EXTERNAL_STORAGE - requesting it");
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
requestPermissions(permissions, 1);
}
}

webview.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file....");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File", Toast.LENGTH_SHORT).show();
});
}

// Set WebChromeClient to handle file chooser requests
myweb.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
// Store the callback and open the file picker
MainActivity.this.filePathCallback = filePathCallback;
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf"); // Ensure PDF files are picked
fileChooserLauncher.launch(intent);
return true;
private class WebViewClientDemo extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}

private class WebChromeClientDemo extends WebChromeClient {
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
if (MainActivity.this.filePathCallback != null) {
MainActivity.this.filePathCallback.onReceiveValue(null);
}
});
MainActivity.this.filePathCallback = filePathCallback;

// Load your Streamlit app URL
myweb.loadUrl("https://jatinmehra-pdf-insight-pro.hf.space");
Intent intent = fileChooserParams.createIntent();
try {
fileChooserLauncher.launch(intent);
} catch (Exception e) {
MainActivity.this.filePathCallback = null;
Toast.makeText(MainActivity.this, "File upload failed: " + e.getMessage(), Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
}

@Override
protected void onDestroy() {
super.onDestroy();
// Clean up the filePathCallback to avoid memory leaks
if (filePathCallback != null) {
filePathCallback.onReceiveValue(null);
filePathCallback = null;
public void onBackPressed() {
if (webview.isFocused() && webview.canGoBack()) {
webview.goBack();
} else {
new AlertDialog.Builder(this)
.setTitle("EXIT")
.setMessage("You want to close this app?")
.setPositiveButton("Yes", (dialog, which) -> finish())
.setNegativeButton("No", null)
.show();
}
}
}

class CheckNetwork {

private static final String TAG = CheckNetwork.class.getSimpleName();

public static boolean isInternetAvailable(Context context) {
NetworkInfo info = ((ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

if (info == null) {
Log.d(TAG, "no internet connection");
return false;
} else {
if (info.isConnected()) {
Log.d(TAG, " internet connection available...");
return true;
} else {
Log.d(TAG, " internet connection");
return true;
}
}
}
}
Loading

0 comments on commit 9635abd

Please sign in to comment.