Pars Application doesn't accept string - android

I'm making a android app .
I wanna make a RSS reader application .
I get help of an Udemy's course , I almost copy all the codes , what codes he has said on course , but I've got problem! contrariwise video course !
I have problem in this codes :
private String mFileContents;
private Button btnParse;
private ListView xmlList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnParse = (Button) findViewById(R.id.btnParse);
btnParse.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ParseApplications parseApplications = new ParseApplications(mFileContents);
parseApplications.process();
ArrayAdapter<Application> arrayAdapter = new ArrayAdapter<Application>(
MainActivity.this, R.layout.list_item, parseApplications.getApplications());
xmlList.setAdapter(arrayAdapter);
}
});
xmlList = (ListView) findViewById(R.id.xmlList);
DownloadData downloadData = new DownloadData();
downloadData.execute("http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topfreeapplications/limit=10/xml");
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
my APP will connect to 10 top apps of apple market and show them ( show apps' name and artist and release date between two line )
It should be like this :
App
instead that my app get error and stop ! and as far as I know that get error for 'mFileContents' , it is string but as Android Studio comment : I must make a public string in ParseApplications class ! but when I do that , app doesn't work still ! how can I resolve that ?

Related

i want use jsoup to grab news on my android app

I have a problem that I want to use jsoup to grab news but always fail.
this is news website.
https://www3.nhk.or.jp/news/
this is my picture . which I circle is I wanted data.
https://drive.google.com/open?id=1KJAyOSdHO8APPD6_A9MjxkoFjekcQLXt
but no matter what I do. it always get wrong data or empty.
this is my program.
public class News extends AppCompatActivity {
Button ok;
private static final String url ="https://www3.nhk.or.jp/news/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news);
ok=(Button)findViewById(R.id.ok);
ok.setOnClickListener(okbtn);
}
private Button.OnClickListener okbtn=new Button.OnClickListener(){
public void onClick(View v){
try{
Connection.Response response = Jsoup.connect(url).execute();
String body = response.body();
Document data = Jsoup.parse(body);//visible-phone print_hide
Elements country=data.select("main");
Elements main=data.select("div[id=module module--news-main index-main]");
for(Element e1: country)
{
mytoast(e1+"");
}
}
catch(Exception ex){ex.printStackTrace() ;}
}
};
private void mytoast(String str)
{
Toast toast=Toast.makeText(this, str, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
please help me
thanks
You can try to see it's HTML first.
If you can't see it, you don't use jsoup.
There's a small hint in its comment:
このページではJavaScriptを使用しています
=>This is generated by JavaScript
If it's generated, you can't find it from Jsoup.
In this case, I'll use Chrome's tool to monitor the XHR tab
Look into each XHR request, and find the most possible one,
for example, I see this
https://www3.nhk.or.jp/news/json16/syuyo.json?_=1559183885640
A part of the response:
"id":"193411",
"title":"三菱UFJ銀行 新規口座は原則デジタル通帳に",
"pubDate":"Thu, 30 May 2019 04:03:11 +0900",
"cate":"5",
...
"id":"193437",
"title":"エアレース世界選手権 今季限りで終了",
"pubDate":"Thu, 30 May 2019 09:40:37 +0900",
So this is exactly what you want. It comes from another link!
You don't need Jsoup, just HttpGet the link
https://www3.nhk.or.jp/news/json16/syuyo.json?_=1559183885640
And I think the numbers looks like UnixTime,
So I check the current time is : 1559184830782, that's it.
Just use that link as API and time as parameter.

Issue with endless loop in android studio

Working in Android Studio and I've run into a few small issues so I figured I would ask for help / advice.
I am currently working on a small testing application that would allow users to open the application and select practice test or timed test (as displayed in picture 1). If users select practice test they have unlimited time to select an answer and the systems tells them if they have picked the correct answer. If the user selects timed than the system allots a predetermined amount of time and after each question the score is added and calculated, here lies my issues.
1.) Right now my code loops endlessly, ideally (at least for the timed aspect) I want my code to go through the 5 questions scoring the correct or incorrect based on the users selection. Then I want to display the # correct and in correct.
So my question is two fold, first how do I go about preventing my code from looping endless so I can begin to record iterations as ++correctAnswer ++incorrect answer. And, when it comes time to display the results, should I create a new activity to display the results.
Android is a bit confusing to me, I hope I have provided enough information and I appreciate and helping advice.
Thank You
** Code **
private int currentQuestion;
private String[] questions;
private String[] answers;
private Button answerButton;
private Button questionButton;
private TextView questionView;
private TextView answerView;
private EditText answerText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init()
{
questions = new String[]{"What is the acronym for Computer Science and Information Management?",
"What is the CSIT corse number of the class you are currently in?",
"What Android program do we use to create android applications?"};
answers = new String[]{"CSIT","2250", "Android Studio"};
currentQuestion = -1;
answerButton = (Button)findViewById(R.id.AnswerButton);
questionButton = (Button)findViewById(R.id.QuestionButton);
questionView = (TextView)
findViewById(R.id.QuestionTextView);
answerView = (TextView) findViewById(R.id.AnswerTextView);
answerText = (EditText) findViewById(R.id.AnswerText);
answerButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
checkAnswer();
}});
questionButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
showQuestion();
}});
}
// Display current quesiton
public void showQuestion()
{
currentQuestion++;
if(currentQuestion == questions.length)
currentQuestion =0;
questionView.setText(questions[currentQuestion]);
answerView.setText("");
answerText.setText("");
}
// Return true if answer is correct
public boolean isCorrect(String answer)
{
return (answer.equalsIgnoreCase(answers[currentQuestion]));
}
// Display correct or incorrec results
public void checkAnswer()
{
String answer = answerText.getText().toString();
if(isCorrect(answer))
answerView.setText("You are correct!");
else
answerView.setText("Sorry, the correct answer is "+answers[currentQuestion]);
}}
Home Screen
Quiz Screen
Just have a condition check if currentQuestion == 5 at the end of checkAnswer(). If so proceed to the results screen

