Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 可以在flex本机扩展中使用共享内部文件(例如,使用FileProvider)来共享其他应用程序_Android_Apache Flex_Android Intent_Adobe Native Extensions_Android Fileprovider - Fatal编程技术网

Android 可以在flex本机扩展中使用共享内部文件(例如,使用FileProvider)来共享其他应用程序

Android 可以在flex本机扩展中使用共享内部文件(例如,使用FileProvider)来共享其他应用程序,android,apache-flex,android-intent,adobe-native-extensions,android-fileprovider,Android,Apache Flex,Android Intent,Adobe Native Extensions,Android Fileprovider,作为AdobeFlex应用程序的一部分,我正在编写一个android本机扩展,允许我使用Flex代码生成的文件发送带有文件附件的电子邮件。但是,我不希望该文件是世界可读的,因为它可能包含敏感数据。因此,我想从我的应用程序的内部存储区域/缓存中发送文件。我正在使用Intent与其他应用程序(如Gmail)通信以发送电子邮件 在做了一些研究之后,我发现的功能应该完全符合我的要求。但是,静态方法FileProvider.getUriForFile()正在悄悄地使本机扩展失败/崩溃。本机扩展停止并返回n

作为AdobeFlex应用程序的一部分,我正在编写一个android本机扩展,允许我使用Flex代码生成的文件发送带有文件附件的电子邮件。但是,我不希望该文件是世界可读的,因为它可能包含敏感数据。因此,我想从我的应用程序的内部存储区域/缓存中发送文件。我正在使用Intent与其他应用程序(如Gmail)通信以发送电子邮件

在做了一些研究之后,我发现的功能应该完全符合我的要求。但是,静态方法FileProvider.getUriForFile()正在悄悄地使本机扩展失败/崩溃。本机扩展停止并返回null,没有错误,也没有来自LogCat的输出

如果我通过解析字符串手动创建Uri,Gmail会抱怨它无法将文件附加到电子邮件,并且发送的电子邮件没有附件

FREObject调用()中的代码:

//... (Deal with params from flex app) ...

//Setup Intent, and attach email data send from flex application:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, toArray);
intent.putExtra(Intent.EXTRA_CC, ccArray);
intent.putExtra(Intent.EXTRA_BCC, bccArray);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);

Log.d("emaildebug", filePath);
//Check we can read our email attachment from flex app
//filePath is a temporary cache location.
File appFile = new File(filePath);
if (appFile.exists() && appFile.canRead()) {
    Log.d("emaildebug", "file successfully read");
} else {
    return null;
}

//Get a handle on the android Context instead of FREContext. 
Context androidContext = (Context) context.getActivity();

//Get the location of the root files directory.
File attachPath = androidContext.getFilesDir();
File attachFile = new File(attachPath, "attachment.pdf");

//Copy file to root of files directory, so that our FileProvider can access it.
try {
    copyFileUsingChannel(appFile, attachFile);
} catch (Exception e) {
    Log.d("emaildebug", e.getMessage());
}

Log.d("emaildebug", "attachFile exists: " + attachFile.exists() );
Log.d("emaildebug", "attachFile path: " + attachFile.getAbsolutePath());

//This line will silently crash the native extension, instantly returning null, even in try catch.
//Uri contentUri = FileProvider.getUriForFile(androidContext, "com.example.androidextensiontest.provider", attachFile);

//Therefore manually create the Uri from a string.
Uri contentUri = Uri.parse("content://com.example.androidextensiontest.provider/files/attachment.pdf");

Log.d("emaildebug", "uri created");
Log.d("emaildebug", contentUri.toString());

//Grant permisions for all apps that can handle given intent
//Courtesy of: http://stackoverflow.com/questions/18249007/how-to-use-support-fileprovider-for-sharing-content-to-other-apps
List<ResolveInfo> resInfoList = androidContext.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    Log.d("emaildebug", "package: " + packageName);
    androidContext.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);

context.getActivity().startActivity(Intent.createChooser(intent, "Send mail using..."));
<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.example.androidextensiontest.provider"
    android:exported="false"
    android:grantUriPermissions="true" >
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/my_paths" />
</provider>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="files" path="." />
</paths>
11-01 10:58:09.971: D/emaildebug(17013): /data/data/air.com.example.MyAppName.debug/cache/FlashTmp.V17013/attachment.pdf
11-01 10:58:09.971: D/emaildebug(17013): file successfully read
11-01 10:58:09.991: D/emaildebug(17013): attachFile exists: true
11-01 10:58:09.991: D/emaildebug(17013): attachFile path: /data/data/air.com.example.MyAppName.debug/files/attachment.pdf
11-01 10:58:09.991: D/emaildebug(17013): uri created
11-01 10:58:09.991: D/emaildebug(17013): content://com.example.androidextensiontest.provider/files/attachment.pdf
11-01 10:58:09.991: D/emaildebug(17013): package: com.android.email
11-01 10:58:09.991: D/emaildebug(17013): package: com.google.android.gm
<provider 
    android:name="com.example.androidextensiontest.provider.MyContentProvider"
    android:authorities="com.example.androidextensiontest.provider">
