I've been stuck for a while now, trying to add some new functionality (day counter) to an existing apk (widget).
What I've done so far:
- unpacked the apk using apktool (using apktool d -d)
- start new project in netbeans with the specific source
- adding the java class to the existing package
The java code introduces some new parameters. I've added the parameters to different xml's. When I try to rebuild I keep getting the message:
cannot find symbol
symbol : variable layout
location: class fr.gdi.android.news.R
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
Can anyone give me a hint what to do?
some additional info. This is the class I'm trying to add:
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fr.gdi.android.news;
/**
*
* @author John
*/
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.widget.RemoteViews;
public class CountDays extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 60000);
}
private class MyTime extends TimerTask {
RemoteViews remoteViews;
AppWidgetManager appWidgetManager;
ComponentName thisWidget;
public MyTime(Context context, AppWidgetManager appWidgetManager) {
this.appWidgetManager = appWidgetManager;
remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
thisWidget = new ComponentName(context, CountDays.class);
}
@Override
public void run() {
Date date1 = new Date();
Calendar calendar = new GregorianCalendar(2010, 11,25);
long days = (((calendar.getTimeInMillis()- date1.getTime())/1000))/86400;
remoteViews.setTextViewText(R.id.days,""+ days);
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
}
}
1. Apktool does not support writing your code in Java right now. Whole story is here: http://code.google.com/p/android-apktool/issues/detail?id=88 . If you want to use Java, it's possible, but you will have to use a workaround. It's not that hard to implement, but requires you to understand, how Java/javac/bytecode works. Workaround is described in above link, if you don't want to read full story, instructions start at "My script is here".
2. I think (but maybe I'm wrong) that you misunderstand, how R references work. These R.drawables.xxx strings aren't magically converted to resIDs at compile or run time. To use them you have to generate proper R class using SDK. If you use Eclipse or Netbeans, you don't have to do that, cause IDE regenerates R.java file each time you modify something in resources, so you can use R references in your code whenever you want.
In app decoded by apktool you have to manage resIDs manually. It's caused by the fact, that if you want to use some resources in smali, you can't let SDK generate ids for these resources automatically, cause resIDs are stored in smali in numerical form, i.e. "const v0, 0x7f012345", not something like "const v0, R.drawables.xxx". So if you would add e.g. "const v0, 0x7f012345" line to smali and resIDs would be regenerated, your line might reference other resource, that you want.
Of course that's not the case if you want to use resources from Java code, but as I said, this feature isn't fully supported by apktool. Also I think it would be good to add possibility to generate resIDs automatically, even for smali code, cause managing resIDs manually is very inconvenient. But that's future.
For now if you want to add new resource and use it from your Java/smali code, you have to modify public.xml file, add that resource with next free resID and then use that resID from your code.
If you want to know more, you could read this: http://forum.xda-developers.com/showthread.php?p=7380557#post7380557
@Brut.all: Thanks for your extensive answer! I will read the stuff you mention and get back at it.
@Brut.all: I think you're right about me not understanding R.java completely. But what I understand from your story is this. When I want a new resource to use in a new class and to be used in the existing xml, I would have to do the following:
- add a line to the res/values/ids.xml, for example:
Code:
<item type="id" name="main">false</item>
- add a line to the res/values/public.xml, for example:
Code:
<public type="id" name="main" id="0x7f0a0034" />
- add a line to the R$id.java and R$layout.java (don't exactly know which one)
Code:
.field public static final main:I = 0x7f0a0034
first: is this correct? second: How can I refer to the newly added resource in my new class. R.layout.main doesn't work, R$layout.main doesn't work.
Code:
remoteViews = new RemoteViews(context.getPackageName(), R$layout.main);
john37 said:
- add a line to the res/values/ids.xml, for example:
Code:
<item type="id" name="main">false</item>
Click to expand...
Click to collapse
You don't have to do that. If you add new drawable, XML or @+id/something value, then it's ok.
john37 said:
- add a line to the res/values/public.xml, for example:
Code:
<public type="id" name="main" id="0x7f0a0034" />
Click to expand...
Click to collapse
Yes.
john37 said:
- add a line to the R$id.java and R$layout.java (don't exactly know which one)
Code:
.field public static final main:I = 0x7f0a0034
Click to expand...
Click to collapse
No ;-)
If you want to use these resources in smali, then you could use them as is, e.g.: "const v0, 0x7f0a0034".
If you want to use my workaround to work in Java, then you could do the same, as above, e.g.:
Code:
int id = 0x7f0a0034;
or you could do this cleaner and generate R class manually: remove all existing R*.java classes (they aren't used) and create single R.java file:
Code:
public final class R {
public static final class id {
public static final int main = 0x7f0a0034;
}
}
and then you could use it as "R.id.main" in your code.
But first you have to implement workaround to use any Java code.
@Brut.all: thanks again for your reply. I think I didn't understand your previous story fully. I am 'developing' on windows, so your workaround is going to be tricky. Do you know if anyone has ported your script to windows?
Some additional info: I don't want to use a new resource in the existing smali code. What I want is a new resource, say @id/main, to be used in the xml files and in a java class, which describes the method that should be invoked when the widget updates.
What I've done now is that I've made a new R$main class with the resources I want to use. I also made the java class with the method and it refers to the resources mentioned in the R$main class. This way I can build it without problems in Netbeans. But when I want to use apktool, I keep getting the message:
Code:
I: Checking whether sources has changed...
I: Smaling...
Exception in thread "main" java.lang.NullPointerException
at org.jf.util.PathUtil.getRelativeFile(Unknown Source)
at org.jf.smali.smaliFlexLexer.getSourceName(Unknown Source)
at org.jf.smali.smaliFlexLexer.getErrorHeader(Unknown Source)
at org.jf.smali.smaliFlexLexer.nextToken(Unknown Source)
at org.antlr.runtime.CommonTokenStream.fillBuffer(Unknown Source)
at org.antlr.runtime.CommonTokenStream.LT(Unknown Source)
at org.jf.smali.smaliParser.smali_file(Unknown Source)
at brut.androlib.mod.SmaliMod.assembleSmaliFile(Unknown Source)
at brut.androlib.src.DexFileBuilder.addSmaliFile(Unknown Source)
at brut.androlib.src.SmaliBuilder.buildFile(Unknown Source)
at brut.androlib.src.SmaliBuilder.build(Unknown Source)
at brut.androlib.src.SmaliBuilder.build(Unknown Source)
at brut.androlib.Androlib.buildSourcesSmali(Unknown Source)
at brut.androlib.Androlib.buildSources(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.androlib.Androlib.build(Unknown Source)
at brut.apktool.Main.cmdBuild(Unknown Source)
at brut.apktool.Main.main(Unknown Source)
Maybe I'm completely on the wrong track...
Sometimes I get NullPointerException instead of real smali errors, when I'm doing "apktool b". I think it's a bug in the apktool. Try to smali "smali" dir normally, without apktool to see errors.
But I don't really see much sense in adding any Java classes, because they just can't work without additional steps. What my script does, is:
javac all files from brut.iface
javac all files from brut.src against compiled brut.iface
convert compiled brut.src to smali. This is done in two steps:
dx them to classes.dex
baksmali them using baksmali or apktool
Most of commands from my script (javac, dx, apktool/baksmali) should work on a Windows. File operations, i.e. mkdir, rm, cp should be easily portable. I don't know, how to replace "find" command.
You could try to use Cygwin - then you should be able to run my script on a Windows.
To do this properly, I'm installing Linux now, so my next reply could take a while...
Related
I'm creating a project as a dll. Can anybody tell me how to go about debugging it. I attach it to the remote process "services.exe" but any breakpoints I put, dont hit and display an exclamation mark, saying that no executable code exists at that point..
How do you guys debug ur DLLs??
be sure that services.exe is the correct process
bye
Let me explain a bit. Actually I'm trying to write a WinMob service (This is my first time writing a service dll, infact, first time writing a dll).
I created a dll with the DLL_PROCESS_ATTACH case in the ul_reason_for_call calling a SPC_init function (exported using __declspec(dllexport)).
Moreover, I added these entries to the registry:
[HKEY_LOCAL_MACHINE\Services\ShantzABC]
"Order"=dword:00000009
"Index"=dword:00000000
"Prefix"="SPC"
"Keep"=dword:00000001
"Dll"="ShantzABC.dll"
"FriendlyName"="ShantzABC"
But the service didn't load. Then I added the line "services load ShantzABC" to the deployment options of my VS2005 project. Now, on pressing F5, the service loads (I know because I put a MessageBox() inside the SPC_init, which is now displayed on screen) BUT:
1. I can't see the ShantzABC.dll loaded in Remote Process Viewer tool (seeing for services.exe)
2. Moreover, I can't hit any breakpoints in my project, even the one kept on the MessageBox() line. (Though now they have stopped giving the error "not an executable line" that they were giving earlier)
Actually I'm trying to start a project which could benefit greatly if it was a service instead of me writing an exe for it..
So, any pointers??
EDIT: added a part of the code:
Code:
#include "stdafx.h"
#include "ShantzABC.h"
#include <windows.h>
#include <commctrl.h>
HINSTANCE g_hInst;
// This is an example of an exported function.
__declspec(dllexport) HRESULT SPC_init(void)
{
HRESULT result;
MessageBox(NULL, TEXT("initCtrl"), TEXT("INIT"), MB_OK);
result = S_OK;
return result;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
HRESULT result;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//save instance handle
g_hInst = (HINSTANCE) hModule;
result = SPC_init();
MessageBox(NULL, TEXT("initCtrl"), TEXT("main"), MB_OK);
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
1. implements all the exported functions for service:
Init, Open, Close, Deinit, IOControl, Read, Seek, Write also if empty (just return 0)
2. instead to use F5 to debug it, try to deploy the dll and attach the process to debug it: Debug > Attach to process.... (vs2005's menu)
i hope this help you
Could you please direct me to an SW development environment, which documents the above functions, Reg_Key meanings etc. sort of a reference guide? What compilers/linkers do you guys use ?
crino said:
1. implements all the exported functions for service:
Init, Open, Close, Deinit, IOControl, Read, Seek, Write also if empty (just return 0)
2. instead to use F5 to debug it, try to deploy the dll and attach the process to debug it: Debug > Attach to process.... (vs2005's menu)
Click to expand...
Click to collapse
I implemented all the functions and just returned 1. (didnt return 0 because read on a msdn blog that returning 0 form dllmain or xxx_Init will unload the dll)
But again on attaching to services.exe, its not loading my dll(or unloads it soon after loading). (Dll is kept in \windows)
So, cant find the dll in the modules window and so cant load the symbols for it in order to debug it..
I want to developer RSS FEED reader for android. I am following this tutorial : http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/downloads.html
I am not getting any error in the program but not getting desired output
**This is my logcat:**
Code:
07-20 16:12:23.531: ERROR/Zygote(33): setreuid() failed. errno: 2
07-20 16:12:35.101: ERROR/Zygote(33): setreuid() failed. errno: 17
07-20 16:12:37.031: ERROR/BatteryService(59): usbOnlinePath not found
07-20 16:12:37.031: ERROR/BatteryService(59): batteryVoltagePath not found
07-20 16:12:37.031: ERROR/BatteryService(59): batteryTemperaturePath not found
07-20 16:12:37.061: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
07-20 16:12:47.381: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
07-20 16:12:47.412: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
07-20 16:12:47.812: ERROR/System(59): Failure starting core service
07-20 16:12:47.812: ERROR/System(59): java.lang.SecurityException
07-20 16:12:47.812: ERROR/System(59): at android.os.BinderProxy.transact(Native Method)
07-20 16:12:47.812: ERROR/System(59): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
07-20 16:12:47.812: ERROR/System(59): at android.os.ServiceManager.addService(ServiceManager.java:72)
07-20 16:12:47.812: ERROR/System(59): at com.android.server.ServerThread.run(SystemServer.java:184)
07-20 16:12:49.591: ERROR/SoundPool(59): error loading /system/media/audio/ui/Effect_Tick.ogg
07-20 16:12:49.591: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressStandard.ogg
07-20 16:12:49.602: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressSpacebar.ogg
07-20 16:12:49.612: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressDelete.ogg
07-20 16:12:49.622: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressReturn.ogg
07-20 16:12:52.672: ERROR/ThrottleService(59): Could not open GPS configuration file /etc/gps.conf
07-20 16:12:54.551: ERROR/logwrapper(145): executing /system/bin/tc failed: No such file or directory
07-20 16:12:54.691: ERROR/logwrapper(147): executing /system/bin/tc failed: No such file or directory
07-20 16:12:54.781: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
07-20 16:13:17.789: ERROR/HierarchicalStateMachine(59): TetherMaster - unhandledMessage: msg.what=3
07-20 16:13:38.669: INFO/ActivityManager(59): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=268 uid=10028 gids={}
07-20 16:13:38.689: WARN/RecognitionManagerService(59): no available voice recognition services found
07-20 16:13:39.370: DEBUG/dalvikvm(59): GC_EXPLICIT freed 9347 objects / 593752 bytes in 302ms
07-20 16:13:39.590: DEBUG/dalvikvm(165): GC_EXPLICIT freed 2883 objects / 156272 bytes in 1275ms
07-20 16:13:39.659: INFO/installd(35): unlink /data/dalvik-cache/[email protected]@[email protected]
07-20 16:13:39.782: DEBUG/AndroidRuntime(118): Shutting down VM
07-20 16:13:39.789: DEBUG/jdwp(118): adbd disconnected
07-20 16:13:39.809: INFO/AndroidRuntime(118): NOTE: attach of thread 'Binder Thread #3' failed
07-20 16:13:39.879: INFO/ActivityThread(268): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
07-20 16:13:40.131: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
07-20 16:13:40.429: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
07-20 16:13:40.511: DEBUG/AndroidRuntime(278): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-20 16:13:40.511: DEBUG/AndroidRuntime(278): CheckJNI is ON
07-20 16:13:41.740: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 50234 ms (total 50234 ms)
07-20 16:13:42.340: DEBUG/AndroidRuntime(278): --- registering native functions ---
07-20 16:13:43.790: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.msi.androidrss/.ShowDescription }
07-20 16:13:43.890: DEBUG/AndroidRuntime(278): Shutting down VM
07-20 16:13:43.910: DEBUG/jdwp(278): adbd disconnected
07-20 16:13:43.960: INFO/AndroidRuntime(278): NOTE: attach of thread 'Binder Thread #3' failed
07-20 16:13:44.099: INFO/ActivityManager(59): Start proc com.msi.androidrss for activity com.msi.androidrss/.ShowDescription: pid=286 uid=10042 gids={1015}
07-20 16:13:45.939: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2ff7e0:0x2ff8ec] in 7962326 ns
07-20 16:13:46.670: INFO/ActivityManager(59): Displayed activity com.msi.androidrss/.ShowDescription: 2691 ms (total 2691 ms)
**This is my manifest.xml**
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msi.androidrss"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".RSSReader"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</intent-filter>
</activity>
</application>
</manifest>
**This is one of my .java program "RSSReader.java"**
Code:
package com.msi.androidrss;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.util.Log;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.content.Intent;
import com.msi.androidrss.ShowDescription;
public class RSSReader extends Activity implements OnItemClickListener
{
public final String RSSFEEDOFCHOICE = "http://www.ibm.com/developerworks/views/rss/customrssatom.jsp?zone_by=XML&zone_by=Java&zone_by=Rational&zone_by=Linux&zone_by=Open+source&zone_by=WebSphere&type_by=Tutorials&search_by=&day=1&month=06&year=2007&max_entries=20&feed_by=rss&isGUI=true&Submit.x=48&Submit.y=14";
private static final int SELECT = 0;
private static final int REFRESH = 1;
public final String tag = "RSSReader";
private RSSFeed feed = null;
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// go get our feed!
feed = getFeed(RSSFEEDOFCHOICE);
// display UI
UpdateDisplay();
}
private RSSFeed getFeed(String urlToRssFeed)
{
try
{
// setup the url
URL url = new URL(urlToRssFeed);
// create the factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create a parser
SAXParser parser = factory.newSAXParser();
// create the reader (scanner)
XMLReader xmlreader = parser.getXMLReader();
// instantiate our handler
RSSHandler theRssHandler = new RSSHandler();
// assign our handler
xmlreader.setContentHandler(theRssHandler);
// get our data via the url class
InputSource is = new InputSource(url.openStream());
// perform the synchronous parse
xmlreader.parse(is);
// get the results - should be a fully populated RSSFeed instance, or null on error
return theRssHandler.getFeed();
}
catch (Exception ee)
{
// if we have a problem, simply return null
return null;
}
}
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0, RSSReader.SELECT, 0, "Choose RSS Feed").setIcon(android.R.drawable.ic_menu_mapmode);
//menu.add(0,0,"Choose RSS Feed");
//menu.add(0,1,"Refresh");
menu.add(0, RSSReader.REFRESH, 0, "Refresh").setIcon(android.R.drawable.ic_menu_mapmode);
Log.i(tag,"onCreateOptionsMenu");
return true;
}
@Override
public boolean onMenuItemSelected(final int featureId, final MenuItem item) {
switch (item.getItemId()) {
case RSSReader.SELECT:
Log.i(tag,"Set RSS Feed");
return true;
case RSSReader.REFRESH:
Log.i(tag,"Refreshing RSS Feed");
return true;
}
return false;
}
private void UpdateDisplay()
{
TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
ListView itemlist = (ListView) findViewById(R.id.itemlist);
if (feed == null)
{
feedtitle.setText("No RSS Feed Available");
return;
}
feedtitle.setText(feed.getTitle());
feedpubdate.setText(feed.getPubDate());
ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems());
itemlist.setAdapter(adapter);
itemlist.setOnItemClickListener(this);
itemlist.setSelection(0);
}
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");
Intent itemintent = new Intent(this,ShowDescription.class);
Bundle b = new Bundle();
b.putString("title", feed.getItem(position).getTitle());
b.putString("description", feed.getItem(position).getDescription());
b.putString("link", feed.getItem(position).getLink());
b.putString("pubdate", feed.getItem(position).getPubDate());
itemintent.putExtra("android.intent.extra.INTENT", b);
startActivity(itemintent);
}
}
**This is one of my .java program "ShowDescription.java"**
Code:
package com.msi.androidrss;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;
import android.view.*;
public class ShowDescription extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.showdescription);
String theStory = null;
Intent startingIntent = getIntent();
if (startingIntent != null)
{
Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT");
if (b == null)
{
theStory = "bad bundle?";
}
else
{
theStory = b.getString("title") + "\n\n" + b.getString("pubdate") + "\n\n" + b.getString("description").replace('\n',' ') + "\n\nMore information:\n" + b.getString("link");
}
}
else
{
theStory = "Information Not Found.";
}
TextView db= (TextView) findViewById(R.id.storybox);
db.setText(theStory);
Button backbutton = (Button) findViewById(R.id.back);
backbutton.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
}
**As an output I am getting "*"NO RSS FEED AVAILABLE"*", why ?**
**HELP!!!**
I found the IBM tutorial very hard to follow, I eventually read RSS through a simpler way. Here is a link to the tutorial I wrote after:
http://droidapp.co.uk/?p=166
eatmold said:
I found the IBM tutorial very hard to follow, I eventually read RSS through a simpler way. Here is a link to the tutorial I wrote after:
http://droidapp.co.uk/?p=166
Click to expand...
Click to collapse
Thanks, could you plz upload the full source code ?
Does it support images and clickable feed so that clicking any feed directs the user to the website ?
I will upload the full source of my app today.
It will read any section of the xml so if there are images you will be able to extract the URL and use it in your app. It does support clickable feed also, just by extracting the post URL again.
The app I made is for an audio podcast.
Here you go... hope it helps
http://dl.dropbox.com/u/6876950/EppyGibbonPodcast.zip
help
hello tony,
first thank you for the source code.
I tried running your source code but I am getting these error messages:
Code:
Description Resource Path Location Type
Project 'EppyGibbonPodcast' is missing required library: 'C:\Users\Tony.DZNT\AndroidDev\android-sdk-windows\extras\android\compatibility\v4\android-support-v4.jar' EppyGibbonPodcast Build path Build Path Problem
The project cannot be built until build path errors are resolved EppyGibbonPodcast Unknown Java Problem
Attribute minSdkVersion (4) is lower than the project target API level (10) AndroidManifest.xml /EppyGibbonPodcast line 1 Android ADT Problem
This is the version of my eclipse:
Code:
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110218-0911
I am using 2.2 but I can see you created this code for 2.3. I do have API installed for 3.0 and 3.1 etc so I should be at-least able to run the program on virtual mobile (on PC thru eclipse) but getting the above error msgs.
Please Help.
I just found the file "android-support-v4.jar" in this location:
D:\Android\AndroidSDK\android-sdk-windows\extras\android\compatibility\v4
now how and where I can link this path ?
eatmold said:
I found the IBM tutorial very hard to follow, I eventually read RSS through a simpler way. Here is a link to the tutorial I wrote after:
http://droidapp.co.uk/?p=166
Click to expand...
Click to collapse
very clean and precise. i really like well compartmentalized code
iamsuper123 said:
I just found the file "android-support-v4.jar" in this location:
D:\Android\AndroidSDK\android-sdk-windows\extras\android\compatibility\v4
now how and where I can link this path ?
Click to expand...
Click to collapse
Sorry, I must have left that in from when I was playing with Fragments, it's not needed. You can remove it from the build path. Right click the project, properties, then find and remove from build path.
Hi tony,
I did try to remove it and now I am getting these errors:
Code:
Description Resource Path Location Type
FragmentActivity cannot be resolved to a type podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 14 Java Problem
FragmentActivity cannot be resolved to a type podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 19 Java Problem
The import android.support cannot be resolved podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 8 Java Problem
The method findViewById(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 24 Java Problem
The method findViewById(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 27 Java Problem
The method findViewById(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 30 Java Problem
The method getIntent() is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 32 Java Problem
The method onCreate(Bundle) of type podcast must override a superclass method podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 17 Java Problem
The method setContentView(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 21 Java Problem
The method startActivity(Intent) is undefined for the type new View.OnClickListener(){} podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 57 Java Problem
The method startActivity(Intent) is undefined for the type new View.OnClickListener(){} podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 67 Java Problem
AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized main.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 50 Java Problem
Attribute minSdkVersion (4) is lower than the project target API level (10) AndroidManifest.xml /EppyGibbonPodcast line 1 Android ADT Problem
The import com.owentech.eppygibbonpodcast.R is never used arrays.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 3 Java Problem
I would deeply appreciate if you could upload a fresh copy of source code without this fragment file / issue.
thank you
OK. I'll upload again tomorrow.
thanks i will keep an eye on your site and here
I have re-uploaded the source, now without the Fragment compatability.
http://dl.dropbox.com/u/6876950/EppyGibbonPodcast.zip
Let me know if you have any problems, but this should run fine now.
Tony
thank you very much tony
it does work now.
I just get these warnings:
Code:
Description Resource Path Location Type
AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized main.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 50 Java Problem
AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized rsstest.java /rsstest/src/com/owentech/eppygibbonpodcast line 50 Java Problem
Attribute minSdkVersion (4) is lower than the project target API level (10) AndroidManifest.xml /EppyGibbonPodcast line 1 Android ADT Problem
I tested the code and I think it only works for the RSS FEED that you added in the code.
I tried other rss feed like "http://rss.news.yahoo.com/rss/mostviewed" mentioned on your website (in comments) and few other rss feeds but nothing seems to be working.
(thanks once for all the help)
I wouldn't worry about those warnings.
The app I have uploaded is specifically for the Epileptic Gibbon Podcast, which is a wordpress site.
The code should just need slight changes to match the rss feed you want to use. I suggest you download the rss xml for Epileptic Gibbon and the rss xml for Yahoo and compare the differences.
really great code.
Thanks.
I could really use some help.
I would like to use this app to pull feeds for this site.
http://las-vegas-drunk-driving-attorney.com/
But have no idea how to add this to eclipse and then turn it in to an app.
Could someone help out with the steps to take?
Thank.
So in my toolkit, id like to design an activity where I could point it towards certain lines in the build.prop to allow a user to easily toggle, for instance this line
qemu.hw.mainkeys=0
So, in the layout xml, lets say it had "Enable Nav Bar" and a "Toggle Button" for on/off
Where would i start in developing such a feature?
You create a ToggleButton and whenever it is clicked, you change the line.
What is your problem?
nikwen said:
You create a ToggleButton and whenever it is clicked, you change the line.
What is your problem?
Click to expand...
Click to collapse
My concerns are wouldnt I need to add ro permissions on the prop before toggling and a reboot action to apply
I think your device needs to be rooted to be able to write to the build.prop file. You do not need root access to read it though
I'm from mobile and i can't post some code but i will give you some hints
To edit build.prop programmatically first you ne ed to be rooted then you can use the shell command "sed" to exchange values. Take a look at AOKP settings source on github and look for density changer class
If you want to import various build properties you can use fileinputstream and read the file line by line then let the app create listview custom items for every line in the file (you need a custom adapter) .
Sorry if this post it's not really useful but i will edit this when at PC
Sent from my HTC One X using Tapatalk 4 Beta
Thankyou for the tip! The answer might of been infront of my face possibly...
Sent from my 9300 using xda app-developers app
xcesco89 said:
I'm from mobile and i can't post some code but i will give you some hints
To edit build.prop programmatically first you ne ed to be rooted then you can use the shell command "sed" to exchange values. Take a look at AOKP settings source on github and look for density changer class
If you want to import various build properties you can use fileinputstream and read the file line by line then let the app create listview custom items for every line in the file (you need a custom adapter) .
Sorry if this post it's not really useful but i will edit this when at PC
Sent from my HTC One X using Tapatalk 4 Beta
Click to expand...
Click to collapse
I Wrote something up but I keep getting force closes "Not a java code monkey yet, still learning" and Ill post here what I have when I get to my pc later. Maybe you can see what Im missing or did wrong. What I did is I have a preference screen similiar to AOKP density changer class. What Im going for is a PreferenceList that you click and your values are Enable or Disabled and another preference to reboot to apply settings. Im wanting to allow the user to enable and disable the Navigation Bar by toggling it through the build.prop. If this works, I want to add more toggles custom values like change your phone model, Screen Density, build number, ect; but figured Id start with something simpler first and see if it works.
Sent from my Alps9300 using Tapatalk
Nx Biotic said:
I Wrote something up but I keep getting force closes "Not a java code monkey yet, still learning" and Ill post here what I have when I get to my pc later. Maybe you can see what Im missing or did wrong. What I did is I have a preference screen similiar to AOKP density changer class. What Im going for is a PreferenceList that you click and your values are Enable or Disabled and another preference to reboot to apply settings. Im wanting to allow the user to enable and disable the Navigation Bar by toggling it through the build.prop. If this works, I want to add more toggles custom values like change your phone model, Screen Density, build number, ect; but figured Id start with something simpler first and see if it works.
Sent from my Alps9300 using Tapatalk
Click to expand...
Click to collapse
this is the method you need:
Code:
private void setLcdDensity(int newDensity) {
Helpers.getMount("rw");
new CMDProcessor().su.runWaitFor("busybox sed -i 's|ro.sf.lcd_density=.*|"
+ "ro.sf.lcd_density" + "=" + newDensity + "|' " + "/system/build.prop");
Helpers.getMount("ro");
}
( method took from here : https://github.com/TeamBAKED/packag...aked/romcontrol/fragments/DensityChanger.java )
newDensity is the int/string you let the user set ( you can use a seekbar or a dialog or what you prefer)
you have also CMDProcessor().su.runWaitFor : just use the classes you can find here : https://github.com/TeamBAKED/packag...11bca71808c9143/src/com/baked/romcontrol/util
just add these classes in your project ( these are to simplify your life when you need to use android terminal [ remember to give credits on your app! ] )
Now, you can use various types of views and methods to show to the user all the available props:
- manually add every view for every line in your build.prop ( this will probably limit the compatibility with other devices and make your app "laggy" due to "gazilions" views )
- use a blank linearLayout and inflate a "row view" for every line in build.prop:
read file line by line and import every line in an ArrayList:
Code:
ArrayList<String> Tokens = new ArrayList<String>();
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("/system/build.prop");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
strLine = strLine.trim();
if ((strLine.length()!=0)) {
String[] names = strLine.split("\\s+");
Tokens.add(names[0]);
}
}
for (String s : Tokens) {
//System.out.println(s);
//Log.d("NNNNNNNNNNNNNNNNNN", s);
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
names = new String[Tokens.size()-1];
names = Tokens.toArray(names);
ArrayList<String> value = new ArrayList<String>();
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
while ((strLine = br.readLine()) != null) {
strLine = strLine.trim();
if ((strLine.length()!=0)) {
String[] val = strLine.split("\\s+");
value.add(val[1]);
}
}
for (String s : value) {
//System.out.println(s);
//Log.d("NNNNNNNNNNNNNNNNNN", s);
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
System.err.println("Error: " + e.getMessage());
}
values = new String[value.size()-1];
values = value.toArray(values);
LineNumberReader lnr = null;
try {
lnr = new LineNumberReader(new FileReader(new File("/sys/devices/system/cpu/cpu0/cpufreq/UV_mV_table")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
lnr.skip(Long.MAX_VALUE);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int num = lnr.getLineNumber();
Log.d("LINES", ""+num);
int i = 0;
//now inflate a specific view for every line
// you can also filter every item for example by reading the string and inflating a different layout using an if statement
for (String s : names) {
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflater.inflate(R.layout.uvrow, null, true);
TextView text0 = (TextView) v.findViewById(R.id.text0);
ImageButton back0 = (ImageButton) v.findViewById(R.id.back0);
final EditText edit0 = (EditText) v.findViewById(R.id.edit0);
ImageButton fwd0 = (ImageButton) v.findViewById(R.id.fwd0);
text0.setText(s);
parentGroup.addView(v);
edit0.setText(values[i]);
/*
* if you need to set listeners and actions insert them inside this loop!
*/
}
if you need more informations, take a look at my code on github ( was my first "really useful" app ): https://github.com/cesco89/CustomSettings/blob/master/src/com/cesco/customsettings/UVTable.java
it's not perfect, could be tricky, but i can't post all the code here
This Is what I put together...Excuse any errors in java...Im new at this. When I start this fragment, I get a force close. What did I do?
Code:
package com.bionx.res.catalyst;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import com.bionx.res.R;
import com.bionx.res.helpers.CMDProcessor;
import com.bionx.res.helpers.Helpers;
public abstract class Navbar extends PreferenceFragment implements OnPreferenceChangeListener {
Preference mReboot;
ListPreference mStockValue;
int newStockValue;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.navbarchanger);
mStockValue = (ListPreference) findPreference("stock_value");
mStockValue.setOnPreferenceChangeListener(this);
mReboot = findPreference("reboot");
}
public boolean onPreference(Preference preference) {
if (preference == mReboot) {
PowerManager pm = (PowerManager) getActivity()
.getSystemService(Context.POWER_SERVICE);
pm.reboot("Setting Navbar");
}
return false;
}
[user=439709]@override[/user]
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mStockValue) {
newStockValue = Integer.parseInt((String) newValue);
setNavbarValue(newStockValue);
mStockValue.setSummary(getResources().getString(R.string.navbar_changer) + newStockValue);
return true;
}
return false;
}
private void setNavbarValue(int newNavbar) {
Helpers.getMount("rw");
new CMDProcessor().su.runWaitFor("busybox sed -i 's|qemu.hw.mainkeys=.*|"
+ "qemu.hw.mainkeys" + "=" + newNavbar + "|' " + "/system/build.prop");
Helpers.getMount("ro");
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="System Properties"
android:summary="User System Tweaks" />
<ListPreference
android:entries="@array/navbar_stock_entries"
android:entryValues="@array/navbar_stock_values"
android:key="stock_value"
android:title="NavBar Enabler"
android:summary="Toggle the system navbar" />
<Preference
android:key="reboot"
android:title="Reboot"
android:summary="Applies tweaks and reboots" />
</PreferenceScreen>
Where I launch the fragment.
Code:
...
<header
android:fragment="com.bionx.res.catalyst.Navbar"
android:icon="@drawable/ic_changelog"
android:title="System Ui Tweaks"
android:summary="Developers soup of the week" />
...
Nx Biotic said:
This Is what I put together...Excuse any errors in java...Im new at this. When I start this fragment, I get a force close. What did I do?
Code:
package com.bionx.res.catalyst;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
import com.bionx.res.R;
import com.bionx.res.helpers.CMDProcessor;
import com.bionx.res.helpers.Helpers;
public abstract class Navbar extends PreferenceFragment implements OnPreferenceChangeListener {
Preference mReboot;
ListPreference mStockValue;
int newStockValue;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.navbarchanger);
mStockValue = (ListPreference) findPreference("stock_value");
mStockValue.setOnPreferenceChangeListener(this);
mReboot = findPreference("reboot");
}
public boolean onPreference(Preference preference) {
if (preference == mReboot) {
PowerManager pm = (PowerManager) getActivity()
.getSystemService(Context.POWER_SERVICE);
pm.reboot("Setting Navbar");
}
return false;
}
[user=439709]@override[/user]
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mStockValue) {
newStockValue = Integer.parseInt((String) newValue);
setNavbarValue(newStockValue);
mStockValue.setSummary(getResources().getString(R.string.navbar_changer) + newStockValue);
return true;
}
return false;
}
private void setNavbarValue(int newNavbar) {
Helpers.getMount("rw");
new CMDProcessor().su.runWaitFor("busybox sed -i 's|qemu.hw.mainkeys=.*|"
+ "qemu.hw.mainkeys" + "=" + newNavbar + "|' " + "/system/build.prop");
Helpers.getMount("ro");
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:title="System Properties"
android:summary="User System Tweaks" />
<ListPreference
android:entries="@array/navbar_stock_entries"
android:entryValues="@array/navbar_stock_values"
android:key="stock_value"
android:title="NavBar Enabler"
android:summary="Toggle the system navbar" />
<Preference
android:key="reboot"
android:title="Reboot"
android:summary="Applies tweaks and reboots" />
</PreferenceScreen>
Where I launch the fragment.
Code:
...
<header
android:fragment="com.bionx.res.catalyst.Navbar"
android:icon="@drawable/ic_changelog"
android:title="System Ui Tweaks"
android:summary="Developers soup of the week" />
...
Click to expand...
Click to collapse
please post the Log you get on Eclipse !
the log will tell you exactly where the error is
Synopsis:
Have you ever wanted as root apps developer to use your favourite Java codes instead of bash/shell commands?
Have you grown tired of Runtime.getRuntime.exec("su") and ProcessBuilder("su").start()?
I did and still do, that's why I've been searching for a solution for my problem until I found out in AOSP source code that some of *.java files run with root access, tracking the way they execute them with root access led me to make this simple library.
Description:
Cmd library -short for Command- is an open source (licensed under Apache licence V2) that allows you to execute java commands with root access privileges by passing package name, full class name and whether your app is a system app or not in just two lines of codes.
For instance, suppose you want to flash a *.img recovery image, the first thing comes to your mind is this code:
Code:
busybox dd if=/path/to/recovery.img of=/path/to/recoveryPartition
lets say /sdcard/recovery.img is the file path and /dev/block/mmcblk0p12 is the partition (Samsung GALAXY Ace Plus GT-S7500)
Here is how to implement it:
Code:
...
Proccess proc = Runtime.getRuntime().exec("su");
OutputStream stream = proc.getOutputStream();
stream.write("busybox dd if=/sdcard/recovery.img of=/dev/block/mmcblk0p12".getBytes());
stream.flush();
...
Pretty simple isn't it, now suppose you don't know anything about bash codes, what will you do?
Let me answer this question:
1) Learn some bash.
2) Use Cmd library with java codes.
Here is the same implementaion with Cmd library:
Code:
...
JavaRoot root = JavaRoot.newInstance(getPackageName(), RootCommands.class.getName(), false);
root.execute("/sdcard/recovery.img", "/dev/block/mmcblk0p12")
...
And in RootCommands.java file (should not be an inner class):
Code:
package com.bassel.example;
import com.bassel.cmd.Command;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Main extends Command
{
private byte[] buffer;
private File recovery, partition;
private FileInputStream in;
private FileOutputStream out;
//static main method implementation is a must
@Override
public static void main(String[] args)
{
//required to start
new Main().run(args);
}
//the begging just like onCreate
@Override
public void onRun()
{
if(argsCount() < 2) showUsage();
System.out.println(String.format("Flashing %s to %s", getArg(0), getArg(1)));
recovery = new File(nextArg());
partition = new File(nextArg());
buffer = new byte[1024 * 1024];
try
{
in = new FileInputStream(recovery);
out = new FileOutputStream(partition);
while(in.read(buffer) > 0)
{
out.write(buffer);
out.flush();
}
in.close();
out.close();
System.out.println("Flashed successfully!");
}
catch (Exception e)
{e.printStackTrace(System.err);}
}
//called upon calling showUsage()
@Override
public void onShowUsage()
{
System.err.println("Two args are needed!");
}
//called once an exception is caught
@Override
public void onExceptionCaught(Exception exception)
{
exception.printStackTrace(System.err);
}
}
Quite lengthy but sometimes we prefer using Java codes to bash ones, don't we?
Here is another example for listing /data files:
Code:
package com.bassel. example;
import java.io.File;
//Without extending Command.class
public class Main
{
@Override
public static void main(String[] args)
{
String[] files = new File("/data").list();
for(String file : files)
{
System.out.println(file);
}
}
}
Usage in depth:
Check root access:
Cmd.root();
No root:
Cmd.SH.ex(String command, String... args);
Cmd.SH.ex(String[] commands);
Cmd.SH.ex(List commands);
With root access:
Cmd.SU.ex(String command, String... args);
Cmd.SU.ex(String[] commands);
Cmd.SU.ex(List commands);
JavaRoot java = JavaRoot.newInstance(String packageName, String className, boolean isSystemApp);
java.execute(String... args);
java.executeInBackground(String... args);
All previous methods aside of the last one:
java.executeInBackground(String... args);
return an instance of type Output that has the following methods:
Code:
boolean success() //returns true if process exit value = 0 else false
String getString() //returns output in String format
String[] getArray() //returns output in String Array format
List getList() //returns output in String List format
int getExitValue() //returns process exit value
String toString() //returns process status and output in String format
Converting:
String string = ...;
String[] array = ...;
List list = ...;
String s1 = Convert.array2string(array);
String s2 = Convert.list2string(list);
String[] a1 = Convert.list2array(list);
String[] a2 = Convert.string2array(string);
List l1 = Convert.array2list(array);
List l2 = Convert.string2list(string);
Library GitHub link:
Cmd (licensed under Apache License, Version 2.0)
Examples:
Window Manipulator
I'm learning how to manage data that I pull from DB (MYSQL) from this coding. I tried to figure out from free source coding but got stuck on this function, can anybody explain to me flow of this coding?
Code:
protected void onPostExecute(Void aVoid) {
name = names.split(":");
email = emails.split(":");
phone = phones.split(":");
combinedArray = combinedText.split(":");
listView.setAdapter(new ArrayAdapter<String>(RetrieveData.this,
android.R.layout.simple_list_item_1, combinedArray));
progressDialog.dismiss();
}
and when I tried to use this code, red line prompt out and saying that cannot resolved this constructor on if i change
Code:
listItems
to
Code:
names
variables on this
Code:
adapter=new ArrayAdapter<String>(this,
R.layout.list_item, R.id.txtitem, listItems);
I don't understand why I need to use 'split' to pull out the output on listview.