相关疑难解决方法(0)

Android有效地从输入流中读取

我正在为我正在制作的Android应用程序的网站发出HTTP get请求.

我正在使用DefaultHttpClient并使用HttpGet发出请求.我得到实体响应,从中获取一个InputStream对象来获取页面的html.

然后我循环完成回复,如下所示:

BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));
String x = "";
x = r.readLine();
String total = "";

while(x!= null){
total += x;
x = r.readLine();
}
Run Code Online (Sandbox Code Playgroud)

然而,这非常缓慢.

这效率低吗?我没有加载一个大的网页 - www.cokezone.co.uk所以文件大小不大.有一个更好的方法吗?

谢谢

安迪

java android input stream bufferedreader

147
推荐指数
5
解决办法
25万
查看次数

Android意图过滤器:将app与文件扩展名相关联

我有一个自定义文件类型/扩展名,我想与我的应用程序关联.

据我所知,数据元素是为此目的而制作的,但我无法使其正常工作. http://developer.android.com/guide/topics/manifest/data-element.html 根据文档和很多论坛帖子,它应该像这样工作:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:mimeType="application/pdf" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

好吧,它不起作用.我做错了什么?我只想声明自己的文件类型.

android intentfilter android-manifest

90
推荐指数
7
解决办法
7万
查看次数

针对特定文件扩展名的Android意图过滤器?

我希望能够从'net下载具有特定扩展名的文件,并将其传递给我的应用程序来处理它,但我无法找出intent过滤器.文件类型不包含在mimetypes中,我尝试使用

<data android:path="*.ext" />
Run Code Online (Sandbox Code Playgroud)

但我无法让它发挥作用.

android android-manifest android-intent

88
推荐指数
8
解决办法
7万
查看次数

在Android中注册新文件类型

我想在Android上编写简单的STL(几何数据文件)查看器应用程序,但我无法识别系统的格式.我在我的应用清单文件中写的是:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.EDIT" />
    <action android:name="android.intent.action.PICK" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
    <data android:pathPattern=".*\\.stl" />
    <data android:mimeType="application/sla" />
    <data android:host="*" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

但是目前我启动浏览器并下载一些示例STL文件,下载中断,我报告系统的数据文件类型未知.我没有真正的Android设备,所以只使用模拟器,为了开发我在MonoDroid上使用C#(但我不认为这是老实说的问题)

关于主题的任何想法?

先感谢您.

android file-type

21
推荐指数
3
解决办法
2万
查看次数

将您的应用设为默认应用以打开某个文件

如何让我的Android应用程序成为打开某种文件类型的默认应用程序?

我试图清除默认值,但选项是灰色的,有谁知道如何做到这一点?

我想用something.whateverandroid中的文件打开我的应用程序.

android

13
推荐指数
3
解决办法
4万
查看次数

Android接收共享文本文件但不共享文本内容

我正在制作一个能够上传单个或多个文件或文件夹的应用程序.intent-filter的定义如下:

    <activity android:name=".UploadActivity" android:launchMode="singleTop" android:theme="@style/Theme.Sherlock">
        <intent-filter android:label="@string/upload_intent">
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:mimeType="application/*" />
            <data android:mimeType="audio/*" />
            <data android:mimeType="image/*" />
            <data android:mimeType="media/*" />
            <data android:mimeType="multipart/*" />
            <data android:mimeType="text/*" />
            <data android:mimeType="video/*" />
        </intent-filter>
        <intent-filter android:label="@string/upload_intent">
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

这适用于Blackmoon文件资源管理器和Android 4.0.3图库.我的应用程序显示在"共享"菜单中.但是,它也会在浏览器中显示,当您长按URL并选择共享页面时.

当我将文本文件发送到我的应用程序时,我得到了这个:

getIntent().getAction() returns Intent.ACTION_SEND
getIntent().getType() returns "text/plain"
getIntent().getScheme() returns null
getIntent().getExtras().getString(Intent.EXTRA_STREAM) returns the filename
Run Code Online (Sandbox Code Playgroud)

但是,从浏览器发送URL会返回相同的内容减去 Intent.EXTRA_STREAM.我可以在代码中轻松检测到这一点并说"嘿,我无法上传文字!" 但我宁愿改变意图过滤器,以便它只在有EXTRA_STREAM时触发.有可能这样做吗?

(我尝试使用android:scheme但不会区分文件和共享的文本字符串,因为它们都是null ...)

android text share intentfilter extra

5
推荐指数
1
解决办法
1429
查看次数

Android - 从意图选择器中打开 txt 文件

通过单击某个按钮 - 创建选择 txt 文件的意图:

Intent intent = new Intent()
                    .setType("text/plain")
                    .setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select a TXT file"), 123);
Run Code Online (Sandbox Code Playgroud)

它工作正常 - 我从手机内存上的根文件夹中选择 txt 文件 --- /storage/emulated/0/kote.txt

但是当我尝试从中读取数据时,我得到 FileNotFoundException:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    if(requestCode==123 && resultCode==RESULT_OK) {
        Uri selectedfile_uri = intent.getData();
        Log.e("TAG7", "selectedfile_uri ---   " + selectedfile_uri );

        File myFile_test1 = new File(selectedfile_uri.getPath());
        Log.e("TAG7", myFile_test1.getPath() + "     .exists() "+myFile_test1.exists());

        File myFile_test2 = new File(selectedfile_uri.getEncodedPath());
        Log.e("TAG7", myFile_test2.getPath() + "     .exists() "+myFile_test2.exists());

        function_read_txt_file(myFile_test1); //returns FileNotFoundException …
Run Code Online (Sandbox Code Playgroud)

android filenotfoundexception android-intent onactivityresult

5
推荐指数
1
解决办法
3082
查看次数