Connect a client app Android to a server written with Sails.js using socket.io

Here's my situation: i have a server written with sails.js where i have a user model. I have a dashboard where i can see all the users, create new, delete them and so on...Now i want to create an android app where i can get, using socket.io, notification about the events that occour to the user model.
Example: if i delete a user from my dashboard i want the app to recive a notification from the server that the user has been deleted.
Here's my code for the app:
public class MainActivity extends Activity {
//socket instance
private Socket mSocket;
{
try {
mSocket = IO.socket("http://server_url:port/user");
} catch (URISyntaxException e) {
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //set the layout for this activity
final TextView tv = (TextView) findViewById(R.id.textView);
mSocket.on("user", new Emitter.Listener() {
#Override
public void call(Object... args) {
tv.setVisibility(View.INVISIBLE);
}
});
mSocket.connect();
final Button btn_createUser = (Button)findViewById(R.id.button);
btn_createUser.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mSocket.connected()) {
//tv.setVisibility(View.INVISIBLE);
}
}
});
}
}
Like i did with the dashboard to connect the socket to the server i did the same thing here, but it seems like the socket doesn't connect, in fact, when i delete a user from the dashboard i get no notification.
Here's the code (that works) i used in my dashboard to connect my socket to the server and listen to updates from the user model:
//connect to the server and listen to updates from user model
io.socket.get('/user', function(data, jwres) {
$scope.users = data;
$scope.$apply(); //write users in the table...
});
//wait for updates...
io.socket.on('user', function serverResponded (data) {
if(data.verb == "updated")
{
//get the user index in the array and update it
var index = getIndex(data.id, $scope.users);
$scope.users[index].online = data.data.online;
$scope.$apply();
}
if(data.verb == "destroyed")
{
//get the user index in the array and remove it
var index = getIndex(data.id, $scope.users);
$scope.users.splice(index, 1);
$scope.$apply();
}
if(data.verb == "created")
{
//simply update the array
$scope.users.push(data.data);
$scope.$apply();
}
});
Now, i think all i'm missing out in the android app is the GET request which automatically subscribe my socket to the model and get notified if something happen...but i don't know hot to do it.
I hope i was clear enough...thank to everyone who will answer me!
PS: i don't want to use AndroidAsync because i need the ultimate version of socket.io!
In case someone need it, i found the solution: https://github.com/balderdashy/sails/issues/2640 here you can find out how to solve the issue! :)