</provider>
public class MyContentProvider extends ContentProvider implements PipeDataWriter<InputStream> {

public MyContentProvider() {
    // Never Output
    Log.d("emaildebug", "Constructor");
}

@Override
public boolean onCreate() {
    // Never Output
    Log.d("emaildebug", "OnCreate");
    return false;
}

//.. Rest of class
}
如果我尝试使用file://Uri从外部存储器发送文件,那么文件附件工作得很好。但是,正如前面提到的,文件附件可能包含敏感数据,因此我希望避免使用外部存储

我相信我看到的是,文件提供者不能在本机扩展中工作。我还尝试使用ContentProvider,但是没有调用构造函数和onCreate方法

内容提供者清单:

//... (Deal with params from flex app) ...

//Setup Intent, and attach email data send from flex application:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, toArray);
intent.putExtra(Intent.EXTRA_CC, ccArray);
intent.putExtra(Intent.EXTRA_BCC, bccArray);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);

Log.d("emaildebug", filePath);
//Check we can read our email attachment from flex app
//filePath is a temporary cache location.
File appFile = new File(filePath);
if (appFile.exists() && appFile.canRead()) {
    Log.d("emaildebug", "file successfully read");
} else {
    return null;
}

//Get a handle on the android Context instead of FREContext. 
Context androidContext = (Context) context.getActivity();

//Get the location of the root files directory.
File attachPath = androidContext.getFilesDir();
File attachFile = new File(attachPath, "attachment.pdf");

//Copy file to root of files directory, so that our FileProvider can access it.
try {
    copyFileUsingChannel(appFile, attachFile);
} catch (Exception e) {
    Log.d("emaildebug", e.getMessage());
}

Log.d("emaildebug", "attachFile exists: " + attachFile.exists() );
Log.d("emaildebug", "attachFile path: " + attachFile.getAbsolutePath());

//This line will silently crash the native extension, instantly returning null, even in try catch.
//Uri contentUri = FileProvider.getUriForFile(androidContext, "com.example.androidextensiontest.provider", attachFile);

//Therefore manually create the Uri from a string.
Uri contentUri = Uri.parse("content://com.example.androidextensiontest.provider/files/attachment.pdf");

Log.d("emaildebug", "uri created");
Log.d("emaildebug", contentUri.toString());

//Grant permisions for all apps that can handle given intent
//Courtesy of: http://stackoverflow.com/questions/18249007/how-to-use-support-fileprovider-for-sharing-content-to-other-apps
List<ResolveInfo> resInfoList = androidContext.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    Log.d("emaildebug", "package: " + packageName);
    androidContext.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);

context.getActivity().startActivity(Intent.createChooser(intent, "Send mail using..."));
<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.example.androidextensiontest.provider"
    android:exported="false"
    android:grantUriPermissions="true" >
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/my_paths" />
</provider>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="files" path="." />
</paths>
11-01 10:58:09.971: D/emaildebug(17013): /data/data/air.com.example.MyAppName.debug/cache/FlashTmp.V17013/attachment.pdf
11-01 10:58:09.971: D/emaildebug(17013): file successfully read
11-01 10:58:09.991: D/emaildebug(17013): attachFile exists: true
11-01 10:58:09.991: D/emaildebug(17013): attachFile path: /data/data/air.com.example.MyAppName.debug/files/attachment.pdf
11-01 10:58:09.991: D/emaildebug(17013): uri created
11-01 10:58:09.991: D/emaildebug(17013): content://com.example.androidextensiontest.provider/files/attachment.pdf
11-01 10:58:09.991: D/emaildebug(17013): package: com.android.email
11-01 10:58:09.991: D/emaildebug(17013): package: com.google.android.gm
<provider 
    android:name="com.example.androidextensiontest.provider.MyContentProvider"
    android:authorities="com.example.androidextensiontest.provider">
</provider>
public class MyContentProvider extends ContentProvider implements PipeDataWriter<InputStream> {

public MyContentProvider() {
    // Never Output
    Log.d("emaildebug", "Constructor");
}

@Override
public boolean onCreate() {
    // Never Output
    Log.d("emaildebug", "OnCreate");
    return false;
}

//.. Rest of class
}

MyContentProvider:

//... (Deal with params from flex app) ...

//Setup Intent, and attach email data send from flex application:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, toArray);
intent.putExtra(Intent.EXTRA_CC, ccArray);
intent.putExtra(Intent.EXTRA_BCC, bccArray);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, message);

Log.d("emaildebug", filePath);
//Check we can read our email attachment from flex app
//filePath is a temporary cache location.
File appFile = new File(filePath);
if (appFile.exists() && appFile.canRead()) {
    Log.d("emaildebug", "file successfully read");
} else {
    return null;
}

//Get a handle on the android Context instead of FREContext. 
Context androidContext = (Context) context.getActivity();

//Get the location of the root files directory.
File attachPath = androidContext.getFilesDir();
File attachFile = new File(attachPath, "attachment.pdf");

