小编Laz*_*nja的帖子

使用blobstore与谷歌云端点和android

我正在使用eclipse插件开发一个app-engine连接的android项目.该应用程序的一个方面是允许用户Alpha将图片发送给用户Bravo.为此,我有以下设置:

用户Alpha发布:

  • 通过端点将图像发送到我的应用引擎服务器
  • 服务器将图像存储在blob存储中
  • 服务器在数据存储区中存储blobkey

用户Bravo获得:

  • 服务器从数据存储区获取blobkey
  • 服务器使用blob密钥获取图像
  • 服务器使用端点将图像发送到Android应用程序

这个设置需要两(2)分钟,从我的Android应用程序发送图像到我可以在blob疼痛中看到它.不用说这是完全不可接受的.

我的服务器通过以下代码以编程方式处理图像:

public static BlobKey toBlobstore(Blob imageData) throws FileNotFoundException, FinalizationException, LockException, IOException {
        if (null == imageData)
            return null;

        // Get a file service
        FileService fileService = FileServiceFactory.getFileService();

        // Create a new Blob file with mime-type "image/png"
        AppEngineFile file = fileService.createNewBlobFile("image/jpeg");// png

        // Open a channel to write to it
        boolean lock = true;
        FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);

        // This time we write to the channel directly
        writeChannel.write(ByteBuffer.wrap
            (imageData.getBytes()));

        // …
Run Code Online (Sandbox Code Playgroud)

google-app-engine android blobstore gae-eclipse-plugin google-cloud-endpoints

32
推荐指数
2
解决办法
9769
查看次数

Android http连接异常

我的Android 3.1模拟器有些问题.我无法获取我的XML文件.

protected InputStream getInputStream() {
    try {

        return feedUrl.openConnection().getInputStream();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误跟踪:

08-07 22:34:26.657: ERROR/AndroidRuntime(563): Caused by: android.os.NetworkOnMainThreadException
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at java.net.InetAddress.lookupHostByName(InetAddress.java:477)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:277)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at java.net.InetAddress.getAllByName(InetAddress.java:249)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
08-07 22:34:26.657: ERROR/AndroidRuntime(563):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): …
Run Code Online (Sandbox Code Playgroud)

android

18
推荐指数
2
解决办法
5万
查看次数

从浏览器链接启动Android应用程序

我尝试使用自己的方案从浏览器启动我的应用程序时遇到问题.
代码如下:
清单文件:

   <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" 
        android:exported="false">
        <intent-filter>

            <data  android:scheme="allplayer" />

            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

Html文件:

<html>
<head>
</head>
<body>
<a href="allplayer://site.com">Test link</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

如果我点击链接,我的应用程序将无法启动.我做了很多研究,但找不到答案.
如果我用http更改allplayer一切正常. 通过此链接,我了解到不建议您使用自己的方案.这是否意味着你自己的计划不起作用?这里 的人正在使用自己的方案,从他的反馈来看,它似乎正在发挥作用. 我错过了什么吗?




android android-intent

17
推荐指数
1
解决办法
2万
查看次数

android alarmmanager多个闹钟,一个覆盖另一个?

我搜索了帖子以寻找我的问题的答案,但没有找到解决我问题的任何东西.我正在尝试使用一个AlarmSettings类设置3个不同的警报.当我设置两个警报时,第二个警报优先于第一个警报,第一个警报永远不会消失.我认为这可能与我的未决意图有关...我对Android很新,非常感谢帮助.这是我设置警报的代码:

