ImageView imageview = (ImageView)findViewById(R.id.image1);
imageview.setImageResource(imageIDs[position]);
String imageUrl = "file:///local/dir/page_1"; // http://example.com/image.jpg
WebView wv = (WebView) findViewById(R.id.yourwebview);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl(imageUrl);
That's part of my code.....
when i run this, on the emulator, the app runs but when i click on the icon to view the image via webview. it force closes. what am i doing not correctly.
Connect the debugger to your phone and look at where it is crashing. The clues you get there are (almost) priceless.
Sent from a distant planet with the aid of my towel.
Check manifest for all class , may be.
______________________________________
Sent from Xperia Arc
~Running DooMKernel[Rev : v10][FW:4.0.A.2.368]
~Dont forget to say thanks.Just click on the lower right corner thanks button.
Logcat is your friend.
Put display statements in your program too; they show up in logcat, for example:
System.out.println("I am here 1");
System.out.println("I am here 2");
And it's a good idea to test validity of views:
if(imageview != null) {
// TO DO...
}
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A
I'm looking at both a book and the beginning projects on developers.android.com and have a question. Google is utilizing the android:nClick to handle the click event which then points to a public method for execution....but the book is setting up click listeners by setting a View with the buttons ID and then executing the setOnClickListener. OnClickListenver has one method called OnClick which is then executed.
//book
public class MyGame extends Activity implements OnClickListener {
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
}
}
My question. Which is the better way to handle the Button Click? In looking at what google does in the XML, it seems a helluva lot cleaner....but curious on what the advantage is for the other way (and I cannot think of any). Search of the site didn't yield anything.
I dunno if the methods have advantages between them, however, I prefer the androidnClick method since the code looks clearer
You usually want to use the onClick method, as there is no benefit to implementing the OnClickListener (only more effort and possible performance loss).
If you want things like long clicks or other events, you will have to implement that (or define an inline listener), as there is no xml tag for those.
I think the OnClickListener is actually only there for consistency with these other classes
Requires Xposed Framework!
This module disables the desk dock feature on your device.
If anyone's wondering how this is useful, I made it for my Xperia Z1's magnetic cable, Sony sells the cable in a dock, so using the cable by itself puts the device in dock mode, which forces rotation regardless of my choice, and if the cable disconnects while my device is in car mode, it switches off car mode, which is kind of annoying while driving.
Compatibility:
Tested on my Z1, I coded it with 4.2 in mind, may or may not work on 4.1 / 4.3, trying it won't do any harm.
Source:
The mod is open source: https://github.com/MohammadAG/Xposed-Disable-Desk-Dock
You may not publish this on the Play Store or any other market.
Download:
http://dl-count.xposed.info/modules/com.mohammadag.disabledeskdock_v1_8f4e5c.apk
Changelog:
[1.0]
Initial release.
Support development:
If you found this mod useful, consider donating with PayPal.
This finally solved the annoying problem with my GT-P3110 (Galaxy Tab 2 7") with Go Launcher (pro). I use Go Launcher also on my tablet to stay consistent with my Xperia Ray - where it works flawlessly. On the GT-P3110 I have to adjust the environment with "App Settings" to be DPI 240 and font-size = 99% and then Go Launcher can be used perfectly for my taste.
The problem with Go Launcher and the GT-P3110 was that Go Launcher restarted every time I have set the tablet in the original dock or when I put it out of it. So any transition from or to desk-dock mode gave me a break until Go Launcher has reloaded all apps
Reporting the problem to Go Development team (twice actually) has not revealed a solution over months - but your module did it - thanks!
Exactly what I've been looking for!
I ran into the problem of some apps closing down due to dock mode, but this seems to be not a problem anymore.
Tried this on my droid maxx xt1080m. It's still bringing up car dock.
My issue is walking around with my phone stacked on top of my tablet in my hand. I guess I could freeze car mode. Any ideas?
Well this made my day thanks! working for me on omnirom 4.4.4 xperia z c6603
finally find a way to disable the auto rotation! thanks a lot for this
finally the solution. everytime i dock the S4, the currently running app closes and needs to be started again. CM11 btw.
Full Uninstall help
I know by myself it's kind of a stange question but, since I'm facing a very courious issue, I'm here to ask if there's any suggetion on how to full disble and remove this module.
I have the phone going into a sort of bootloop when swithced off (only way to recover is "power + vol up" long press combo).
And this is one of the last modifications I made, plus this happens only when I connect the magnetic cable.
Thank you all for your support.
Mr Mohammad sir. Is there any chance this module could be edited to block the detection of the pins in the USB connector that starts car mode? I have googled and googled and have come to the conclusion that on the M8 and its predecessors have faulty USB ports and are prone to collecting dust and/or just being faulty. It is extremely annoying flipping on and out of car mode when have never used and will never use car mode.
bballer182
bballer182 said:
Mr Mohammad sir. Is there any chance this module could be edited to block the detection of the pins in the USB connector that starts car mode? I have googled and googled and have come to the conclusion that on the M8 and its predecessors have faulty USB ports and are prone to collecting dust and/or just being faulty. It is extremely annoying flipping on and out of car mode when have never used and will never use car mode.
Click to expand...
Click to collapse
bballer182
I have the same issue. I really hope MohammadAG can find a solution for us.
Working for me on Android 4.4.4 stock rom Xperia Z3.
and not working on Android 5.0.2 CM rom.
Is there any solution on Android LL (5.0.2)?
It's very useful tool but it can't run on Lollipop.
Thank you.
Same here, running stock 5.0.2 on D6503 where the module is activaded but dock mode is still active. Please adapt the module for LP
Thanks a lot
The developer doesn't look active on XDA anymore since february. Maybe another developer can look at source and adapt it to lollipop.
jassalmithu said:
The developer doesn't look active on XDA anymore since february. Maybe another developer can look at source and adapt it to lollipop.
Click to expand...
Click to collapse
I also mentioned him on twitter. Still no answer.
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
My DisableDock.java:
Code:
package com.mohammadag.disabledeskdock;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.getIntField;
import static de.robv.android.xposed.XposedHelpers.setIntField;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import android.content.IntentFilter;
import android.content.res.Configuration;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class DisableDock implements IXposedHookLoadPackage {
private UiModeManager mUiModeManager = null;
private boolean mIsInCarMode = false;
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("android"))
return;
findAndHookMethod("com.android.server.UiModeManagerService", lpparam.classLoader,
"isDeskDockState", int.class, XC_MethodReplacement.returnConstant(false));
Class<?> DockObserver = findClass("com.android.server.DockObserver", lpparam.classLoader);
XposedBridge.hookAllConstructors(DockObserver, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
mUiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
IntentFilter iF = new IntentFilter();
iF.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
iF.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(intent.getAction())) {
mIsInCarMode = true;
} else if (UiModeManager.ACTION_EXIT_CAR_MODE.equals(intent.getAction())) {
mIsInCarMode = false;
}
}
}, iF);
}
});
findAndHookMethod(DockObserver, "handleDockStateChange", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
int mActualDockState = getIntField(param.thisObject, "mActualDockState");
int mReportedDockState = getIntField(param.thisObject, "mReportedDockState");
int mPreviousDockState = getIntField(param.thisObject, "mPreviousDockState");
int newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
switch (mActualDockState) {
case Intent.EXTRA_DOCK_STATE_DESK:
case Intent.EXTRA_DOCK_STATE_HE_DESK:
case Intent.EXTRA_DOCK_STATE_LE_DESK:
default:
newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
break;
case Intent.EXTRA_DOCK_STATE_CAR:
newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
break;
}
if (mUiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR || mIsInCarMode) {
newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
setIntField(param.thisObject, "mActualDockState", newFakeState);
// Prevent sound playback
param.setResult(null);
}
String debugString = String.format("Act: %s Prv: %s Rep: %s Fak: %s Car: %s",
getStringFromDockState(mActualDockState), getStringFromDockState(mPreviousDockState),getStringFromDockState(mReportedDockState),
getStringFromDockState(newFakeState), String.valueOf(mIsInCarMode));
// Toast.makeText( context, debugString, Toast.LENGTH_LONG).show();
XposedBridge.log(debugString);
setIntField(param.thisObject, "mActualDockState", newFakeState);
setIntField(param.thisObject, "mReportedDockState", newFakeState);
}
});
}
private static String getStringFromDockState(int dockState) {
switch (dockState) {
case Intent.EXTRA_DOCK_STATE_DESK:
return "Intent.EXTRA_DOCK_STATE_DESK";
case Intent.EXTRA_DOCK_STATE_HE_DESK:
return "Intent.EXTRA_DOCK_STATE_HE_DESK";
case Intent.EXTRA_DOCK_STATE_LE_DESK:
return "Intent.EXTRA_DOCK_STATE_LE_DESK";
case Intent.EXTRA_DOCK_STATE_CAR:
return "Intent.EXTRA_DOCK_STATE_CAR";
case Intent.EXTRA_DOCK_STATE_UNDOCKED:
default:
return "Intent.EXTRA_DOCK_STATE_UNDOCKED";
}
}
}
NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
Thanks! Working on Z1 C6902 :good:
Can you also do some widgets like RecentCallWidget from KK?
NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
Thanks a lot man. I returned my Xperia Z Ultra and waiting for a Xperia Z3 to be delivered. Will test and let you know then. Cheers.
NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
Unfortunately, it doesn't work on my Z1 Compact D5503. Thanks nonetheless!
EDIT: all good now! For some reason, it installed on my SD card!
NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
It worked for me! Thank you very much!!!
I'm developing an augmentative communication application for use on Kindle Fire. I'm using Fire HD 6 as my test device. I'm working in Xamarin, C#.
I know there is a speech recognizer on the device as the microphone icon appears on the keyboard and I can use it to populate the search window. However, my andoid speech recognizer code is not working. I get the "recognizer not present" error. Here is the code that I'm working with:
public class VoiceRecognition : Activity
{
private static String TAG = "VoiceRecognition";
private const int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private ListView mList;
public Handler mHandler;
private Spinner mSupportedLanguageView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
mHandler = new Handler();
SetContentView(Resource.Layout.Main);
Button speakButton = FindViewById<Button>(Resource.Id.btnRecord);
// Check to see if a recognition activity is present
PackageManager pm = PackageManager;
IList<ResolveInfo> activities = pm.QueryIntentActivities(new Intent(RecognizerIntent.ActionRecognizeSpeech), 0);
if (activities.Count != 0)
speakButton.Click += speakButton_Click;
else
{
speakButton.Enabled = false;
speakButton.Text = "Recognizer not present";
}
}
Click to expand...
Click to collapse
This code is obviously not going to work, but I don't know where to go from here. How can I access the voice recognizer on this device?
Thanks!
I am making a wallpaper app which i was testing in my phone. I used Android 9 Api 28 for the testing purpose. My app has 2 buttons one to set wallpaper and other to set lockscreen wallpaper. My home wallpaper button is working just fine. But my lock screen isnt. First it was showing error when i wrote it. When i hovered over it, it said this feature is supported by API 24 and above so it was giving option to surround it with a if check. I clicked on it and it got it in the if check but error was gone but it wasnt working in my phone still. No logcat error as well. No crashes. I tried it on my brother's phone android 10 api 29. It worked fine. It was meant for api 24 and above but why its not working in api 28 but working in api 29. What should i change in the code to make it work?
What I have tried:
I tried the below mentioned code for the lock screen wallpaper. fl_iv in the code is a framelayout containing an imageView which is showcasing the wallpaper image.
val result: Bitmap = fl_iv.drawToBitmap()
val wallpaperManager = WallpaperManager.getInstance(this)
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
wallpaperManager.setBitmap(result, null, true, WallpaperManager.FLAG_LOCK)
}
} catch (ex: IOException) {
ex.printStackTrace()
}