//Copy file to root of files directory, so that our FileProvider can access it.
try {
    copyFileUsingChannel(appFile, attachFile);
} catch (Exception e) {
    Log.d("emaildebug", e.getMessage());
}

Log.d("emaildebug", "attachFile exists: " + attachFile.exists() );
Log.d("emaildebug", "attachFile path: " + attachFile.getAbsolutePath());

//This line will silently crash the native extension, instantly returning null, even in try catch.
//Uri contentUri = FileProvider.getUriForFile(androidContext, "com.example.androidextensiontest.provider", attachFile);

//Therefore manually create the Uri from a string.
Uri contentUri = Uri.parse("content://com.example.androidextensiontest.provider/files/attachment.pdf");

Log.d("emaildebug", "uri created");
Log.d("emaildebug", contentUri.toString());

//Grant permisions for all apps that can handle given intent
//Courtesy of: http://stackoverflow.com/questions/18249007/how-to-use-support-fileprovider-for-sharing-content-to-other-apps
List<ResolveInfo> resInfoList = androidContext.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    Log.d("emaildebug", "package: " + packageName);
    androidContext.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);

context.getActivity().startActivity(Intent.createChooser(intent, "Send mail using..."));
<provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.example.androidextensiontest.provider"
    android:exported="false"
    android:grantUriPermissions="true" >
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/my_paths" />
</provider>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <files-path name="files" path="." />
</paths>
11-01 10:58:09.971: D/emaildebug(17013): /data/data/air.com.example.MyAppName.debug/cache/FlashTmp.V17013/attachment.pdf
11-01 10:58:09.971: D/emaildebug(17013): file successfully read
11-01 10:58:09.991: D/emaildebug(17013): attachFile exists: true
11-01 10:58:09.991: D/emaildebug(17013): attachFile path: /data/data/air.com.example.MyAppName.debug/files/attachment.pdf
11-01 10:58:09.991: D/emaildebug(17013): uri created
11-01 10:58:09.991: D/emaildebug(17013): content://com.example.androidextensiontest.provider/files/attachment.pdf
11-01 10:58:09.991: D/emaildebug(17013): package: com.android.email
11-01 10:58:09.991: D/emaildebug(17013): package: com.google.android.gm
<provider 
    android:name="com.example.androidextensiontest.provider.MyContentProvider"
    android:authorities="com.example.androidextensiontest.provider">
</provider>
public class MyContentProvider extends ContentProvider implements PipeDataWriter<InputStream> {

public MyContentProvider() {
    // Never Output
    Log.d("emaildebug", "Constructor");
}

@Override
public boolean onCreate() {
    // Never Output
    Log.d("emaildebug", "OnCreate");
    return false;
}

//.. Rest of class
}
公共类MyContentProvider扩展ContentProvider实现PipeDataWriter{
公共内容提供者(){
//从不输出
Log.d(“emaildebug”、“Constructor”);
}
@凌驾
公共布尔onCreate(){
//从不输出
Log.d(“emaildebug”、“OnCreate”);
返回false;
}
//…班上其他人
}
是我做错了什么,还是flex本机扩展不支持ContentProviders/FileProviders?或者,是否有其他解决方案可用于将位于内部存储器中的文件附加到电子邮件。我在SO和google上的搜索没有遇到过其他有类似经历的人,特别是在FileProvider.getUriForFile()方面。感谢您的帮助/意见

对不起,这是一堵文字墙,我想记录我到目前为止所做的一切,以及哪些有效,哪些无效


tldrContentProviders/文件提供程序是否在flex本机扩展中工作?是否有其他方法将内部文件作为电子邮件附件发送?

因此,我终于有时间回来看看这个问题。我学到了更多关于flex扩展构建过程和android开发的知识

我现在有了一个在AdobeFlex扩展中完全工作的文件提供程序

解决方案的第一部分是,对于flex扩展,忽略.ane中的清单。相反,必须在flashbuilder的appname-app.xml中的清单扩展下提供任何活动或提供程序:

<android>
    <colorDepth>16bit</colorDepth>
    <manifestAdditions><![CDATA[
        <manifest android:installLocation="auto">
            <application android:enabled="true"
                android:launchMode="singleInstance">
                <provider
                    android:name="android.support.v4.content.FileProvider"
                    android:authorities="com.example.androidextensiontest.files"
                    android:exported="false"
                    android:grantUriPermissions="true">
                    <meta-data
                        android:name="android.support.FILE_PROVIDER_PATHS"
                        android:resource="@xml/file_paths" />
                </provider>
            </application>
        </manifest>
    ]]></manifestAdditions>
</android>
建立一个正常的电子邮件。在此之后,my fileprovider开始工作,这意味着您可以使用此行生成fileprovider uri:

Uri contentUri = FileProvider.getUriForFile(androidContext, "com.example.androidextensiontest.files", attachFile);

您是如何设置platform.xml的?我无法让它找到我的paths.xml,它一直在退回到只支持缓存目录的默认值。