SHOW:
|
|
- or go back to the newest paste.
1 | package com.mcv.android.myhce; | |
2 | ||
3 | ||
4 | import android.app.Activity; | |
5 | import android.content.Context; | |
6 | import android.content.Intent; | |
7 | import android.content.pm.FeatureInfo; | |
8 | import android.content.pm.PackageManager; | |
9 | import android.os.Bundle; | |
10 | import android.util.Log; | |
11 | import android.widget.ImageView; | |
12 | ||
13 | ||
14 | public class MainActivity extends Activity { | |
15 | private static final String TAG = MainActivity.class.getSimpleName(); | |
16 | ||
17 | ImageView imageView; | |
18 | ||
19 | @Override | |
20 | protected void onCreate(Bundle savedInstanceState) { | |
21 | // TODO Auto-generated method stub | |
22 | super.onCreate(savedInstanceState); | |
23 | setContentView(R.layout.activity_main); | |
24 | Log.i(TAG,"onCreate"); | |
25 | ||
26 | imageView = (ImageView)findViewById(R.id.imageView1); | |
27 | imageView.setImageResource(R.drawable.connectimg); | |
28 | ||
29 | //Per saber si el dispositiu acctepta la tecnologia | |
30 | if (isFeatureAvailable(this, PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { | |
31 | - | }else{ |
31 | + | |
32 | - | Log.i(TAG,"HCE no funciona"); |
32 | + | }else{ |
33 | - | } |
33 | + | Log.i(TAG,"HCE no funciona"); |
34 | } | |
35 | } | |
36 | ||
37 | @Override | |
38 | protected void onStart() { | |
39 | - | Intent intent = new Intent(this,MyHCEService.class); |
39 | + | |
40 | - | // Creem un nou Messenger per tornar la comunicació |
40 | + | Intent intent = new Intent(this,MyHCEService.class); |
41 | - | //Messenger messenger = new Messenger(handler); |
41 | + | |
42 | Log.i(TAG,"HCE funciona"); | |
43 | }else{ | |
44 | - | }else{ |
44 | + | Log.i(TAG,"HCE no funciona"); |
45 | - | Log.i(TAG,"HCE no funciona"); |
45 | + | } |
46 | - | } |
46 | + | |
47 | - | //intent.putExtra("MESSENGER", messenger); |
47 | + | |
48 | } | |
49 | ||
50 | public final static boolean isFeatureAvailable(Context context, String feature) { | |
51 | final PackageManager packageManager = context.getPackageManager(); | |
52 | final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures(); | |
53 | - | final PackageManager packageManager = context.getPackageManager(); |
53 | + | for (FeatureInfo f : featuresList) { |
54 | - | final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures(); |
54 | + | if (f.name != null && f.name.equals(feature)) { |
55 | - | for (FeatureInfo f : featuresList) { |
55 | + | return true; |
56 | - | if (f.name != null && f.name.equals(feature)) { |
56 | + | } |
57 | - | return true; |
57 | + | } |
58 | - | } |
58 | + | return false; |
59 | - | } |
59 | + | } |
60 | ||
61 | - | return false; |
61 | + | |
62 | - | } |
62 | + | protected void onDestroy() { |
63 | super.onDestroy(); | |
64 | - | @Override |
64 | + | Intent intentStop = new Intent(this,MyHCEService.class); |
65 | - | protected void onDestroy() { |
65 | + | |
66 | - | super.onDestroy(); |
66 | + | |
67 | - | Intent intentStop = new Intent(this,MyHCEService.class); |
67 | + | |
68 | } |