I have added the following code to my manifest file:
<activity
android:name="com.example.123.scan"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.scan" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Every time I start my app.
I could not get the intent of NFC that I need to proceed.
public void onResume() {
super.onResume();
Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
String sss=getIntent().getAction();
Toast.makeText(this,sss, Toast.LENGTH_SHORT).show();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(sss)) {
Toast.makeText(this, "NDEF", Toast.LENGTH_SHORT).show();
processIntent(getIntent());
}
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(sss)) {
Toast.makeText(this, "TAG", Toast.LENGTH_SHORT).show();
processIntent(getIntent());
}
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(sss)) {
Toast.makeText(this, "TECH", Toast.LENGTH_SHORT).show();
processIntent(getIntent());
}
}
Every time, it toasted android.intent.action.scan instead of the NFC intent.
What is the problem?
I created an Android Library for easy NFC on android, check it out it might be an easy solution - link
Related
I am facing problem to work with VoiceInteractor. Here it my Manifest part:
<activity android:name=".ProductSearchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.actions.SEARCH_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
</application>
And in the Activity,
#Override
public void onResume() {
super.onResume();
if (isVoiceInteraction()) {
getVoiceInteractor().submitRequest(new VoiceInteractor.PickOptionRequest(prompt, optionArr, null) {
#Override
public void onPickOptionResult(boolean finished, Option[] selections, Bundle result) {
if (finished && selections.length == 1) {
showResult(selections[0].getIndex());
}
}
#Override
public void onCancel() {
getActivity().finish();
}
});
}
}
Whenever I am starting my app using "OK Google, search Jackets on MYCART", it starts the application, but isVoiceInteraction() is always returning false and getVoiceInteractor() is always returning null even if I am starting the app by google search. Can anyone help me on that?
I'm trying to get all SD card statuses using the BroadcastReceiver, but the code isn't working correctly. The BroadcastReceiver does not give a comprehensive log after a change in SD card status, such as Turn on(off) USB Storage. Any ideas?
Manifest receiver actions:
<receiver android:name=".Broadcasts.BroadcastChangeSDCardStatus">
<intent-filter>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
<action android:name="android.intent.action.MEDIA_EJECT"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
</intent-filter>
</receiver>
OR this receiver defined:
<receiver android:name=".Broadcasts.BroadcastChangeSDCardStatus">
<intent-filter>
<action android:name="android.intent.action.ACTION_MEDIA_BAD_REMOVAL"/>
<action android:name="android.intent.action.ACTION_MEDIA_EJECT"/>
<action android:name="android.intent.action.ACTION_MEDIA_REMOVED"/>
<action android:name="android.intent.action.ACTION_MEDIA_UNMOUNTED"/>
</intent-filter>
</receiver>
BroadcastReceiver class to detect
public class BroadcastChangeSDCardStatus extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
boolean status = getStorageStatus();
Log.e("SDCARD Status: ", status + "");
}
public static boolean getStorageStatus() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return false;
} else {
return false;
}
}
}
<receiver android:name=".Broadcasts.BroadcastChangeSDCardStatus" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_REMOVED" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
</intent-filter>
Above code should work but as you said you already tried this so it looks like something is wrong with your receiver name .Your broadcast receivers is not registered.Give receiver name complete package name with class name correctly
You also need to set the android:scheme to "file" :
Do this by adding <data android:scheme="file" /> to your receiver like:
<receiver android:name=".Broadcasts.BroadcastChangeSDCardStatus">
<intent-filter>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
<action android:name="android.intent.action.MEDIA_EJECT"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>
Hope this helps you out
i'm after adding this permission resolve my problem now:
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
I have followed the following tutorial : http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/
But even after editing android manifest xml as told there I am getting the following error:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.google.zxing.client.android.SCAN pkg=com.google.zxing.client.android (has extras) }
My Code :
public class BarCodeScannerActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok;
ok=(Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Helllllllloooooooo");
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
System.out.println("onActivityResult________resultCode________ "+resultCode);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
System.out.println("contentsssssssssssssssssssssss" + contents);
Toast.makeText(getApplicationContext(),"Congratulations!!!... Product Code"+ contents + "On Scanning This Item..." ,Toast.LENGTH_LONG).show();
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
System.out.println("Formaattttttttttttttt " + format);
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
And mainfest file:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".BarCodeScannerActivity"
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.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CAMERA" />
Hi
Now i am getting a strange problem of attached screen shot once i updated my manifest as follows:
<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
![enter image description here][1]
<activity android:name=".ScanItemActivity"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
</activity>
I mean it says ""Sorry, the Android camera encountered a problem. You may need to
restart the device."
Nothing is there in logcat.
This is quite confused. You don't need to change your manifest at all if you are integrating by Intent, so remove anything you changed just for the integration.
The app is not installed, and you are not handling this properly. You must catch ActivityNotFoundException, or determine ahead of time that the app to handle the Intent is installed.
But, there is no need for any of this complexity. See http://code.google.com/p/zxing/wiki/ScanningViaIntent . You can use IntentIntegrator, which does all of this for you correctly, in a few lines of code.
After attempting to perform a search and failing, I am trying to launch an activity to display results from a search, but the app crashes when it gets to the point of the intent:
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
Intent mapIntent = new Intent(SearchActivity.this, MapResults.class);
mapIntent.putExtra("query", query);
startActivity(mapIntent);
}
here is the class it is supposed to launch:
public class MapResults extends MapActivity implements OnGestureListener, OnDoubleTapListener {
/** Called when the activity is first created. */
public String query;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
query = intent.getStringExtra("query");
Toast.makeText(this, "The query: " + query, Toast.LENGTH_LONG).show();
}
#Override
public boolean isRouteDisplayed() {
return false;
}
and the manifest file:
<activity android:name=".SplashScreen"
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=".Main">
<intent-filter>
<action android:name="com.example.android.test.Main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
<activity android:name=".SearchActivity"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
<meta-data android:name="android.app.searchable"
android:resource="#layout/searchable"/>
</activity>
<activity android:name=".MapResults">
<intent-filter>
<action android:name="com.example.android.test.MapResults"
android:label="#string/map_results_title"/>
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity" />
</activity>
I know that in the MapResults class it is not launching a map at the moment, its just displaying text, but this is just while I am trying to receive the data from the intent.
Any idea, cause I'm stuck!
In your MapResults class, the line :
Toast.makeText(this, "The query: " + query, Toast.LENGTH_LONG).show();
will create a NullPointerException as you are concatenating a null String. Your data member query is null at this point, you should have something like this :
query = intent.getStringExtra( "query" );
Toast.makeText(this, "The query: " + query, Toast.LENGTH_LONG).show();
Otherwise, your mechanism to transfer data using intents seems alright to me.
Regards,
Stéphane
The only problem, that I can see in the code is your intent variable is null, so it crashes on intent.getAction()
up: haven't noticed MapActivity code - if variable query is not initialized at the moment of Toast - yes, it's a second problem
<intent-filter>
<action android:name="com.example.android.test.Main" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
can you change DEFAULT to LAUNCHER?
just try it
Roger,
I see that you've been tinkering with camera intents. I'm having real trouble just getting
a simple app to tell me when the camera button has been pressed. Do you have some code to help me on my way.
Thanks.
David
In the manifest, you need to state you want to receive the intent for the camera button:
<receiver android:name="domain.namespace.CameraReceiver">
<intent-filter>
<action android:name="android.intent.action.CAMERA_BUTTON"/>
</intent-filter>
</receiver>
<activity android:name="domain.namespace.MyCameraActivity"
android:label="#string/app_name" android:screenOrientation="landscape" android:icon="#drawable/camera"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
In the receiver:
public void onReceive(Context context, Intent intent) {
KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
return;
}
//prevent the camera app from opening
abortBroadcast();
Intent i = new Intent(Intent.ACTION_MAIN);
i.setClass(context, MyCameraActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}