System UI crashes while requesting USB access permission using USB host api
I was trying to access a usb device attached to an android M mobile using USB host api , the code looks like below :-
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private TextView tvPath;
private boolean permissionGranted=false;
private static final String ACTION_USB_PERMISSION =
"com.android.example.USB_PERMISSION";
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
}
permissionGranted=true;
} else {
Log.d(TAG, "permission denied for device " + device);
}
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvPath=findViewById(R.id.path);
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while(deviceIterator.hasNext()){
UsbDevice device = deviceIterator.next();
tvPath.setText(device.getDeviceName());
manager.requestPermission(device, permissionIntent); // system ui crashes here
}
}
}
It detects the usb device , but on requesting permission to access the device it crashes the system UI with the following exception :-
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.systemui/com.android.systemui.usb.UsbPermissionActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
at com.android.systemui.usb.UsbPermissionActivity.onCreate(UsbPermissionActivity.java:120)
at android.app.Activity.performCreate(Activity.java:6583)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2531)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2666)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5769)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
The manifest file looks like below:-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.filedemo">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">
</uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-feature android:name="android.hardware.usb.host"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
</activity>
</application>
</manifest>
According to documentation
If you want your application to be notified of an attached USB device, specify an and element pair for the android.hardware.usb.action.USB_DEVICE_ATTACHED intent in your main activity.
So I have not added any this intent filter as I am enumerating USB devices . I am unable find if I have done anything wrong ! Any help will be appreciated .
Is using USB host api the best way to access USB devices on android ?
See also questions close to this topic
-
I Build apk of my android project. Apk also build successfully. but when i try to install apk in my phone its not installing and showing error.?
This file does not have an app associated with it for performing this action. please install an app or, if one is already installed, create an association in the default apps setting page android studio build Apk this file does not have an app associated with it for performing this action. please install an app or, if one is already installed, create an association in the default apps setting page.
-
Get certain pixels from png file and return it as bitmap
I got a png image which contains all of different pictures i want to extract them separately.
public Image newImagePixel(String fileName, ImageFormat format,int x,int y,int w,int h){ bitmap = BitmapFactory.decodeStream(in, null, options); Bitmap map1 = Bitmap.createBitmap(w-x, h-y,bitmap.getConfig()); int [] allpixels = new int [ bitmap.getHeight()*bitmap.getWidth()]; bitmap.getPixels(allpixels, 0, bitmap.getWidth(), x,y,w,h); map1.setPixels(allpixels, 0, map1.getWidth(), 0,0,w-x, h-y); return new AndroidImage(map1, format); }
When i call the method :
Assets.example = g.newImagePixel("sheet.png", ImageFormat.ARGB4444,33,164,126,200);
I get the error on:
bitmap.getPixels(allpixels, 0, bitmap.getWidth(), x,y,w,h);
-
How to make sure that app signing passwords are not available if someone decompiles the apk?
Currently I sign the app in the following manner where keys are read from env in CI.
signingConfigs { release { storeFile file(System.getenv("ANDROID_KEYSTORE_PATH")) storePassword System.getenv("KEYSTORE_PASSWORD") keyAlias System.getenv("KEY_ALIAS") keyPassword System.getenv("KEY_PASSWORD") } } buildTypes { release { signingConfig signingConfigs.release manifestPlaceholders = [excludeSystemAlertWindowPermission: "true"] } }
But this method will make the passwords available if someone decompiles the apk.
Is there a way by which keys are only used during signing and then stripped from code and then uploaded to Play store?
Or if someone can point me to more secure ways of signing apk's?
-
StatusBar not accepting alpha in color I set
So there may be a bunch of similar-looking questions on here about setting one's
statusBar
color, but I have a slightly different question, which I haven't found a conclusive answer on yet after a few hours of looking...Basically, how can I set my
statusBar
to accept a color value I set it to which contains some level of alpha in it?- For instance, I want 90% opacity so it's just barely see-through, but also the color of my choice.
I've already tried methods in my theme, such as
<item name="android:statusBarColor">@color/grey_900_transparent</item>
grey_900_transparent
above is defined in my colors.xml as#E6222222
.
I've also tried setting it programmatically, but the result is the same: the status bar doesn't want to accept alpha values for slight transparency.
I've been messing around with setting
android:windowTranslucentStatus:true
, but that doesn't seem to allow any color once it's transparent, let alone any level of transparency other than full-blown 100% see-through.So what can I do to make my
statusBar
the same color and alpha as my toolbar below it (grey_900 with 90% opacity)?Thanks for any of your help!
- How to create a bottom navigation with center icon which is highlighted even if it is not selected or checked like the one mentioned below in android
-
PopUpWindow or Dialog it is not getting the style correctly at Activity
I am trying to have a
PopUpWindow
or aDialog
so when I click a button it will show. It is shown but the problem it is that not the liked design and it is not having a background like normalDialog
I want to have a at the bottom of activity aDialog
orPopup
so it will be matched parent and wrapped content or any height no problem. And I want to haveClickListener
do I need to write when thedialog
or thePopUpWindow
is shown or where ? Or is it better to create aFragment
and then only to call thatFragment
atActivity
Below are my images
1. Is the actual design
2. Like this must be shown.Below is my code.
BookmarkActivity.class
ivShareMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); PopupWindow pw = new PopupWindow( inflater.inflate(R.layout.dialog_fragment_share, null, false), WindowManager.LayoutParams.MATCH_PARENT, 600, true); pw.showAsDropDown(ivShareMenu); // The code below assumes that the root container has an id called 'main' } });
dialog_fragment_share.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" android:id="@+id/layoutWithSharing" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="8.0dip"> <LinearLayout android:id="@+id/layoutPrivateMode" android:background="@drawable/selector_right_round_white_btn" style="@style/DialogShareAdvLayout"> <ImageView android:id="@+id/ivIncognitoMenu" android:src="@drawable/menu_incognito_on" style="@style/DialogShareAdvIcon" /> <TextView android:layout_marginLeft="8.0dip" android:text="@string/WBVFontIncognito" style="@style/DialogShareAdvTv" /> </LinearLayout> <LinearLayout android:gravity="center" android:id="@+id/layoutNightMode" android:background="@drawable/selector_white_round_btn" android:layout_width="fill_parent" android:layout_marginLeft="12.0dip" android:layout_marginRight="12.0dip" android:layout_weight="1.0" style="@style/DialogShareAdvLayout"> <ImageView android:id="@+id/ivNightMode" android:src="@drawable/night_button" style="@style/DialogShareAdvIcon" /> <TextView android:ellipsize="end" android:id="@+id/tvNightMode" android:layout_marginLeft="8.0dip" android:text="@string/WBVNightModeNight" android:lines="1" style="@style/DialogShareAdvTv" /> </LinearLayout> <LinearLayout android:id="@+id/ivTextSearch" android:background="@drawable/selector_left_round_white_btn" style="@style/DialogShareAdvLayout"> <ImageView android:src="@drawable/ic_search_black_24dp" style="@style/DialogShareAdvIcon" /> <TextView android:layout_marginLeft="8.0dip" android:text="@string/WBVFindInPage" style="@style/DialogShareAdvTv" /> </LinearLayout> </LinearLayout> <LinearLayout android:orientation="vertical" android:background="@android:color/white" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="8.0dip" android:paddingRight="16.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="@dimen/share_layout_min_width"> <ImageView android:id="@+id/ivResetFont" android:background="@drawable/selector_gray_btn" android:paddingLeft="8.0dip" android:paddingRight="8.0dip" android:clickable="true" android:layout_width="42.0dip" android:layout_height="42.0dip" android:src="@drawable/font_icn" /> <TextView android:textSize="13.0sp" android:textColor="@android:color/black" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="2.0dip" android:text="@string/WBVFontSize" /> <SeekBar android:id="@+id/seekBarFont" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:layout_weight="1.0" /> <TextView android:textSize="14.0sp" android:textColor="@android:color/black" android:id="@+id/tvFontSize" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> <View style="@style/GrayDivider" /> <LinearLayout android:id="@+id/shareLayout" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/vgAddFavour" style="@style/DialogShareLayout.vertical"> <ImageView android:src="@drawable/action_add_favorites" style="@style/DialogShareImgViewShare.Big" /> <TextView android:text="@string/WBVAddToBookmarks" style="@style/DialogShareText.Big" /> </LinearLayout> <LinearLayout android:id="@+id/vgAddReadable" style="@style/DialogShareLayout.vertical"> <ImageView android:src="@drawable/action_add_readinglist" style="@style/DialogShareImgViewShare.Big" /> <TextView android:text="@string/WBVAddToReadingList" style="@style/DialogShareText.Big" /> </LinearLayout> <LinearLayout android:id="@+id/vgCopyLink" style="@style/DialogShareLayout.vertical"> <ImageView android:src="@drawable/action_copylink" style="@style/DialogShareImgViewShare.Big" /> <TextView android:text="@string/WBVCopyLink" style="@style/DialogShareText.Big" /> </LinearLayout> <LinearLayout android:id="@+id/vgShare" style="@style/DialogShareLayout.vertical"> <ImageView android:src="@drawable/action_share_url" style="@style/DialogShareImgViewShare.Big" android:visibility="visible"/> <TextView android:text="@string/WBVShare" style="@style/DialogShareText.Big" /> </LinearLayout> </LinearLayout> <View style="@style/GrayDivider" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="@dimen/share_layout_min_width"> <LinearLayout android:id="@+id/vgDownLoadList" android:paddingLeft="2.0dip" android:layout_weight="11.0" style="@style/DialogShareLayout.horizontal"> <ImageView android:src="@drawable/action_download_list" style="@style/DialogShareImgViewShare.Small" /> <TextView android:text="@string/WBVDownloadList" style="@style/DialogShareText.Small" /> </LinearLayout> <LinearLayout android:id="@+id/vgSettings" android:layout_weight="11.0" style="@style/DialogShareLayout.horizontal"> <ImageView android:paddingRight="4.0dip" android:src="@drawable/action_settings" style="@style/DialogShareImgViewShare.Small" /> <TextView android:text="@string/SVTitle" style="@style/DialogShareText.Small" /> </LinearLayout> <LinearLayout android:id="@+id/vgQuit" android:paddingRight="10.0dip" android:layout_weight="12.0" style="@style/DialogShareLayout.horizontal"> <ImageView android:src="@drawable/action_quit" style="@style/DialogShareImgViewShare.Small" /> <TextView android:text="@string/WBVQuit" style="@style/DialogShareText.Small" /> </LinearLayout> </LinearLayout> <View style="@style/GrayDivider" /> <Button android:id="@id/btnCancel" android:text="@string/WBVHideMenu" style="@style/DialogLoadingButton" /> </LinearLayout> </LinearLayout>
bookmark_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" style="@style/MainLayout"> <LinearLayout android:id="@+id/linBrowser" style="@style/BrowserLayout"> <FrameLayout android:id="@+id/frameLayoutSearch" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true"> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <WebView android:id="@+id/vpBrowsers" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.0" android:background="@color/downloadText" /> <ImageButton android:id="@+id/My_btn" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_marginRight="25dp" android:layout_marginBottom="60dip" android:background="@drawable/round_button" android:src="@drawable/ic_share_white_24dp" /> </RelativeLayout> <FrameLayout android:id="@+id/ivBackground" style="@style/ImageViewBlockWebView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone"> <FrameLayout android:id="@+id/backPanel" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/gray_alpha"> <LinearLayout android:id="@+id/layoutCopyPast" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="4.0dp" android:layout_marginTop="4.0dp" android:layout_marginRight="4.0dp" android:background="@android:color/transparent" android:orientation="horizontal"> <Button android:id="@+id/btnPaste" style="@style/CopyPastPanelButtons" android:text="@string/SearchPage_Panel_Paste" /> <View android:id="@+id/firstDivider" style="@style/CopyPastPanelDivider" /> <Button android:id="@+id/btnCopy" style="@style/CopyPastPanelButtons" android:text="@string/SearchPage_Panel_Copy" /> <View android:id="@+id/secondDivider" style="@style/CopyPastPanelDivider" /> <Button android:id="@+id/btnCut" style="@style/CopyPastPanelButtons" android:text="@string/SearchPage_Panel_Cut" /> </LinearLayout> <LinearLayout android:id="@+id/layoutExtension" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom|center|left" android:layout_marginLeft="16.0dp" android:layout_marginBottom="16.0dp" android:orientation="horizontal" /> <ImageButton android:id="@+id/ibShare" style="@style/ImageButtonContext.Share" /> </FrameLayout> <FrameLayout android:id="@+id/trendMainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone"> <include layout="@layout/trend_frame" /> <LinearLayout android:id="@+id/layoutCopy" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="4.0dp" android:layout_marginTop="4.0dp" android:orientation="horizontal" android:visibility="gone"> <Button android:id="@+id/btnPasteTrend" style="@style/CopyPastPanelButtons" android:text="@string/SearchPage_Panel_Paste" /> <View style="@style/CopyPastPanelEmpty" /> <View style="@style/CopyPastPanelEmpty" /> </LinearLayout> </FrameLayout> </FrameLayout> <LinearLayout android:id="@+id/linLayoutBrowserPanel" android:layout_width="fill_parent" android:layout_height="@dimen/search_height" android:layout_gravity="bottom|center" android:orientation="vertical"> <View android:id="@+id/brPanelDivider" android:layout_width="fill_parent" android:layout_height="1.0px" android:background="@color/browserPanel" /> <LinearLayout android:id="@+id/searchTextLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@color/blue_title" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="2.0dp" android:paddingTop="2.0dp" android:paddingRight="2.0dp" android:paddingBottom="2.0dp" android:visibility="gone"> <FrameLayout android:id="@+id/ivCloseTextSearch" style="@style/ViewGroupButtonBrowser.Small"> <ImageView style="@style/SearchBtnNext" android:src="@drawable/selector_close_white_24dp" /> </FrameLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="2.0dp" android:layout_marginRight="2.0dp" android:layout_weight="1.0" android:background="@drawable/white_round_button" android:gravity="center_vertical" android:orientation="horizontal" android:paddingLeft="8.0dp" android:paddingTop="8.0dp" android:paddingRight="8.0dp" android:paddingBottom="8.0dp"> <EditText android:id="@+id/etTextSearch" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0" android:background="@android:color/transparent" android:hint="@string/WBVFindInPage" android:inputType="textNoSuggestions" android:privateImeOptions="nm" android:textColorHint="@color/gray" android:textSize="14.0sp" /> <TextView android:id="@+id/tvSearchCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="8.0dp" android:textColor="@color/gray" android:textSize="14.0sp" /> </LinearLayout> <FrameLayout android:id="@+id/ivPrevFind" style="@style/ViewGroupButtonBrowser.Small"> <ImageView style="@style/SearchBtnNext" android:src="@drawable/selector_keyboard_arrow_left_white_24dp" /> </FrameLayout> <FrameLayout android:id="@+id/ivNextFind" style="@style/ViewGroupButtonBrowser.Small"> <ImageView style="@style/SearchBtnNext" android:src="@drawable/selector_keyboard_arrow_next_white_24dp" /> </FrameLayout> </LinearLayout> <LinearLayout android:id="@+id/linLayoutBrowserPanelSettings" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:id="@+id/linLayoutBrowserBack" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/blue_title" android:orientation="horizontal"> <LinearLayout style="@style/SideLayoutBrowserPanel" android:layout_weight="6.0"> <FrameLayout android:id="@+id/imgBtnPreviousPage" style="@style/ViewGroupButtonBrowser.Side"> <ImageButton android:id="@+id/ivPrevPage" style="@style/ImageButtonBrowser" android:src="@drawable/ic_arrowleft_browser_tr" /> </FrameLayout> <FrameLayout android:id="@+id/imgBtnNextPage" style="@style/ViewGroupButtonBrowser.Side"> <ImageButton android:id="@+id/ivNextPage" style="@style/ImageButtonBrowser" android:src="@drawable/ic_arrowright_browser_tr" /> </FrameLayout> <FrameLayout android:id="@+id/imgBtnVisHistory" style="@style/ViewGroupButtonBrowser.Side"> <ImageButton style="@style/ImageButtonBrowser" android:src="@drawable/selector_visual_history" /> </FrameLayout> <FrameLayout android:id="@+id/imgBtnOpenReading" style="@style/ViewGroupButtonBrowser.Side"> <ImageButton style="@style/ImageButtonBrowser" android:src="@drawable/selector_bookmarks_browser" /> </FrameLayout> <FrameLayout android:id="@+id/imgBtnShare" style="@style/ViewGroupButtonBrowser.Side"> <ImageButton android:id="@+id/ivShareMenu" style="@style/ImageButtonBrowser" android:layout_marginTop="-2.0dp" android:paddingTop="2.0dp" android:paddingBottom="0.0dp" android:src="@drawable/selector_action_reading_list" /> </FrameLayout> </LinearLayout> <LinearLayout style="@style/SideLayoutBrowserPanel" android:layout_weight="11.0"> <LinearLayout android:id="@+id/imgBtnRead" style="@style/ViewGroupButtonBrowser.Side" android:layout_height="fill_parent" android:layout_weight="0.7" android:gravity="center"> <ImageButton android:id="@+id/imgBtnDef" style="@style/ImageButtonBrowser" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_marginRight="-12.0dp" android:scaleType="fitCenter" android:scaleX="@dimen/browser_switch_scale" android:scaleY="@dimen/browser_switch_scale" android:src="@drawable/toolbar_switch_mobilizer_off" /> <Switch android:id="@+id/switcher" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="center" android:scaleX="@dimen/browser_switch_scale" android:scaleY="@dimen/browser_switch_scale" android:switchMinWidth="20.0dp" android:textOff="" android:textOn="" android:thumb="@drawable/toolbar_switch_knob" android:track="@drawable/switch_background" /> <ImageButton android:id="@+id/imgBtnReadable" style="@style/ImageButtonBrowser" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_marginLeft="-12.0dp" android:scaleType="fitCenter" android:scaleX="@dimen/browser_switch_scale" android:scaleY="@dimen/browser_switch_scale" android:src="@drawable/toolbar_switch_mobilizer_on" /> </LinearLayout> <FrameLayout android:id="@+id/imgBtnFullScreen" style="@style/ViewGroupButtonBrowser.Side" android:layout_marginRight="5.0dp" android:paddingLeft="5.0dp"> <ImageButton style="@style/ImageButtonBrowser" android:src="@drawable/selector_fullscreen_on" /> </FrameLayout> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> <ImageButton android:id="@+id/imgBtnFullScreenOff" style="@style/ImgTransparentBtnBrowser" android:layout_gravity="bottom|center|right" android:layout_marginRight="10.0dp" android:src="@drawable/ic_fullscreen_off" /> <ImageButton android:id="@+id/imgBtnBack" style="@style/ImgTransparentBtnBrowser" android:layout_gravity="bottom|center|left" android:layout_marginLeft="10.0dp" android:src="@drawable/ic_fs_back" /> </FrameLayout> </LinearLayout> </LinearLayout>
-
Retrieving multiple items from DynamoDB for an Android application
I am working on an Android application, where I am storing current latitude and longitude of a device through GPS in DynamoDB. I have a separate activity where I am trying to fetch those lat-long values and show them on map in real time. I have created a method as below where I can fetch those lat-long values by specifying the primary key (let's say "vehicle_id") and show a marker for that location on map.
public void showMarker(final int primary_key) { new Thread(new Runnable() { int width = 50; int height = 50; BitmapDrawable bitmapDrawable = (BitmapDrawable) getResources().getDrawable(R.drawable.car); Bitmap b = bitmapDrawable.getBitmap(); Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false); Double fetchedLatitude; Double fetchedLongitude; @Override public void run() { VehicleLocationsDO readData = dynamoDBMapper.load(VehicleLocationsDO.class, primary_key); fetchedLatitude = readData.getLatitude(); fetchedLongitude = readData.getLongitude(); Log.e("Fetched Values::::::::", readData.toString() + " " + fetchedLatitude + " " + fetchedLongitude); runOnUiThread(new Runnable() {@Override public void run() { LatLng latLng = new LatLng(fetchedLatitude, fetchedLongitude); if (marker == null) { marker = mMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(smallMarker))); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(fetchedLatitude, fetchedLongitude), 16.5f)); } else { MarkerAnimation.animateMarkerToGB(marker, latLng, new LatLngInterpolator.Spherical()); // mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(fetchedLatitude,fetchedLongitude),16.5f)); } } }); } }).start(); }
I want to retrieve multiple (or all) items or rows present in DynamoDB table, so that I can show multiple markers on the map. How can I do that in my Android app?
-
Continue only if one OR another condition is met
I have an app that is basically a survey activity. Some questions require that one set of conditions OR another set be filled out before continuing.
When the user presses yes they get one set of EditText fields, if they press no they get a different set. Either choice enables the same continue button, but I need to check that just one of the two sets are filled out before continuing to the next activity.
bContinue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (myYesSection.isShown() && valueCombined.getText().toString().isEmpty()){ Toast.makeText(getApplicationContext(), "Please enter the combined score.", Toast.LENGTH_LONG).show(); } if (myNoSection.isShown() && valueOne.getText().toString().isEmpty() || valueTwo.getText().toString().isEmpty() || valueThree.getText().toString().isEmpty()){ Toast.makeText(getApplicationContext(), "Please fill out all fields.", Toast.LENGTH_LONG).show(); } else{ Intent toNextActivity = new Intent(getApplicationContext(), QuestionThree.class); startActivity(toNextActivity); } } });
In action, if the valueCombined is filled out, the toast comes up to "Please fill out all fields." and the user does not go to the next activity. If the valueCombined is filled out, I don't need the other fields filled out.
Filling out valueOne, valueTwo, and valueThree allows the next activity to be opened, but a toast to "Please enter the combined score."
What must I change so the button press requires only one of the two conditions to continue?
Update Working code Thanks @Andreas for the lesson. This checks exactly what I need, and does not pop the wrong toast if the wrong set of conditions are on display:
bContinue.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int count = 0; if (combinedValue.getText().toString().isEmpty()){ if (myYesSection.isShown()) { Toast.makeText(getApplicationContext(), "Please enter combined score.", Toast.LENGTH_LONG).show(); } count++; } if (valueOne.getText().toString().isEmpty() || valueTwo.getText().toString().isEmpty() || valueThree.getText().toString().isEmpty()){ if (myNoSection.isShown()) { Toast.makeText(getApplicationContext(), "Please fill out all fields.", Toast.LENGTH_LONG).show(); } count++; } if (count == 1){ Intent toNextActivity = new Intent(getApplicationContext(), QuestionThree.class); startActivity(toNextActivity); } }
-
My board design with a FTDI chip is a lot slower than a generic off the shelf RS232 to USB cable. Why is that the case?
Hello People of the internet,
The company I work at implement hardware that is using RS232 however the board uses a network cable instead of a standard DB9 RS232 connector. So to remove the custom cable they need to mufacture for customers I designed a simple RS232 to USB converter that has a USB on the one side and a network cable on the other. It uses the FT230X chip from FTDI and a standard serial to rs232 converter from ST. However after doing some tests it seems that when I run my configuration program it now takes significantly longer to send and receive data. A test showed with a standard RS232 to USB cable converter sending and receiving data took 6 seconds and with my new deign the same process took 16 seconds.
Anyone know how this can be? It's important to mention that every single byte sent requires an acknowledge byte to be sent back i.e. it's always 1 byte RX 1 byte TX repeat.
-
WiFi USB isn't recognized in VirtualBox - Parrot Security
i have a WiFi USB TL-WN821N,and i have internet in both host(windows 10) and the VirtualBox(Parrot Security),sometimes the USB shows up in the USB Setting under 'Syntek [0312]' which makes no sense,and sometimes it shows in the Menu in parrot o/s in USB section under 'crow USB 2.0' but if i try to check it it either gets checked but the terminal doesn't recognize it or it says the USB is busy,try again later,I'm confused...i have a networking project soon and i need to make this work i been on the internet for 3 days already. thanks for the help in advance!
-
How to add USB audio support into a android Kernel?
I have an RKMv5 which is a rooted RK3288 based android stick running 5.1.1. I would like to output and input audio using a usb audio adapter based on the C-Media HS 100B Chip. I believe this may require editing the kernel of the device to add driver support or prioritize over defaults. What is the most efficient way to go about this?
Please see this page for more information about the use case