2017-11-08 21:15:07 +01:00
|
|
|
package androidnative;
|
|
|
|
import android.content.Intent;
|
2018-04-11 21:50:43 +02:00
|
|
|
import android.util.Log;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.os.*;
|
|
|
|
import java.util.Map;
|
2019-01-09 22:03:16 +01:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.Manifest.permission;
|
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-11-08 21:15:07 +01:00
|
|
|
|
|
|
|
/** An alternative Activity class for Qt applicaiton.
|
|
|
|
|
|
|
|
Remarks: It is recommended but not a must to use this class as the main activity.
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class AndroidNativeActivity extends org.qtproject.qt5.android.bindings.QtActivity {
|
2019-01-09 22:03:16 +01:00
|
|
|
public static final int MY_PERMISSIONS_REQUEST_WRITE_STORAGE = 0x245285a8;
|
|
|
|
|
2017-11-08 21:15:07 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
SystemDispatcher.onActivityResult(requestCode,resultCode,data);
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:50:43 +02:00
|
|
|
|
2017-11-08 21:15:07 +01:00
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2019-01-09 22:03:16 +01:00
|
|
|
if (ContextCompat.checkSelfPermission(this,android.Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
// Permission is not granted
|
|
|
|
|
|
|
|
ActivityCompat.requestPermissions(this,new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},MY_PERMISSIONS_REQUEST_WRITE_STORAGE);
|
|
|
|
|
|
|
|
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
|
|
|
|
// app-defined int constant. The callback method gets the
|
|
|
|
// result of the request.
|
|
|
|
} else {
|
|
|
|
|
2018-10-01 21:17:54 +02:00
|
|
|
System.loadLibrary("friendiqa");
|
2018-04-22 21:12:40 +02:00
|
|
|
if((getIntent().getFlags() == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)) || (getIntent().getFlags() == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) || (getIntent().getFlags() == Intent.FLAG_ACTIVITY_NEW_TASK) || (getIntent().getFlags() == Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) || (getIntent().getFlags() == (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED))) {
|
2018-04-11 21:50:43 +02:00
|
|
|
SystemDispatcher.onActivityResume();
|
|
|
|
} else {
|
|
|
|
Intent data = getIntent();
|
2018-04-22 21:12:40 +02:00
|
|
|
if ((data!=null) && (data.getType() != null) && !(data.getBooleanExtra("used",false))){
|
|
|
|
String type = data.getType();
|
|
|
|
String[] parts = type.split("/");
|
|
|
|
String maintype= parts[0];
|
|
|
|
if (maintype.equals("text")){
|
|
|
|
SystemDispatcher.loadClass("androidnative.TextIntent");
|
|
|
|
SystemDispatcher.onActivityResult(0x245285a4,Activity.RESULT_OK,data);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
SystemDispatcher.loadClass("androidnative.ImagePicker");
|
|
|
|
SystemDispatcher.onActivityResult(0x245285a3,Activity.RESULT_OK,data);
|
|
|
|
}
|
2018-04-11 21:50:43 +02:00
|
|
|
getIntent().replaceExtras(new Bundle());
|
|
|
|
getIntent().setAction("");
|
|
|
|
getIntent().setData(null);
|
|
|
|
getIntent().setFlags(0);
|
|
|
|
getIntent().putExtra("used", true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
SystemDispatcher.onActivityResume();
|
|
|
|
}}
|
2017-11-08 21:15:07 +01:00
|
|
|
}
|
2019-01-09 22:03:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public void onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case MY_PERMISSIONS_REQUEST_WRITE_STORAGE: {
|
|
|
|
// If request is cancelled, the result arrays are empty.
|
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
SystemDispatcher.onActivityResume();
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-08 21:15:07 +01:00
|
|
|
|
2018-10-01 21:17:54 +02:00
|
|
|
protected void onNewIntent(Intent data) {
|
|
|
|
System.loadLibrary("friendiqa");
|
2018-04-11 21:50:43 +02:00
|
|
|
super.onNewIntent(data);
|
2018-04-22 21:12:40 +02:00
|
|
|
if ((data!=null) && (data.getType() != null) && !(data.getBooleanExtra("used",false))){
|
|
|
|
String type = data.getType();
|
|
|
|
String[] parts = type.split("/");
|
|
|
|
String maintype= parts[0];
|
|
|
|
if (maintype.equals("text")){
|
|
|
|
SystemDispatcher.loadClass("androidnative.TextIntent");
|
|
|
|
SystemDispatcher.onActivityResult(0x245285a4,Activity.RESULT_OK,data);
|
|
|
|
} else {
|
|
|
|
SystemDispatcher.loadClass("androidnative.ImagePicker");
|
|
|
|
SystemDispatcher.onActivityResult(0x245285a3,Activity.RESULT_OK,data);
|
|
|
|
}
|
|
|
|
getIntent().replaceExtras(new Bundle());
|
|
|
|
getIntent().setAction("");
|
|
|
|
getIntent().setData(null);
|
|
|
|
getIntent().setFlags(0);
|
|
|
|
getIntent().putExtra("used", true);
|
|
|
|
} else {
|
|
|
|
SystemDispatcher.onActivityResume();
|
|
|
|
}
|
2018-04-11 21:50:43 +02:00
|
|
|
|
|
|
|
} // onNewIntent
|
2017-11-08 21:15:07 +01:00
|
|
|
}
|
|
|
|
|