err cache miss when trying to view a website using web viewer - android

i am trying to make an application whereby when an user opens the application, they will be directed to a mobile anime website and i encountered this problem. Help !
For Main Activity
package com.example.ahliang125.kissanime;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.kissanime.com/m");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
For Activity Main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<WebView android:id="#+id/activity_main_webview" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
For Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ahliang125.kissanime" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.internet"/>
</manifest>

Could be that "android.permission.internet" should be "android.permission.INTERNET"

Related

Creation of action bar in Android Studio

I am new to the Android development app. I was following the tutorials given in the official site. So far everything was good but when I started to create and modify the action bar, this error started to arise:
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : Main AndroidManifest.xml at AndroidManifest.xml manifest:package attribute is not declared
My manifest file is this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="14"/>
package="com.mycompany.myfirstapp" >
<application>
<!-- The/main activity (it has no parent activity) -->
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo" >
<activity
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.hpcore.myfirstapp.MyActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.hpcore.myfirstapp.MyActivity" />
</activity>
</application>
</manifest>
And my main activity Java code is this:
package com.example.hpcore.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import com.mycompany.myfirstapp.DisplayMessageActivity;
public class MyActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE= "com.hp core.myfirstapp.MESSAGE";
public void sendMessage(View view)
{
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE,message);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_displaymessage);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_Activity_actions,menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId())
{
case R.id.action_search:
openSearch();
return true;
case R.id.action_settings:
openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
I guess the problem in one of these files.
You package attribute should be part of Manifest Tag-
Change your manifest Tag like below-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myfirstapp" >
<uses-sdk android:minSdkVersion="14"/>

Flashligth Android app - feature not working on phones

I am a developer just starting out with Android.
I developed an app for Android that runs on tablet and phone which offers various services including flashlight.
I added this configuration in the manifest:
<Uses-feature android: name = "android.hardware.camera" android: required = "false" />
<Uses-feature android: name = "android.hardware.telephony" android: required = "false" />
I thought that with these two last optional features I could access the flash device when present on phone without exclude tablets to have the possibility to install the app but it doesnt work.
Where am I wrong? Can someone please help me?
The above code just give the permission for the flashLight.
You have to write a code to turnon and off the Flash
I am adding the snippet of the demo i did for turning on and offing the flash light.
MainActivity.java
package com.example.balaji.myapplication;
import android.hardware.Camera;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
private Camera cam;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button turnOn = (Button)findViewById(R.id.turnOnFlashLight);
turnOn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
turnOnFlashlight();
}
});
Button turnOff = (Button)findViewById(R.id.turnOffFlashLight);
turnOff.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
turnOffFlashlight();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void turnOnFlashlight(){
cam = Camera.open();
Camera.Parameters p = cam.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
}
public void turnOffFlashlight(){
cam.release();
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<Button
android:id="#+id/turnOnFlashLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On"
/>
<Button
android:id="#+id/turnOffFlashLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn Off"
/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.balaji.myapplication" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am also giving the stackoverflow links for more information on this.
How to turn on FlashLight in Lollipop programmatically Android

Having problems with Webview from another activity Android Studio?

I have a project called PubliComidas, In my project there are 3 activities. The first is SplashScreen, Second is my MainActivity, third is a WebView which is loaded on button click in MainActivity, Problems is that the webview is not working as I expected.
When I run my app and click on the button, it shows: Web page not avalaible net::ERR_CACHE_MISS, However it's so curious because I tried to test the same code in another project apart, P.D, it was tested in only 1 blank activity when you start for the first time a new project, same steps and it works perfect but not in this app so is it a problem with this activity? or the webview cannot be shown with a lot of activities, my first and Second activity work fine but the third not, my idea is to display google. My goal is to display twitter feeds but first if it doesn't work with google even it won't work with twitter. Some help is highly and strongly appreciated, thank you!!
here is my code
Twitter.java
package com.example.json.publicomidas;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Twitter extends Activity {
private WebView mWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twitter);
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://google.co.cr");
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
}
#Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
MyWebViewClient.java
package com.example.json.publicomidas;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (Uri.parse(url).getHost().endsWith("www.google.co.cr")){
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
view.loadUrl(url);
return true;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.json.publicomidas" >
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.json.publicomidas.Twitter"
android:label="#string/twitter" >
</activity>
<activity
android:name="com.example.json.publicomidas.MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.json.publicomidas.Splash_Screen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>
activity_twitter.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/images"
tools:context="com.example.json.publicomidas.Twitter">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
The permission declaration should be outside of the application tag. Like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.json.publicomidas" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.json.publicomidas.Twitter"
android:label="#string/twitter" >
</activity>
<activity
android:name="com.example.json.publicomidas.MainActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.json.publicomidas.Splash_Screen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Display App Icon in action bar under api 11

I'm writing simple tutorial app and for some reason my App icon is not showing up (I want to use it as navigate up button instead of the arrow).
As stated in the topic, I want to do it on Api level 11, however all the sollutions I've found rely on setIcon method.
getActionBar().setIcon(R.drawable.ic_launcher); //only on API >= 14
The fragment preview in Android studio 1.0.2 does show the icon, however the emulator does not, so I'd expect the resource is ok. Also, the search and delete icons are working like a charm. I've tried setting this both as Icon and a logo to no avail.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yamba"
android:versionCode="1"
android:versionName="1.0"
>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light"
android:logo="#drawable/ic_launcher"
>
<activity
android:parentActivityName=".MainActivity"
android:name=".StatusActivity"
android:label="#string/app_name" >
</activity>
<!--- The labe is what's displayed at the taskbar!-->
<activity
android:parentActivityName=".MainActivity"
android:name=".SettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_settings.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.yamba.SettingsActivity">
<TextView android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
menu_settings.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.yamba.SettingsActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
SettingsActivity.java
package com.example.yamba;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SettingsActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null){
SettingsFragment fragment = new SettingsFragment();
getFragmentManager().beginTransaction().add(android.R.id.content, fragment, fragment.getClass().getSimpleName()).commit();
setContentView(R.layout.activity_settings);
// getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
// only for API>=14
// getActionBar().setDisplayShowHomeEnabled(true);
// getActionBar().setIcon(R.drawable.ic_launcher);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.menu_settings, menu);
// return true;
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch(id){
case R.id.action_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
case R.id.action_tweet:
startActivity(new Intent(this, com.example.yamba.StatusActivity.class));
return true;
default:
return false;
}
}
}
SettingsFragment.java
package com.example.yamba;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
/**
* Created by me on 19-01-2015.
*/
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences prefs;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
public void onStart(){
super.onStart();
prefs= PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(this);
}
#Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
}
}
I've stumbled upon suggestion that I may be able to define custom style based on one of the existing styles, but can't quite figure out how to approach it.
If you need any other file, let me know and thanks for your time.
since it's API 11..
did you try using the support libraries?
try switching
getActionBar().setIcon(R.drawable.ic_launcher);
with :
getSupportActionBar().setIcon(R.drawable.ic_launcher);
tell me if it works and we'll continue from there :)

My app is crashing when I use the Theme.NoTitleBar in the menefest file

I've done this on my other apps and it worked fine. On my new app, when I run it I get a message box that says
"Unfortunately livebitcoinscharts has stopped",
The project is just from the template code generated by eclipse, I did not add anything to it
I'm using eclipse and tried putting a break point on the first line of code, which never went off.
Manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
code:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.bitcoinslivecharts2.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
I think this is because you are usin ActionBarActivity which is under android suuport library v7 appcompat library which has to inflate a theme under Theme.AppCompat like Theme.AppCompat.Light.DarkActionBar
You can just inherit from Activity if you don't want actionbar.

Categories

Resources