how do the customize android app send message to the official WeChat app?

second question, what is the WeChat app's package name? (due to i can't find it)
follow main quesition, i use WeChat official android sample code to execute the app.
But i don't know how to assign the specific WeChat user with sending out message .
any friend tell me how to finish it?
this is WeChat Sample code for sening message:
http://dev.wechat.com/download/sdk/WeChat_SDK_sample_android_en.zip
public static final String APP_ID = "wxd930ea5d5a258f4f";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
}
#Override
public void onClick(View v) {
WXTextObject textObj = new WXTextObject();
textObj.text = text;
WXMediaMessage msg = new WXMediaMessage();
msg.mediaObject = textObj;
msg.description = text;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("text");
req.message = msg;
req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
api.sendReq(req);
finish();
}
A.how can i know that i should send who?
B.APP_ID = "wxd930ea5d5a258f4f" represent is WeChat chat id?
C.i just run the sample app,then i send out message .it say"發送被拒絕"
that mean refuse to send message.what is the problem?
D.i live in Taiwan,When i register to http://dev.wechat.com/signup
. i input my Taiwan format phone code,but my phone never receive any
WeChat verification code for SMS
In result, i just want to know that how could the custom android app send message to the specific Wechat.Use the sample code to achieve the goal?

sending data from one app to another app in android(AIR for ANDROID)

As we can send data from one Activity to another within the app and also from one app to another app by using Intent
I'm able to send data from my one app to another by using following code
just consider there are two apps APP1 and APP2 and I'm sending data from APP1 to APP2 and vice verse.
In APP1 package name: (com.sush.myApp)
public class HomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
// to receive data from com.my.demo package and display it to TextView
TextView mText = (TextView)findViewById(R.id.textView1);
String name=getIntent().getStringExtra("User_Message");
mText.setText(name);
// to send data from com.sush.myApp package to com.my.demo package
Button btn1 =(Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.my.demo");
i.putExtra("User_ID", "sush19");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "App Not Found", Toast.LENGTH_LONG).show();
}
}
});
}
and from APP2 package name: (com.my.demo)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// to receive data from com.sush.myApp package and display it to TextView
final TextView txt1 = (TextView)findViewById(R.id.Text1);
String name=getIntent().getStringExtra("User_ID");
txt1.setText(name);
// to send data from com.my.demo package to com.sush.myApp package
Button btnSending = (Button)findViewById(R.id.btnSend);
final EditText myMessage = (EditText)findViewById(R.id.txtMessage);
btnSending.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
if (myMessage.getText().toString().equals(""))
{
Toast.makeText(v.getContext(), "Enter your message", Toast.LENGTH_SHORT).show();
}
else
{
try
{
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.sush.myApp");
i.putExtra("User_Message", myMessage.getText().toString());
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}catch(Exception e)
{
e.printStackTrace();
Toast.makeText(v.getContext(), "Error: "+e, Toast.LENGTH_LONG).show();
}
}
}
});
}
And its working perfect..
Now my problem is I want to do same operation i.e sending data from one app to another but my first app is in Java created using Eclipse and my second app is in ActionScript created using AIR for Android in Adobe Flash Professional CS6
Is there a way to use Intent and PackageManager in Actionscript so that I can send the data easily from AIR app to Android App, if yes then can anyone show me a example
Or else can anyone show me an example on how to send data from Android App to AIR for Android App and vice verse..
Thank you...
There's 2 methods I can think of for this.
The first is to use the Java code you have written (or similar), package it as a Native Extension, and build that into your app.
Another alternative is to use a URI scheme and read the data from the InvokeEvent. This SO question covers that method already.

Categories

Resources