public void setAlarm() {

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, timepicker.getCurrentHour());
        calendar.set(Calendar.MINUTE, timepicker.getCurrentMinute());
        calendar.set(Calendar.SECOND, 0);

        if (timepicker.getCurrentHour() < calendar.get(Calendar.HOUR_OF_DAY)) { //if the alarm hour is less than the current hour
            calendar.add(Calendar.DATE, 1);                                     //then add 24 hours (1 DATE or Day)                 
        }

        //Create the text that we want to set the TextView alarmtime to in Main
        StringBuilder sb = new StringBuilder();
        if (timepicker.getCurrentHour() > 12) {
            sb.append(timepicker.getCurrentHour() - 12);
        } else {
            sb.append(timepicker.getCurrentHour());
        }
        sb.append(":");
        sb.append(timepicker.getCurrentMinute());
        sb.append(" ");
        if (timepicker.getCurrentHour() …
Run Code Online (Sandbox Code Playgroud)

java android

16
推荐指数
1
解决办法
9461
查看次数

java.io.filenotfoundexception在设备上打开失败的eacces(权限被拒绝)

以下代码包括从服务器下载文件并将其保存在存储中,当设备具有内部存储时可以正常工作.
但是当我使用没有内部存储的设备尝试它时,只有外部存储器,我得到以下异常.

java.io.filenotfoundexception打开失败的eacces(权限被拒绝)

public void downloadFile(String dlUrl, String dlName) {
    int count;

    HttpURLConnection con = null;
    InputStream is = null;
    FileOutputStream fos = null;

    try {
        URL url = new URL( dlUrl );
        con = (HttpURLConnection) url.openConnection();
        con.setDoInput(true);
        con.connect();

        is = url.openStream();
        String dir = Environment.getExternalStorageDirectory() + Util.DL_DIRECTORY;
        File file = new File( dir );
        if( !file.exists() ){
            file.mkdir();
        }

        Util.LOG_W(TAG, "Downloading: " + dlName + " ...");

        fos = new FileOutputStream(file + "/" +  dlName);
        byte data[] = new …
Run Code Online (Sandbox Code Playgroud)

android android-file android-permissions

16
推荐指数
4
解决办法
5万
查看次数

带有每日通知的 Android 应用

我正在制作一个 android 应用程序......我一直在尝试为一天中的特定时间设置的每日通知编写代码。起初,我真的认为这会是一件容易的事,几乎 Play 商店中的每个应用程序都有一个定时通知。但是在一遍遍搜索之后,我发现的所有方法和 Youtube 教程都对我不起作用。问题可能出在我身上,但我不知道是什么。我所需要的只是一个简单、优雅、易于理解的方法(如果有的话)。任何帮助将不胜感激。

我所做的所有搜索都让我走到了这一步……但仍然没有任何运气:

此方法在我的 MainActivity 类中,仅在第一次启动应用程序时调用以设置闹钟...

private void alarmMethod() {
    Intent myIntent = new Intent(this, NotifyService.class);
    AlarmManager alarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE);
    pendingIntent = PendingIntent.getService(this, 0, myIntent, 0);

    // Set the alarm to start at approximately 2:00 p.m.
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 14);

    // With setInexactRepeating(), you have to use one of the AlarmManager interval
    // constants--in this case, AlarmManager.INTERVAL_DAY.
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, pendingIntent);

    Toast.makeText(MainActivity.this, "Start Alarm", Toast.LENGTH_LONG)
            .show();
Run Code Online (Sandbox Code Playgroud)

这是我的 NotifyService 类:

package com.OHS.example; …
Run Code Online (Sandbox Code Playgroud)

android android-notifications

9
推荐指数
1
解决办法
8506
查看次数

库中的Android服务

我创建了一个带有服务的库,我希望能够在多个apk中绑定.

这是我的图书馆清单

<service class=".service.MyService" android:permission="com.wissen.permission.MY_SERVICE_PERMISSION">
<intent-filter>
<action android:value="com.wissen.testApp.service.MY_SERVICE" />
</intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)

这是我的apk清单

<uses-permission android:name="com.wissen.permission.MY_SERVICE_PERMISSION"></uses-permission>
Run Code Online (Sandbox Code Playgroud)

我当然将lib添加到apk.我继续找不到服务(警告).我究竟做错了什么.

我用这种方式绑定它

bindService(new Intent("com.wissen.testApp.service.MY_SERVICE"), conn, Context.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)

解决方案:
我为这些创建了aidl,现在工作正常.

service android

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

在android中自定义MediaPlayer类

我刚刚完成了一个项目,我使用webwiew进行视频播放.现在我被要求用自定义播放器替换webview部分.玩家应该能够处理HLS.

如果我使用VideoView和MediaController,我可以播放直播.但不幸的是,MediaController有自己的控件.我想要自己的控件,这就是我被卡住的地方.

到目前为止我试过:

  1. 要重新编写MediaController类并尝试更改布局.它没有工作,因为我无法清除由于依赖性导致的所有错误.
  2. 我尝试使用vidtry代码(http://github.com/commonsguy/vidtry)作为参考,但没有运气.
  3. 我试图构建一个扩展MediaController的类,但它也没有用.

我几乎在Stackoverflow上关于自定义媒体播放器的所有线程,但无法找到信息让我开始.
是否可以在不使用NDK的情况下创建自定义媒体播放器类?
如果有人知道如何创建自定义媒体播放器类,请帮助我.

java android

7
推荐指数
1
解决办法
1504
查看次数

如何在XML选择器中使用字体图标(font-awesome)

是否可以在选择器中使用字体图标而不是drawable?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/menu_home_press" android:state_pressed="true"></item>
    <item android:drawable="@drawable/menu_home"></item>
</selector>
Run Code Online (Sandbox Code Playgroud)

xml android font-awesome

6
推荐指数
1
解决办法
4372
查看次数

CardView 在滚动活动中不会折叠

我有滚动活动,其中有一个 CardView,其行为类似于此动画中所示的浮动操作按钮。

FAB 隐藏但 CardView 不隐藏

正如您所看到的,fab 正在淡入淡出(进出),但卡片视图的行为并非如此。
我的layout.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.rhcloud.arshadali.task.ScrollingActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_scrolling" />

    <android.support.v7.widget.CardView
        android:id="@+id/id_card"
        android:layout_width="match_parent"
        android:layout_height="46dp"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        android:foreground="@android:color/white"
        android:layout_margin="5dp">
        <ImageView
            android:id="@+id/app_googleplay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:maxWidth="30dp"
            android:maxHeight="30dp"
            android:layout_gravity="center_vertical"/>
        <TextView
            android:id="@+id/app_apk"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="com.javiersantos"
            android:fontFamily="sans-serif-thin"
            android:textColor="@android:color/black"
            android:gravity="center"/>
    </android.support.v7.widget.CardView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

有什么方法可以实现这一目标吗?

java android material-design android-cardview android-coordinatorlayout

6
推荐指数
1
解决办法
1231
查看次数