小编Ric*_*tri的帖子

Android应用中的Google钱包集成

我正在开发一个Android应用程序,我们可以通过信用卡等打开谷歌钱包付款.

我想在我的Android应用程序中集成谷歌钱包,点击按钮启动.

这是我的场景:

我必须选择一个是通过信用卡付款到另一个用户帐户,如汇款和购买任何项目的付款.

其次是通过网上银行付款.

我们可以使用谷歌钱包进行上述功能吗?

android android-pay

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

确定通知是否调用了Activity

我正在使用带有各种TabsActivitiy.从应用程序的不同部分创建通知,以告知用户某些内容已更改.当用户点击通知时,我现在设法调用活动.但是,如何在运行时或通过单击通知确定活动是以"正常"方式创建的?

(根据单击的通知,我想转发到另一个选项卡而不是显示主选项卡.)

Intent intent = new Intent(ctx, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent, 0);

        // TODO: Replace with .Build() for api >= 16
        Notification noti = new Notification.Builder(ctx)
                .setContentTitle("Notification"
                .setContentText(this.getName())
                .setSmallIcon(R.drawable.icon)
                .setContentIntent(pendingIntent)
                .setDefaults(
                        Notification.DEFAULT_SOUND
                                | Notification.DEFAULT_LIGHTS)
                .setAutoCancel(true)
                .getNotification();

        NotificationManager notificationManager = (NotificationManager) ctx
                .getSystemService(Context.NOTIFICATION_SERVICE);

        // Hide the notification after its selected
        notificationManager.notify(this.getId(), noti); 
Run Code Online (Sandbox Code Playgroud)

这成功调用了我的MainActivity.但是,当Activity被触发时,是否有一些方法被调用pendingIntent

想在主要活动中定义这样的东西:

onTriggeredByNotification(Notification noti){
     //determinte tab, depending on Notification.
}
Run Code Online (Sandbox Code Playgroud)

notifications android android-pendingintent

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

正确释放I/O资源

我想知道什么是释放文件资源/句柄的最佳/适当方式.

传统代码,

BufferredInputStream stream = null
try{
  ----
  stream = new BufferredInputStream(new FileInputStream());
  ----
} finally{
  if(stream != null){
    stream.close()
  }
Run Code Online (Sandbox Code Playgroud)

}

通过BufferredInputStream.close单独关闭来释放文件句柄,还是需要stream(i.e. FileInputStream.close())显式调用底层文件句柄.

P.S. Javadoc for [FilterOutputStream.close]method指定它也将显式关闭基础流.但其他流似乎在文档中没有这个.

[FilterOutputStream.close]: http://docs.oracle.com/javase/1.4.2/docs/api/java/io/FilterOutputStream.html#close%28%29
Run Code Online (Sandbox Code Playgroud)

请指教.提前致谢.

java io file

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

Android从库中选择显示内存错误的图像

我正在编写一个代码示例,我必须从库中选择代码正在工作的图像但是在从库中选择图像后,我在OnActivityResult中得到了OutOfMemoryError

我能够获得小图像,但是大图像会产生问题.

这是我的代码:

try{
                    Uri selectedImageUri = data.getData();
                    String[] filePathColumn = {MediaStore.Images.Media.DATA};
                    Cursor cursor = getContentResolver().query(selectedImageUri, filePathColumn, null, null, null);
                    cursor.moveToFirst();
                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                    String filePath = cursor.getString(columnIndex);
                    cursor.close();
                    bitmap = BitmapFactory.decodeFile(filePath);
                    _profileImage.setImageBitmap(bitmap);
                    _profileImage.setScaleType(ScaleType.FIT_XY);
                    Constant._addPhotoBitmap=bitmap;
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    Bitmap resizedbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
                    resizedbitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
                    byte [] _byteArray = baos.toByteArray();
                    String base64 = Base64.encodeToString(_byteArray,Base64.DEFAULT);
                    Constant._addPhotoBase64 = base64;
                }catch (OutOfMemoryError e) {
                    e.printStackTrace();
                    Constant.showAlertDialog(Constant.errorTitle,
                            "Image size is too large.Please upload small image.", …
Run Code Online (Sandbox Code Playgroud)

android image-gallery

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

无法连接到android上的蓝牙插座

我试图通过蓝牙从Android客户端发送消息到Mac OS X. 我在Mac OS X Snow Leopard上使用bluecove 2.0.1 Java蓝牙库.

服务器代码:

public class EchoServer2 {
private static final String UUID_STRING = "00001101-0000-1000-8000-00805F9B34FB"; // 32 hex digits
private static final String SERVICE_NAME = "echoserver";

private LocalDevice mLocalDevice;

public EchoServer2() {
    try {
        mLocalDevice = LocalDevice.getLocalDevice();
    } catch(IOException e) {
        System.err.print("Error connection to bluetooth");
    }   
}

public void start() throws IOException {
    StreamConnectionNotifier connectionNotifier =
        (StreamConnectionNotifier) Connector.open(
                "btspp://localhost:" + UUID_STRING +
                ";name=" + SERVICE_NAME + ";authenticate=false");

    System.out.println("Bluetooth Address: " + mLocalDevice.getBluetoothAddress());

    System.out.println("Waiting …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluecove

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

Android活动页面卷曲动画

我必须在活动事务中提供页面卷曲动画.我已经在图像上检查了android页面卷曲演示,但它不适用于活动.

以下是我们可以在图像上实现页面卷曲动画的链接,而不是在活动上:

https://github.com/openaphid/android-flip

http://devappandroid.com/android-beginner/page-curlturn-effect-android

我们怎样才能在活动中实现页面卷曲动画.

animation android android-activity

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

如何在JTextPane中获取输入文本的高度?

是否有可能获得输入文本的高度JTextPane?像素会很棒,但任何代表它的价值都可以.例如我输入了JTextPane这个:

Lorem Ipsum只是印刷和排版行业的虚拟文本.自16世纪以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一台未知的打印机采用了类型的厨房,并将其拼凑成一本类型的样本.它不仅存在了五个世纪,而且还延续了电子排版,基本保持不变.它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表格的推出而普及,最近还推出了包括Lorem Ipsum版本在内的Aldus PageMaker等桌面出版软件.

有没有办法获得它的长度值(不是它有多少行)?我需要这个,因为如果我在其中一行中输入图片,总高度会发生变化,我希望能够知道它的确切变化程度.的JTextPane,我用了一个StyledDocument,没有HTML.我做了一个SSCCE而不是图像,我使用了两种不同的字体大小来显示2的高度之间的差异JTextPanes.

public class Fonts extends JFrame {

    private JPanel contentPane;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Fonts frame = new Fonts();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public Fonts() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);

        JTextPane textPane …
Run Code Online (Sandbox Code Playgroud)

java swing jtextpane

3
推荐指数
1
解决办法
1103
查看次数

在Android上使用asynctask的Webview

我想这样做,进度对话框等待webview上的加载项.我怎么能做到哪个dialog.dismiss()事件取决于在webview上加载项目?

    public class asynctask extends  AsyncTask<Void, Void, Void> {

    private ProgressDialog dialog = new ProgressDialog(WebActivity.this);


  @Override
  protected void onPostExecute(Void result) {
      // TODO Auto-generated method stub
Run Code Online (Sandbox Code Playgroud)

在那里我该怎么办?

      dialog.dismiss();
Run Code Online (Sandbox Code Playgroud)

对话消失,无需等待

     }
 @Override 
 protected void onPreExecute() {
      // TODO Auto-generated method stub
        dialog.setMessage("Loading..Please wait.");

        dialog.show();
        dialog.setCanceledOnTouchOutside(false);
     }



@Override
protected Void doInBackground(Void... params) {
      // TODO Auto-generated method stub




      return null;
     }


 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.webview);

    webView = (WebView) findViewById(R.id.webView1);


    Bundle extras = …
Run Code Online (Sandbox Code Playgroud)

android loading webview android-webview android-asynctask

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

额外的东西似乎丢失了onResume()

我有一个Intent,通过一个很长的Extra从我的数据库中获取信息.它还设置了Activity通过a 的标题String Extra.

现在,当我第一次启动活动时,一切都显示出来.但是我有另一个Activity用于添加新的数据库项.问题是,当我按下后退按钮(操作栏中的徽标旁边有一个箭头)时,回到原来的Activity,似乎Extras已经消失,因为标题ListView是空的.

这是启动时显示ListView没有问题的Activity:

DaysActivity.java:

package com.gauvion.gfit;

import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class DaysActivity extends ListActivity {

    private DaysDataSource datasource;
    private SimpleCursorAdapter dataAdapter;
    private boolean isEditing = false;
    private Toast toast_deleted;
    private String[] columns = new String[] { MySQLiteHelper.COLUMN_NAME, MySQLiteHelper.COLUMN_DAY };
    private int[] to;
    private long routineDataID;
    private String routineDataName;

    @SuppressLint("ShowToast")
    @Override
    public void onCreate(Bundle savedInstanceState) { …
Run Code Online (Sandbox Code Playgroud)

android android-intent extra android-activity

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

在相对布局中查看中心

我有一个relativelayout包含一个progressbar和一个Loading textview..我需要progressbar和文本视图锥体在相对布局的中心.但它更多的是向右而不是在中心.下面是我的代码..

<RelativeLayout 
                android:layout_width="fill_parent"
                android:layout_height="26dp" 
                android:layout_gravity="bottom"
             android:background="@drawable/border">
                        <ProgressBar
                        style="?android:attr/progressBarStyleSmall"
                        android:id="@+id/progressBar"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_centerInParent="true"
                        android:layout_centerHorizontal="true" />


              <TextView 
                        android:id="@+id/TextViewProgress"
                        android:text="Loading"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="16dp"
                        android:layout_toRightOf="@+id/progressBar"
                        />
Run Code Online (Sandbox Code Playgroud)

android view relativelayout

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

Android card.io sdk显示此设备无法使用相机读取卡号

我正在开发一个Android应用程序,通过信用卡支付,我正在使用CARD.IO SDK for android.

我已将card.io sdk集成到我的代码中,但是当我启动应用程序时,它不允许我扫描任何卡.它显示一条消息,此设备无法使用相机读取卡号

这是我的代码:

包org.my.scanExample;

import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;
import org.my.scanExample.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MyScanActivity extends Activity
{
    // You MUST register with card.io to get an app token. Go to https://card.io/apps/new/
    private static final String MY_CARDIO_APP_TOKEN = "app_id";
    private View v;
    final String TAG = getClass().getName();

    private Button scanButton;
    private TextView resultTextView;

    private int MY_SCAN_REQUEST_CODE = 100; // arbitrary int

    /** Called when …
Run Code Online (Sandbox Code Playgroud)

android card.io

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