add checkintent to main file

This commit is contained in:
Eudes Inácio
2023-10-27 16:21:15 +01:00
parent d7f80d7cc2
commit a0609e5ba2
7 changed files with 144 additions and 45 deletions
+15 -8
View File
@@ -14,13 +14,20 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" /> <data android:mimeType="image/*" />
<data android:mimeType="image/*" /> </intent-filter>
<data android:mimeType="application/*" /> <intent-filter>
<data android:mimeType="video/*" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter> </intent-filter>
</activity> </activity>
<provider android:authorities="${applicationId}.fileprovider" android:exported="false" <provider android:authorities="${applicationId}.fileprovider" android:exported="false"
@@ -32,4 +39,4 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest> </manifest>
+72 -32
View File
@@ -23,10 +23,11 @@ import { PermissionList } from '../models/permission/permissionList';
import { SendIntent } from "send-intent"; import { SendIntent } from "send-intent";
import { Plugins } from '@capacitor/core'; import { Plugins } from '@capacitor/core';
import { Filesystem } from '@capacitor/filesystem';
import { NewActionPage } from '../pages/publications/new-action/new-action.page'; import { NewActionPage } from '../pages/publications/new-action/new-action.page';
import { PublicationsPage } from '../pages/publications/publications.page'; import { PublicationsPage } from '../pages/publications/publications.page';
import { fetchData } from 'plugins/Echo'; import { fetchData } from 'plugins/Echo';
import { Encoding, Filesystem, FilesystemDirectory } from '@capacitor/filesystem';
const { App } = Plugins; const { App } = Plugins;
@@ -147,6 +148,8 @@ export class HomePage implements OnInit {
); );
}); */ }); */
/* this.checkSendIntentReceived(''); */
} }
goto(url) { goto(url) {
@@ -157,44 +160,52 @@ export class HomePage implements OnInit {
async checkSendIntentReceived() { async checkSendIntentReceived(result) {
try {
const result: any = await SendIntent.checkSendIntentReceived(); SendIntent.checkSendIntentReceived().then((result: any) => {
alert('shared')
if (result) { if (result) {
console.log('SendIntent received'); console.log('SendIntent received');
console.log('JSON RESULT', JSON.stringify(result)); console.log(JSON.stringify(result));
const modal = await this.modalController.create({
component: PublicationsPage,
componentProps: {
item: "item",
intent: JSON.stringify(result)
},
cssClass: 'new-action modal modal-desktop',
backdropDismiss: false
});
/* modal.onDidDismiss().then(() => {
this.getActions();
}); */
await modal.present();
} }
if (result.url) { if (result.url) {
console.log('SendIntent received URL'); let resultUrl = decodeURIComponent(result.url);
let resultUrl = decodeURIComponent(result.url); Filesystem.readFile({path: resultUrl})
Filesystem.readFile({ path: resultUrl })
.then((content) => { .then(async (content) => {
console.log('CONtent data', content.data);
const modal = await this.modalController.create({
component: PublicationsPage,
componentProps: {
item: "item",
intent: content.data
},
cssClass: 'new-action modal modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
SendIntent.finish();
});
await modal.present();
console.log(content.data);
}) })
.catch((err) => console.log('Erro filesystem', err)); .catch((err) => console.error(err));
} }
} catch (error) { }).catch(err => console.error(err));
console.error('error check intent', error);
}
} }
ngOnInit() { ngOnInit() {
if(window["sharedintend"]) {
this.router.navigateByUrl("/home/publication");
}
window["this.router"] = this.router
/* this.checkSendIntentReceived() */ /* this.checkSendIntentReceived() */
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
@@ -291,14 +302,27 @@ export class HomePage implements OnInit {
if (!this.platform.is('desktop')) { if (!this.platform.is('desktop')) {
App.addListener('appStateChange', ({ isActive }) => { App.addListener('appStateChange', ({ isActive }) => {
if (isActive) { if (isActive) {
/* this.checkSendIntentReceived("value") */
// The app is in the foreground. // The app is in the foreground.
fetchData() /* fetchData()
.then((value) => { .then((value) => {
console.log('fetchData was successful in file2.ts',value); console.log('fetchData was successful in file2.ts', value);
this.imageToBase64(value)
.then((base64Data) => {s
if (base64Data) {
// Use the base64 data as needed
console.log('Base64 data:', base64Data);
} else {
console.error('Base64 data is null');
}
});
if (value)
this.checkSendIntentReceived(value)
}) })
.catch((error) => { .catch((error) => {
console.error('Error in file2.ts:', error); console.error('Error in file2.ts:', error);
}); }); */
console.log('App is in the foreground'); console.log('App is in the foreground');
/* this.checkSendIntentReceived() */ /* this.checkSendIntentReceived() */
} else { } else {
@@ -311,6 +335,22 @@ export class HomePage implements OnInit {
} }
async imageToBase64(imageUri: string): Promise<string | null> {
try {
const result = await Filesystem.readFile({
path: imageUri,
directory: FilesystemDirectory.External, // Adjust the directory as needed
encoding: Encoding.UTF8,
});
// The result will contain the base64-encoded data
return result.data;
} catch (error) {
console.error('Error reading image:', error);
return null;
}
}
clearTabButtonSelection() { clearTabButtonSelection() {
this.tabButton.home = false; this.tabButton.home = false;
this.tabButton.agenda = false; this.tabButton.agenda = false;
@@ -21,7 +21,7 @@
<ion-label class="title font-25-em">Acções</ion-label> <ion-label class="title font-25-em">Acções</ion-label>
</div> </div>
<div class="div-icon"> <div *ngIf="!intent" class="div-icon">
<button *ngIf="p.userPermission([p.permissionList.Actions.create])" title="Adicionar nova ação presidencial" class="btn-no-color" (click)="AddPublicationFolder()"> <button *ngIf="p.userPermission([p.permissionList.Actions.create])" title="Adicionar nova ação presidencial" class="btn-no-color" (click)="AddPublicationFolder()">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " slot="icon-only" src='assets/images/icons-add.svg'></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'default' " slot="icon-only" src='assets/images/icons-add.svg'></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " slot="icon-only" src='assets/images/theme/gov/icons-add.svg'></ion-icon> <ion-icon *ngIf="ThemeService.currentTheme == 'gov' " slot="icon-only" src='assets/images/theme/gov/icons-add.svg'></ion-icon>
@@ -31,6 +31,12 @@
<ion-icon class=" font-45-em" src="assets/images/theme/gov/icon-reload.svg"></ion-icon> <ion-icon class=" font-45-em" src="assets/images/theme/gov/icon-reload.svg"></ion-icon>
</button> </button>
</div> </div>
<div *ngIf="intent" class="div-icon">
<button title="Atualizar" class="btn-no-color" (click)="close()">
<ion-icon class=" font-45-em" src="assets/images/icons-search-close.svg"></ion-icon>
</button>
</div>
</div> </div>
</div> </div>
@@ -132,6 +132,9 @@ export class PublicationsPage implements OnInit {
}, 250); }, 250);
} }
close() {
this.modalController.dismiss();
}
get windowInnerWidth(): number { get windowInnerWidth(): number {
return window.innerWidth return window.innerWidth
} }
+1 -1
View File
@@ -4,4 +4,4 @@ import { doneITProd } from './suport/doneIt'
import { DevDev } from './suport/dev' import { DevDev } from './suport/dev'
export const environment: Environment = oaprProd; export const environment: Environment = DevDev;
+1 -1
View File
@@ -4,4 +4,4 @@ import { doneITDev } from './suport/doneIt'
import { DevDev } from './suport/dev' import { DevDev } from './suport/dev'
export const environment: Environment = oaprDev export const environment: Environment = DevDev
+45 -2
View File
@@ -7,12 +7,13 @@ import { environment } from './environments/environment';
import { defineCustomElements } from '@ionic/pwa-elements/loader'; import { defineCustomElements } from '@ionic/pwa-elements/loader';
import "hammerjs"; // HAMMER TIME import "hammerjs"; // HAMMER TIME
import { SendIntent } from "send-intent";
import { Filesystem } from '@capacitor/filesystem';
if (environment.production) { if (environment.production) {
enableProdMode(); enableProdMode();
} }
/* Sentry.init( /* Sentry.init(
{ {
dsn: 'https://5b345a3ae70b4e4da463da65881b4aaa@o4504340905525248.ingest.sentry.io/4504345615794176', dsn: 'https://5b345a3ae70b4e4da463da65881b4aaa@o4504340905525248.ingest.sentry.io/4504345615794176',
@@ -46,5 +47,47 @@ platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err)); .catch(err => console.log(err));
// Call the element loader after the platform has been bootstrapped // Call the element loader after the platform has been bootstrapped
SendIntent.checkSendIntentReceived().then((result: any) => {
if (result) {
console.log('SendIntent received');
console.log(JSON.stringify(result));
}
if (result.url) {
let resultUrl = decodeURIComponent(result.url);
Filesystem.readFile({path: resultUrl})
.then(async (content) => {
/* const modal = await this.modalController.create({
component: PublicationsPage,
componentProps: {
item: "item",
intent: content.data
},
cssClass: 'new-action modal modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss().then(() => {
SendIntent.finish();
});
await modal.present();
*/
window["sharedintend"] = content.data
window["this.router"].navigateByUrl("/home/publication");
alert('shared')
console.log(content.data);
})
.catch((err) => console.error(err));
}
}).catch(err => console.error(err));
defineCustomElements(window); defineCustomElements(window);