Question: Please I need help with my android assignment. Please provide comments REQUIREMENTS: 1 Activity MainActivity A list view and a web view The List View

Please I need help with my android assignment. Please provide comments

REQUIREMENTS:

1 Activity

MainActivity A list view and a web view

The List View UrlList

It will show a list of URLs

it should have at least 3 default entries in the list, e.g.

https://www.fontbonne.edu https://www.google.com https://my-favoriate-website.com

clicking on an item in the List should open up the website in the Web View

1 BroadcastReceiver

SmsReceiver

use an intent filter to listen for SMS_RECEIVED, register the receiver inside of the Android Manifest file, not dynamically

when an SMS is received, your code should get the message from the SMS

We will assume that you will only receive messages containing URLs

your receiver should then launch a new instance of your Activity, which will add the new URL to the default list AND open the website immediately in the WebView

all entries (including the new one) should still be clickable Your app should support SMS messages with URLs in any valid format,

i.e.

http://www.example.com (Dont need to modify)

http://example.com (Dont need to modify)

www.example.com (Need to prepend http://)

example.com (Need to prepend only http:// , NOT www)

============================================================

I almost got everything except BroadcastReceiver

this what I have done so far

MyReceiver.java 
public class MyReceiver extends BroadcastReceiver { public MyReceiver() { } // SmsManager class is responsible for all SMS related actions final SmsManager sms = SmsManager.getDefault(); @Override public void onReceive(Context context, Intent intent) { // Get Bundle object contained in the SMS intent passed in Bundle bundle = intent.getExtras(); SmsMessage[] smsm = null; String sms_str =""; if (bundle != null) { // Get the SMS message Object[] pdus = (Object[]) bundle.get("pdus"); smsm = new SmsMessage[pdus.length]; for (int i=0; icreateFromPdu((byte[])pdus[i]); sms_str += " Message: "; sms_str += smsm[i].getMessageBody().toString(); sms_str+= " "; } // Start Application's MainActivty activity Intent smsIntent=new Intent(context,MainActivity.class); smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); smsIntent.putExtra("sms_str", sms_str); context.startActivity(smsIntent); } } } 
MyArrayAdapter.java 

public class MyArrayAdapter extends ArrayAdapter { private Context context; private String [] web_link; public MyArrayAdapter(Context context, int position,String [] web_link) { super(context,position,web_link); this.context = context; this.web_link=web_link; } @Override @NonNull public View getView(final int position, View convertView, @NonNull final ViewGroup parent) { final ViewHolder viewHolder; if (convertView == null) { convertView=LayoutInflater.from(getContext()).inflate(R.layout.row_layout,parent,false); viewHolder=new ViewHolder(convertView); convertView.setTag(viewHolder); } else { viewHolder=(ViewHolder)convertView.getTag(); } viewHolder.textView.setText(web_link[position]); return convertView; } private static class ViewHolder{ private TextView textView; public ViewHolder(View view){ textView=(TextView)view.findViewById(R.id.tv_link); } } } 
MainActivity.java  
public class MainActivity extends Activity { ListView listView; String [] web_link; WebView webView; MyArrayAdapter myArrayAdapter; MyReceiver myReceiver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myReceiver=new MyReceiver(); setUpView(); updateList(); } public void setUpView(){ listView = (ListView) findViewById(R.id.list_view); web_link=getResources().getStringArray(R.array.weblink); webView = (WebView) findViewById(R.id.webView); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.setWebViewClient(new MyWebClient()); webView.loadUrl("http://www.google.com"); myArrayAdapter = new MyArrayAdapter(this,android.R.layout.simple_list_item_1, web_link); listView.setAdapter(myArrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { if (position == 0) { webView.loadUrl(web_link[position]); } else if (position == 1) { webView.loadUrl(web_link[position]); } else if (position==2){ webView.loadUrl(web_link[position]); } } }); } public void updateList() { // Get intent object sent from the SMSBroadcastReceiver Intent sms_intent = getIntent(); Bundle b = sms_intent.getExtras(); if (b != null) { // Display SMS in the TextView myArrayAdapter.insert(sms_intent.toString(), 0); } myArrayAdapter.notifyDataSetChanged(); } private class MyWebClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!