I've edited my Manifest code and my Activity code again to reflect appropriate intent filter requirements. However, I'm still getting the same results. I'm unable to read my external record, and I don't know why? When I scan my tags with the NFC Tools app, I can see everything as I would expect. My code produces a NullPointer when it attempts to "read" my array and I have no idea why?
--------------BEGIN MANIFEST--------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bmt_01">
<uses-permission android:name="android.permission.NFC"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:minSdkVersion="15"/> ///must be changed in build.gradle.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="vnd.android.nfc"
android:host="ext"
android:pathPrefix="/com.example.bmt_01:externaltype"
/>
</intent-filter>
</activity>
</application>
</manifest>
--------------END MANIFEST--------------------
--------------BEGIN MAIN ACTIVITY-------------
package com.example.bmt_01;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.nfc.tech.NdefFormatable;
import android.os.Parcelable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
String currentPayload = "";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected void onNewIntent(Intent intent)
{
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
//added the below lines, can delete if they don't work.
NdefRecord payload = ((NdefMessage)rawMsgs[0]).getRecords()[0];
String currentPayload = new String(payload.getPayload());
if (currentPayload.equals("1"))
{
Toast.makeText(this, "NFC Scan1: " + currentPayload, Toast.LENGTH_SHORT).show();
String url = "http://www.google.com";
Intent l = new Intent(Intent.ACTION_VIEW);
l.setData(Uri.parse(url));
startActivity(l);
}
///else
///{
if (currentPayload.equals("2"))
{
Toast.makeText(this, "NFC Scan2: " + currentPayload, Toast.LENGTH_SHORT).show();
String url = "http://www.yahoo.com";
Intent l = new Intent(Intent.ACTION_VIEW);
l.setData(Uri.parse(url));
startActivity(l);
}
///}
}
protected void onResume()
{
super.onResume();
Toast.makeText(this, "NFC Scan3: ", Toast.LENGTH_SHORT).show();
enableForegroundDispatchSystem();
}
#Override
protected void onPause()
{
super.onPause();
disableForegroundDispatchSystem();
}
private void enableForegroundDispatchSystem() {
Toast.makeText(this, "NFC Scan4: ", Toast.LENGTH_SHORT).show();
}
private void disableForegroundDispatchSystem() {
Toast.makeText(this, "NFC Scan5: ", Toast.LENGTH_SHORT).show();
onNewIntent(getIntent());
}
}
--------------END MAIN ACTIVITY---------------
UPDATE*
I should add that my AAR functions correctly. When I have the above app installed on my phone, but do not have it open, my AAR automatically opens and launches the application when I scan my test tag. So, I'm able to "see" the AAR in the array, but NOT the external record.
I'm still unable to read the external record on my tag. Obviously I'm doing something wrong, but I have no idea.
You mix togerthe message and record in your for loop. However there is only one NDEF message, but this message can hold several records. You must use only rawMsgs[0]. Then your for loop can iterate over all records of that message.
I've created a library which lets you parse NDEF records.
You're on the right track - wrapping binary paylod with using the external type - the library supports plugging in your own external type parser/record type(s), if you so prefer.
Related
I am making my first Android App, but my code produces a very strange behaviour i can't understand. And i used Google for three days now with no solution.
If i write in my AndroidManifest.xml a minSdkVersion other than "8", i can't connect to my FTP Server. Also if i use minSdkVersion "8" and targetSdkVersion other than "8". If i don't use minSdkVersion and targetSdkVersion everything works fine. In short:
min 8, target 8 = ok
min 8, no target = ok
no min, no target = ok
min 8, target 17 = failure
min 10, target 10 = failure
and so on...
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.package.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.examplepackage.Settings"></activity>
<activity android:name="com.schmidgroup.sgfax.Tools"></activity>
<activity android:name="com.schmidgroup.sgfax.MyFTP"></activity>
<activity android:name="com.schmidgroup.sgfax.Printing"></activity>
<activity android:name="com.schmidgroup.sgfax.Listings"></activity>
<activity android:name="com.schmidgroup.sgfax.Blue"></activity>
</application>
</manifest>
My MainActivity.Java:
package com.example.package;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.content.Intent;
import android.view.MenuItem;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Button for Bluetooth-Connection
Button verbinden = (Button) findViewById(R.id.button1);
verbinden.setText(R.string.select_device);
verbinden.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent start = new Intent(getApplicationContext(), Blue.class);
startActivity(start);
}
} );
}
}
My class Blue.Java does some Bluetooth stuff and then starts Listings.Java:
package com.example.package;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
public class Listings extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listings);
// Connect zum FTP-Server
MyFTP conn = new MyFTP();
conn.ftpConnect(host, user, pass, 21);
[... some more FTP stuff which don't work in cause of failing Ftp Connection...]
}
}
And finally the MyFTP.Java:
package com.example.package;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.net.ftp.*;
import android.content.Context;
import android.util.Log;
public class MyFTP {
private static void showServerReply(FTPClient FTPClient) {
String[] replies = FTPClient.getReplyStrings();
if (replies != null && replies.length > 0) {
for (String aReply : replies) {
System.out.println("SERVER: " + aReply);
}
}
}
//Now, declare a public FTP client object.
private static final String TAG = "MyFTPClient";
public FTPClient mFTPClient = null;
//Method to connect to FTP server:
public boolean ftpConnect(String host, String username,
String password, int port)
{
try {
mFTPClient = new FTPClient();
// connecting to the host
mFTPClient.connect(host, port);
showServerReply(mFTPClient);
Log.i(TAG, "Successful conntected to " + host);
// now check the reply code, if positive mean connection success
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
// login using username & password
boolean status = mFTPClient.login(username, password);
Log.i(TAG, "Succesful logged in to " + host);
/* Set File Transfer Mode
*
* To avoid corruption issue you must specified a correct
* transfer mode, such as ASCII_FILE_TYPE, BINARY_FILE_TYPE,
* EBCDIC_FILE_TYPE .etc. Here, I use BINARY_FILE_TYPE
* for transferring text, image, and compressed files.
*/
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
return status;
}
} catch(Exception e) {
Log.d(TAG, "Error: could not connect to host " + host );
}
return false;
}
[...and some more stuff...]
Can anyone see what i've doing wrong?
Thank you!
You shouldn't make any network operations on your main UI thread. watch this question about StrictMode Policy in Android 3.0 and higher.
I have this program that will try to monitor incoming SMS messages. But when I tried to run my program in the emulator and I tried to send a SMS message, it works. But when I installed my program in my phone, its not working.
What is the problem?
And I want to run the program at the backend as well. How to do that?
BTW, below are the whole codes for this sample app.
Thanks
RJ
import java.io.BufferedWriter;
import java.io.FileWriter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
public class MySMSMonitor extends BroadcastReceiver
{
private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
#Override
public void onReceive(Context context, Intent intent)
{
if(intent!=null &&
intent.getAction()!=null &&
ACTION.compareToIgnoreCase(intent.getAction())==0)
{
Object[]pduArray= (Object[]) intent.getExtras().get("pdus");
SmsMessage[] messages = new SmsMessage[pduArray.length];
for (int i = 0; i<pduArray.length; i++) {
messages[i] = SmsMessage.createFromPdu ((byte[])pduArray [i]);
}
Log.d("MySMSMonitor","SMS Message Received.");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="spy.Frandy.com"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="6" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".TelephonyDemo"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MySMSMonitor"> <intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/> </intent-filter>
</receiver>
</application>
</manifest>
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class TelephonyDemo extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button sendBtn = (Button)findViewById(R.id.sendSmsBtn);
sendBtn.setOnClickListener(new OnClickListener(){
#Override public void onClick(View view) {
EditText addrTxt = (EditText)TelephonyDemo.this.findViewById(R.id.addrEditText);
EditText msgTxt = (EditText)TelephonyDemo.this.findViewById(R.id.msgEditText);
try {
sendSmsMessage(
addrTxt.getText().toString(),msgTxt.getText().toString());
Toast.makeText(TelephonyDemo.this, "SMS Sent",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(TelephonyDemo.this, "Failed to send SMS", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}});
}
#Override
protected void onDestroy() {
super.onDestroy();
}
private void sendSmsMessage(String address,String message)throws Exception {
SmsManager smsMgr = SmsManager.getDefault();
smsMgr.sendTextMessage(address, null, message, null, null);
}
}
I would simply insist you to use ContentObserver and register content://sms Uri and fetch the type of the SMS using
cusor.getString(cusor.getColumnIndex("type")); // 1 = SMS Received
// 2 = SMS Sent
Further you can easily get the required data from the cursor that you fetched. Here is a blog for the same.
I'm going to assume with the little detail you have provided that the reason it works on a emulator and not your actual phone; may be another conflicting app intercepting the messages before they are broadcasted to your app.
try adding android:priority="1000" to your intent-filter of your receiver in your apps manifest
(a thousand being whatever number you feel necessary, could be higher if needed)
<intent-filter android:priority="1000" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
more info on - intent-filter priority
Try This:
<receiver android:name=".MySMSMonitor"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="2">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I have some trouble while try using broadcast receiver.
Target:
I have three app which will work next schema
1. First - is broadcast receiver app which will write some data to database when it will get a message.
2. Second - is app android which will send some intent with data which must be saved in database.
3. Third - is widget in home screen which will also send some intent with data which must be saved in database.
So, I make three app on eclipse.
1. BroadcastReceiverExample - broadcast receiver it has next files
package com.test.receive;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class SimpleReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "service get started action", Toast.LENGTH_LONG).show();
Log.e("START","START");
}
}
and the manifest file source
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:enabled="true" android:name=".receive.SimpleReceiver" android:exported="false">
<intent-filter android:priority="999">
<action android:name="com.test.SIMPLE_TEST_SERVICE"></action>
</intent-filter>
</receiver>
</application>
</manifest>
also I create App project (BroadcastSenderExample) in Eclipse
and it has file with next sender code
package com.test.sender;
import com.test.R;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class BroadcastSenderExample extends Activity {
public final static String ACTION="com.test.SIMPLE_TEST_SERVICE";
public final static String TYPE="type";
public final static int START=1;
public final static int STOP=0;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnStart=(Button)findViewById(R.id.btnStart);
btnStart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent bcIntent=new Intent(ACTION);
sendBroadcast(bcIntent);
}
});
btnEnd=(Button)findViewById(R.id.btnEnd);
btnEnd.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent bcIntent=new Intent(ACTION);
sendBroadcast(bcIntent);
}
});
}
private Button btnStart=null;
private Button btnEnd=null;
}
Then I install first app on device (and emulator try too), and install second app.
And then second app run intent call nothing happen.
What am I doing wrong?
I make two projects with next code
Project one wBRReceiver
File WBRReceiver.java
package com.x.brreceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class WBRReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent arg1) {
Log.i("THIS IS A TEST RECEIVER","THIS IS A TEST RECEIVER");
Toast.makeText(arg0, "this is a test receiver", Toast.LENGTH_LONG).show();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.brreceiver"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<receiver android:name="WBRReceiver">
<intent-filter>
<action android:name="com.x.START"></action>
</intent-filter>
</receiver>
</application>
</manifest>
And project two wBRSender
File WBRSenderActivity.java
package com.x.brsender;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class WBRSenderActivity extends Activity {
private String ACTION_NAME="com.x.START";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent brr=new Intent(ACTION_NAME);
//I can't use this
//brr.setClass(this, WBRReceiver.class);
//Because i just don't have this class in this case
sendBroadcast(brr);
}
}
And manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.brsender"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".WBRSenderActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And then I install first app onto emulator, and then run second app. And it works.
Did you look at the logcat output? There's a very good chance it tells you exactly what's wrong.
Without staring at your code too much, it seems that your manifest is broken. In your receiver, you state the android:name is ".receive.SimpleReceiver"... this value (when starting with a .) is not simply "the part that follows the Android package name) -- though it works out that way most of the time. In your case, your Android package is "com.test" however the package containing your receiver is "com.test.receive.SimpleReceiver" and its Java package is "com.test.receive". Try changing your android:name to "com.test.receive.SimpleReceiver".
I am creating an app for NFC where my first objective is to get the tag uid from the mifare tag.
When i press the tag button my activvity goes to second activity where i should be getting the tagID.
I am getting error of resource lookup. I know i am doing some major mistakes but could not find it.
Request you to please help.
This is my Meanifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.chetan.nfc"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"></uses-sdk>
<uses-feature android:required="true" android:name="android.hardware.nfc"></uses-feature>
<uses-permission android:name="android.permission.NFC"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true" android:enabled="true">
<activity android:name=".actOne"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="taginfo" android:label="#string/app_name" android:launchMode="standard">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:resource="#xml/nfc_tech_filter" android:name="#string/nfc_tech_filter"></meta-data>
</activity>
</application>
</manifest>
This is my activity one:
package com.chetan.nfc;
import java.util.Date;
import android.app.Activity;
import android.app.LauncherActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.nfc.NfcAdapter;
import android.nfc.tech.NdefFormatable;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class actOne extends Activity {
/** Called when the activity is first created. */
Button tag;
Intent i;
TextView tv;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tag=(Button)findViewById(R.id.Tag);
tv=(TextView)findViewById(R.id.textView1);
tag.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
i=new Intent(v.getContext(),taginfo.class);
startActivity(i);
//launchActivity();
}
});
}
}
This is my Activity 2
package com.chetan.nfc;
import java.io.IOException;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.MifareClassic;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
public class taginfo extends Activity{
TextView tv;
EditText tagIntent;
Log log;
IntentFilter mFilters[];
String mTechLists[][];
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.tagdata);
tagIntent=(EditText)findViewById(R.id.editText1);
tv=(TextView)findViewById(R.id.textView1);
tv.setText(getIntent().toString());
log.e("before get intetn", "");
readTag(getIntent());
}
public void readTag(Intent intent)
{
//tagIntent.setText(intent.getAction());
PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
NfcAdapter nfc_adapter=NfcAdapter.getDefaultAdapter(this);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
Tag myTag = (Tag) intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
tagIntent.setText("");
tagIntent.setText(tagId.toString());
}
}
If the error is about "I am getting error of resource lookup", is not NFC related.
With this code you're getting the UID of the Tag correctly
.
.
.
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Log.d(TAG, "UID: " + bin2hex(tag.getId()));
.
.
.
//To display the UID
static String bin2hex(byte[] data) {
return String.format("%0" + (data.length * 2) + "X", new BigInteger(1,data));
}
If you are simulating a tag detection from your activity 1, then add the appropriate extras. Else let the android nfc service generate the intent for TECH_DISCOVERED, when it detects the actual tag.
I made an app which is just working fine. But when i click on "cancel" or "ok" button when i run the program, instead of linking me to result.java, the simulator give me "The application has stopped unexpectedly please try again" Here's the code
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.database.CursorJoiner.Result;
import android.os.Bundle;
import android.view.View;
import android.widget.AutoCompleteTextView;
public class lib_main extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onAddClick (View botton){
AutoCompleteTextView title = (AutoCompleteTextView)findViewById(R.id.Title);
AutoCompleteTextView author = (AutoCompleteTextView)findViewById(R.id.Author);
AutoCompleteTextView isbn = (AutoCompleteTextView)findViewById(R.id.ISBN);
Intent intent = new Intent();
intent.setClass(this,Result.class);
intent.putExtra("Title", title.getText().toString());
intent.putExtra("Author", author.getText().toString());
intent.putExtra("ISBN", isbn.getText().toString());
startActivity(intent);
}
public void onCancelClick(View botton){
Intent intent = new Intent();
intent.setComponent(new ComponentName(this,Result.class));
intent.putExtra("Cancel","Cancel");
startActivity(intent);
}
}
this is Result.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Result extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView resultText=(TextView)findViewById(R.id.resultText);
Bundle bundle =getIntent().getExtras();
if(bundle.getString("Cancel")!= null)
{resultText.setText("operation cancel");}
else
{ String book =bundle.getString ("Title");
String title =bundle.getString ("Author");
String isbn =bundle.getString ("ISBN");
resultText.setText(
getString (R.string.resultOk)+""+book+""+ title+""+isbn);
}
}
}
the error log write "No command output when running:'am start-n com.Library.doc/com.Library.doc.lib_main-a android.intent.action.MAIN-c android.intent.category.LAUNCHER' in device emulator-5554"
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Library.doc"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".lib_main"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Result"
android:label="#string/result">
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
Can anyone help me with this problem?
Quick question, have you registered both Activities? If you only provide for one in your manifest file you're going to get this error every time you attempt to do something involving the unregistered activity.